增强图形库,在应用 dijkstra 算法时导致错误
Boost graph library causing errors when applying dijkstra's algorithm
我一直在遵循这个例子,这个例子,以及这个堆栈溢出帖子,试图应用Dijkstra算法来找到两个节点之间最短路径的成本。
如果我尝试遵循第一个示例,则NameMap的typedef语句会出现错误。这个错误是神秘的,冗长的,我不知道该怎么处理它。
如果我尝试遵循第二个示例(从Boost文档中复制粘贴!!),它不会编译。这个错误甚至更加神秘和冗长。
第三个(堆栈溢出post)依赖于与第一个相同的类型定义。
是用户错误吗?它可能是,但是我应该如何解释从库代码中生成的错误消息?
更新1
我正在使用g++ (Debian 4.8.2-21) 4.8.2从Debian测试。
更新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}'
你传递了包含源顶点的数组s
作为指定起始顶点的第二个参数,当你应该传递v0
时,编译器正确地抱怨它不能将长数组转换为单个顶点。
相关文章:
- C++选择排序算法中的逻辑错误
- OpenCV - Python 断言错误:SAD 算法 - 立体相机视差图计算
- C++运行时错误与快速排序算法抛出堆栈转储错误
- 我的排序算法程序中的堆错误
- 运行合并排序递归算法时EXC_BAD_ACCESS错误
- 由于指针算法错误,代码在 memcpy 中崩溃
- 卤化物:较大图像的去马赛克算法错误.似乎适用于 16x16 图像
- 错误:在"模板"之前预期主表达式,具有算法的复制功能
- 使用动态数组对算法编译器错误进行排序
- 算法中的排序函数返回错误
- 贝尔曼-福特算法中的 c++ 和分割错误 11
- 算法错误:参数无法从对中掩盖 1
- 字符串相似性算法返回错误值
- Kurskal 算法,Kattis 中的运行时错误
- C++:basic_string::_M_construct 空,对于图形 BFS 算法无效错误
- 为什么这种递归子集和算法会导致指针分配错误
- 骑士团索引和移动算法错误
- C++正在创建二进制搜索树:EXC_BAD_ACCESS错误.算法错误还是编码错误
- 快速排序算法,一些特定输入序列的错误答案和分段错误
- 罗马数字基本算法中基于字符串的错误(使用std::map)