Time-dependent graphs
Hi, I am currently using an adjacency_list for calculating shortest paths using BGL. Now I would like to make the edge weights time-dependent by calling some own function during the algorithm. Unfortunately, I did not really get things working as described in the book "The Boost Graph Library" with respect to self-defined property maps. (Or should I use a visitor for that purpose?) Maybe you could helb me with some code example on using own code for the edge weights to be used during the Dijkstra algorithm? Many thanks and best regards, Thomas Hanne My current code for calculating shortst paths is like ... typedef adjacency_list<listS, vecS, directedS, no_property, property<edge_weight_t, double> > tGraph; ... int anzKnoten = num_vertices(m_Wegezeiten); vector<vertex_descriptor> vorg(anzKnoten); vector<double> wege(anzKnoten); property_map<tGraph, edge_weight_t>::type gewichte = newget(edge_weight, m_Wegezeiten); property_map<tGraph, vertex_index_t>::type indizes = get(vertex_index, m_Wegezeiten); vertex_descriptor start = vertex(nrVon, m_Wegezeiten); dijkstra_shortest_paths(m_Wegezeiten, start, &vorg.at(0), &wege.at(0), gewichte, indizes, less<double>(), closed_plus<double>(), numeric_limits<int>::max(), 0, default_dijkstra_visitor() );
On Jun 22, 2006, at 10:55 AM, Thomas Hanne wrote:
Hi,
I am currently using an adjacency_list for calculating shortest paths using BGL. Now I would like to make the edge weights time-dependent by calling some own function during the algorithm. Unfortunately, I did not really get things working as described in the book "The Boost Graph Library" with respect to self-defined property maps. (Or should I use a visitor for that purpose?)
You can create a new property map that calculates weights however you want, e.g., struct my_weight_map { typedef /*the edge_descriptor type*/ key_type; typedef double value_type; typedef value_type reference; typedef boost::readable_property_map_tag category; // data used by my_weight_map }; double get(const my_weight_map& m, /* the edge_descriptor type*/ edge) { return /* compute weight */; } Then, instead of passing "gewichte" to dijkstra_shortest_path, pass my_weight_map(); Doug
participants (2)
-
Doug Gregor
-
Thomas Hanne