【发布时间】:2013-08-17 17:01:48
【问题描述】:
以下代码在prim_minimum_spanning_treecall 上抛出“负边权重”,即使我使用仅正数。应该进行哪些更改才能使其正常工作?
typedef boost::property<vertex_distance_t, int> VertexProperty;
typedef boost::property<edge_weight_t, int> EdgeProperty;
typedef adjacency_list<vecS, vecS, undirectedS, VertexProperty, EdgeProperty> Graph;
typedef pair<int, int> Edge;
Edge edges[] = {Edge(0, 1), Edge(1, 2)};
int weights[] = {2, 1}; // this works: int weights[] = {1, 2};
Graph g(edges, edges + sizeof(edges)/sizeof(Edge), weights, 3);
std::vector<Graph::vertex_descriptor> predecessors(num_vertices(g));
boost::prim_minimum_spanning_tree(g, &predecessors[0]);
注意:我可以通过调整权重值使其成功。
编译器:MS Visual Studio 2010 C++ 增强版本:1.54
【问题讨论】:
-
看起来不像,但也许权重是累积的,所以任何权重下降都意味着边的权重为负?显而易见的测试:如果权重是递增的,它总是成功,如果它们是递减的值,它总是失败吗?
-
@Jerry Coffin:是的,它对排序很敏感。由于上面的代码在 boost 1.53 版本中可以正常工作,我倾向于认为这是最新的 boost 版本 (1.54) 中的一个错误。
-
@alexm 我看到你已经有了reported the bug,它已经被修复了(难以置信的快!)。
标签: c++ boost-graph