首页 > 解决方案 > 图中没有匹配的函数调用 boost::get

问题描述

我在 boost 中的示例 geometry/07_a_graph_route_example 之后对我的图进行建模。

我的图表如下所示:

typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, gG_vertex_property<string, double, pointClass>, gG_edge_property<listClass, pointClass>> graph_type;

graph_type Graph;

gG_vertex_property作为gG_edge_property自定义属性。

现在每次我尝试dijkstra_shortest_path打电话

     boost::dijkstra_shortest_paths(Graph, endVert,                             // Graph Object, End of Search Object
                                       &predecessors[0], &costs[0],                                             // Vectors to store predecessors and costs
                                       boost::get(boost::edge_weight, Graph),
                                       boost::get(boost::vertex_index, Graph),                                  // Vertex Index Map
                                       std::less<double>(), std::plus<double>(),                                // Cost calculating operators
                                       (std::numeric_limits<double>::max)(), double(),                          // limits
                                       boost::dijkstra_visitor<boost::null_visitor>());                         // Visitior, does nothing at the moment

正如我得到的 WeightMap:

错误:没有匹配函数调用'get' boost::get(boost::edge_weight, Graph)

还有很多不适合我的用例的 add 模板。我如何阅读文档,这是执行此操作的标准方法。我的属性是否缺少某些内容?

我究竟做错了什么?

谢谢你的帮助。

标签: c++boostboost-graph

解决方案


我猜是“gG_vertex_property捆绑gG_edge_property”属性(没有自定义属性之类的东西)。如果是这样,你应该传递这些而不是“boost::get(boost::edge_weight, Graph)”,它试图访问“内部”属性,完全独立的东西。请参阅https://www.boost.org/doc/libs/1_77_0/libs/graph/doc/bundles.html。我猜如果属性是结构并且边缘权重保存在 中gG_edge_property::weight,正确的代码将是这样的:

 boost::dijkstra_shortest_paths(Graph, endVert,                             // Graph Object, End of Search Object
                                   &predecessors[0], &costs[0],                                             // Vectors to store predecessors and costs
                                   get(&gG_edge_property::weight, Graph), /*!!!!!!!!*/
                                   boost::get(boost::vertex_index, Graph),                                  // Vertex Index Map
                                   std::less<double>(), std::plus<double>(),                                // Cost calculating operators
                                   (std::numeric_limits<double>::max)(), double(),                          // limits
                                   boost::dijkstra_visitor<boost::null_visitor>());                         // Visitior, does nothing at the moment

推荐阅读