[英]Boost graph library causing errors when applying dijkstra's algorithm
我一直在松散下面这个例子 , 这一次 ,和这个堆栈溢出后 ,试图运用Dijkstra算法找到两个节点之间的最短路径的成本。
如果尝试遵循第一个示例,则NameMap的typedef语句会出错 。 该错误是神秘的,冗长的,我不知道该如何处理。
如果我尝试遵循第二个示例(从Boost文档复制粘贴!), 则不会编译 。 该错误甚至更加神秘和冗长。
第三个(堆栈溢出后)依赖于与第一个相同的typedef。
这是用户错误吗? 可能是,但是我应该如何解释从库代码中产生的错误消息?
更新1
我正在使用来自debian测试的g ++(Debian 4.8.2-21)4.8.2。
更新2
这是无效的源代码的精简版本。 前面有两行以“ //下面的行导致错误”开头。
更新3我已更改
typedef adjacency_list<listS, vecS, directedS, allow_parallel_edge_tag, EdgeWeightProperty> Graph;
typedef adjacency_list<listS, vecS, directedS, no_property , EdgeWeightProperty> Graph;
您的第一次尝试未使用vertex_name_t
标记定义属性(或将其作为adjacency_list
模板参数传递),因此,当您尝试使用该标记创建property_map
时,编译器将发出错误消息。
您的代码:
typedef property<edge_weight_t, Weight> EdgeWeightProperty;
typedef boost::adjacency_list<listS, vecS, directedS, allow_parallel_edge_tag, EdgeWeightProperty> Graph;
// ^ What's this?
您引用的示例代码:
typedef boost::property<boost::edge_weight_t, Weight> WeightProperty;
typedef boost::property<boost::vertex_name_t, std::string> NameProperty; // <-- not in your code
typedef boost::adjacency_list < boost::listS, boost::vecS, boost::directedS, NameProperty, WeightProperty > Graph;
// ^ Used here
我不知道为什么要传递allow_parallel_edge_tag
作为模板参数。 如果我正确阅读了文档,则在使用自定义容器类型时,该结构是为parallel_edge_traits
专业化设计的。
编辑:一旦有了代码,第二种情况实际上很容易诊断。 通过编译器发出的错误消息,我们寻找导致编译器没有为dijkstra_shortest_paths
选择3参数重载的原因。 许多消息只是告诉您,它拒绝了带有大约十二个参数的重载-应该这样做!
现在, 此错误消息(由g ++使用Coliru发出)是相关的,因为它告诉您为什么编译器拒绝三参数版本:
In file included from main.cpp:5:0:
/usr/local/include/boost/graph/dijkstra_shortest_paths.hpp:602:3: note: void boost::
dijkstra_shortest_paths(const VertexListGraph&, typename boost::graph_traits<Graph>::
vertex_descriptor, const boost::bgl_named_params<T, Tag, Base>&) [ /* irrelevant stuff
telling you how it deduced the template parameters here */ ] <near match>
dijkstra_shortest_paths
^
/usr/local/include/boost/graph/dijkstra_shortest_paths.hpp:602:3: note: no known conversion for
argument 2 from 'long int [6]' to 'boost::graph_traits<boost::adjacency_list<boost::listS,
boost::vecS, boost::directedS, boost::no_property, boost::property<boost::edge_weight_t, long int> >
>::vertex_descriptor {aka long unsigned int}'
当您应该传递v0
,您传递了s
(包含源顶点的数组)作为指定起始顶点的第二个参数,并且编译器理所当然地抱怨它无法将long数组转换为单个顶点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.