boost :: prim_minimum_spanning_tree中出现意外的负边缘权重错误

时间:2013-08-17 17:01:48

标签: c++ boost-graph

以下代码会在prim_minimum_spanning_tree来电时抛出“负边缘权重”,即使我只使用 正数。应该改变什么才能使它发挥作用?

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

1 个答案:

答案 0 :(得分:0)

这是一个Boost bug,并且已经修复:如果其他人从1.54看到此行为,只需update to 1.55 or newer