Dijkstra Shortest Path with VertexList = ListS in boost graph

不羁的心 提交于 2019-11-27 05:18:42

BGL actually has an example of using dijkstra_shortest_paths with listS/listS, but it's not linked to from the HTML documentation: http://www.boost.org/doc/libs/release/libs/graph/example/dijkstra-example-listS.cpp

What the error message is trying to tell you (error: no match for ‘operator=’ in ‘index.boost::adj_list_vertex_property_map...ValueType = boost::detail::error_property_not_found...) is that there is no per-vertex storage for the vertex_index_t property, which is what adj_list_vertex_property_map needs. To fix the problem you can either change your Graph typedef to include per-vertex storage for the vertex_index_t property or use an "external" property map such as associative_property_map.

The dijkstra-example-listS.cpp example uses the approach of changing the graph typedef. To use this approach in your code, you could define:

typedef boost::adjacency_list <boost::listS, boost::listS, boost::directedS,
  boost::property<boost::vertex_name_t, std::string, boost::property<boost::vertex_index_t, int> >,
  boost::property<boost::edge_weight_t, Weight> > Graph;

If somebody is interested in the solution, Creating an associative_property_map as suggested in the previous answer solved the issue:

   typedef std::map<vertex_desc, size_t>IndexMap;
   IndexMap mapIndex;
   boost::associative_property_map<IndexMap> propmapIndex(mapIndex);
   //indexing the vertices
     int i=0;
     BGL_FORALL_VERTICES(v, g, pGraph)
     {
        boost::put(propmapIndex, v, i++);
     }

Then pass this Vertex index map to the dijkstra_shortest_paths() call as a named parameter. PS: BGL_FORALL_VERTICES() is defined in < boost/graph/iteration/iteration_macros.hpp >

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!