c++ 图中没有匹配的boost::get函数调用

w1e3prcc  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(241)

我正在根据boost中的geometry/07_a_graph_route_example示例建模我的图表。
我的Graph看起来像这样:

  1. typedef boost::adjacency_list<
  2. boost::listS,
  3. boost::vecS,
  4. boost::directedS,
  5. gG_vertex_property<string, double, pointClass>,
  6. gG_edge_property<listClass, pointClass>
  7. > graph_type;
  8. graph_type Graph;

使用gG_vertex_propertygG_edge_property作为自定义属性。
现在每次我尝试调用dijkstra_shortest_path

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

作为WeightMap,我得到:
错误:没有匹配的函数用于调用'get' boost::get(boost::edge_weight,Graph)
还有很多不适合我的用例的add模板。我是如何阅读文档的,这是标准的方法。我的财产是不是少了什么?
我做错了什么?
谢谢你的帮助

x4shl7ld

x4shl7ld1#

我猜gG_vertex_propertygG_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中,正确的代码应该是这样的:

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

相关问题