2010-04-09 53 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