【问题标题】:No matching function call for boost::get in graph图中没有匹配的函数调用 boost::get
【发布时间】:2021-12-26 17:59:04
【问题描述】:

我在 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_propertygG_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 模板。我如何阅读文档,这是执行此操作的标准方法。我的属性是否缺少某些内容?

我做错了什么?

感谢您的帮助。

【问题讨论】:

  • 你的gG_vertex_property好像有问题,所以需要minimal reproducible example
  • 我正在看这个空间,但仍然没有代码详细信息?您要添加这些,还是我们应该关闭问题?

标签: c++ boost boost-graph


【解决方案1】:

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

 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

【讨论】:

  • 谢谢,我觉得这样可以。
猜你喜欢
  • 1970-01-01
  • 2012-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
相关资源
最近更新 更多