Re: [Boost-users] [Boost Graph] newbie - dijkstra & external weightmap

Use iterator_property_map (http://www.boost.org/doc/libs/1_41_0/libs/property_map/doc/iterator_property...) using syntax such as the following (replacing "weight_map(agent_weightmap)" in the code just above):
weight_map( make_iterator_property_map( agent_weightmap.begin(), get(vertex_index, g)))
You will need to include <boost/property_map/property_map.hpp> to get iterator_property_map.
-- Jeremiah Willcock
Thanks Jeremiah, But I'm talking about edge weights - why would you put in "get(vertex_index,g)" and not "get(edge_index,g)" or similar (I've tried this simple substitution and it doesn't work; so it's obviously more complex than that)? In any case I've tried more or less exactly what you suggested as follows but the compiler spits out a long error, reported below (libboost1.40): -------- #include <boost/property_map/property_map.hpp> class road; typedef adjacency_list<setS,vecS,undirectedS,no_property,road> Graph; typedef boost::vertex_descriptor vdest; vdest shortest_path(Graph& g, vdest src, vdest dst) { vector<vdest> parent(num_vertices(g)); vector<double> agent_weightmap(num_edges(g)); dijkstra_shortest_paths(g,src, //weight_map(get(&road::transit_time,g)) // ---> this weight_map works weight_map(make_iterator_property_map(agent_weightmap.begin(), get(vertex_index, g))) .predecessor_map(make_iterator_property_map(parent.begin(), get(vertex_index, g)))); vdest vd; for (vd=dst ; parent[vd]!=src ; vd=parent[vd]); return(vd); } -------- Compiler error: ------- /usr/include/boost/property_map/property_map.hpp: In function ‘Reference boost::get(... [lots of instantiated froms] ... instantiated from [dijkstra_shortest_paths(...)] /usr/include/boost/property_map/property_map.hpp:317: error: no match for ‘operator[]’ in ‘(const boost::iterator_property_map<__gnu_cxx::__normal_iterator<double*, .... /usr/include/boost/property_map/property_map.hpp:354: note: candidates are: R boost::iterator_property_map<RandomAccessIterator, IndexMap, ....... ------- I'm getting a backward warning on hash_set included from boost/graph/adjacency_list.hpp - could this be an issue? Thanks again, Fergal.

Thanks Jeremiah,
But I'm talking about edge weights - why would you put in "get(vertex_index,g)" and not "get(edge_index,g)" or similar (I've tried this simple substitution and it doesn't work; so it's obviously more complex than that)?
OK. I misread that -- you do want edge_index. You will need to provide them yourself, though. You must have some mapping from edges to numbers already to index the vector; that needs to be turned into a property map.
In any case I've tried more or less exactly what you suggested as follows but the compiler spits out a long error, reported below (libboost1.40):
-------- #include <boost/property_map/property_map.hpp> class road; typedef adjacency_list<setS,vecS,undirectedS,no_property,road> Graph; typedef boost::vertex_descriptor vdest; vdest shortest_path(Graph& g, vdest src, vdest dst) { vector<vdest> parent(num_vertices(g)); vector<double> agent_weightmap(num_edges(g));
dijkstra_shortest_paths(g,src, //weight_map(get(&road::transit_time,g)) // ---> this weight_map works weight_map(make_iterator_property_map(agent_weightmap.begin(), get(vertex_index, g))) .predecessor_map(make_iterator_property_map(parent.begin(), get(vertex_index, g))));
vdest vd; for (vd=dst ; parent[vd]!=src ; vd=parent[vd]); return(vd); } --------
Compiler error: ------- /usr/include/boost/property_map/property_map.hpp: In function ‘Reference boost::get(... [lots of instantiated froms] ... instantiated from [dijkstra_shortest_paths(...)] /usr/include/boost/property_map/property_map.hpp:317: error: no match for ‘operator[]’ in ‘(const boost::iterator_property_map<__gnu_cxx::__normal_iterator<double*, .... /usr/include/boost/property_map/property_map.hpp:354: note: candidates are: R boost::iterator_property_map<RandomAccessIterator, IndexMap, ....... -------
I'm getting a backward warning on hash_set included from boost/graph/adjacency_list.hpp - could this be an issue?
The warning is not interesting -- it's just saying that BGL is using old-style hash tables; 1.41 (I believe) has this fixed. I do not know the exact cause of the operator[] error; you removed too much of the error message to tell. -- Jeremiah Willcock
participants (2)
-
Fergal Dalton
-
Jeremiah Willcock