Dijkstra Shortest Path with VertexList = ListS in boost graph

前端 未结 2 614
北恋
北恋 2020-11-30 12:57

I am quite new to Boost graph. I am trying to adapt an example for finding Dijkstra Shortest Path algorithm which used VertexList = vecS. I changed the vertex container to L

相关标签:
2条回答
  • 2020-11-30 13:07

    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;
    
    0 讨论(0)
  • 2020-11-30 13:28

    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 >

    0 讨论(0)
提交回复
热议问题