2010-04-09 69 views
5

我正在研究boost图库的使用,以便将它们应用于我考虑的各种网络问题。Boost图库:设置边缘权值

在我一直在寻找的图形边缘值(“权重”)的例子总是被初始化为整数,如在这些Bellman-FordKruskal算法如:

int weights[] = { 1, 1, 2, 7, 3, 1, 1, 1 }; 

我的问题是,如果我尝试并将权重更改为双倍,我收到了一堆关于转换等的警告消息,到目前为止,我还没有弄清楚如何克服。

有没有人看到解决这个问题的方法?

回答

6

这是由weights[]数组与用于增强图/算法的边权重类型之间的不匹配造成的。

在第一个链接的样本,例如,你也应该改变

struct EdgeProperties { 
    int weight; 
}; 
[...] 
property_map<Graph, int EdgeProperties::*>::type 

struct EdgeProperties { 
    double weight; 
}; 
[...] 
property_map<Graph, double EdgeProperties::*>::type 

在第二

typedef adjacency_list < vecS, vecS, undirectedS, 
    no_property, property < edge_weight_t, int > > Graph; 

typedef adjacency_list < vecS, vecS, undirectedS, 
    no_property, property < edge_weight_t, double > > Graph; 
+0

嗨代码可以在这些链接中看到:bellman-example.cpp和kruskal-example.cpp – AndyUK 2010-04-09 15:03:16

+0

看到它并相应地更新了答案。 – baol 2010-04-09 15:08:59

+0

你的第二个建议(克鲁斯卡尔)已经奏效,欢呼起来。我无法完全摆脱Bellman的障碍。 – AndyUK 2010-04-09 15:17:33