我使用Boost图形库定义了一个图形。
typedef boost::property<boost::edge_weight_t, int> EdgeWeightProperty;
typedef boost::adjacency_list<boost::listS, boost::vecS,boost::undirectedS,boost::no_property,EdgeWeightProperty> Graph;
使用以下方法添加边缘非常简单:
boost::add_edge(vertice1, vertice2, weight, graph);
我还没想出如何在边权重被设置后更改它。一个可能的解决方案是删除该边,然后重新添加它并更新其权重值,但是这似乎有点过度。
int weight = g[ed.first].weight;
和g[ed.first].weight = weight + weightToAdd;
分别替代boost::get
和boost::put
函数。 - Abdullah Giray Yağlıkçıedge_weight_t()
? - lucidbrot