2010-12-01 39 views
1

我還有一個關於Boost圖形庫的問題,我無法通過Google搜索或閱讀文檔來回答自己。這與我的其他問題沒有直接關係,所以我想我最好開始一個新線程。BGL:我如何直接訪問節點和邊的數據?

我有一個鄰接佈局的圖形,並使用綁定的屬性來訪問節點和邊的數據。爲了方便起見,我在Graph中使用了typedef。因此,我可以訪問存儲的數據,例如用於vertex_descriptor的,通過輸入這樣的事情:

Graph[my_vertex_descriptor].setX(4); 
Graph[my_vertex_descriptor].setY(10); 

現在我想以定義與數據存儲對象的引用,以便能夠鍵入類似的東西:

typedef Graph[vertex_descriptor]::type Vertex; 
Vertex v = Graph[my_vertex_descriptor]; 
v.setX(4); 
v.setY(10); 

通過這種或我試圖避免不必要地重新計算通過使用映射的[]operator和特定描述符對象來訪問的映射值的類似方法。我的頂點和邊緣包含大量數據,所以在某些情況下,我當前的代碼會產生許多相同值的重新計算來處理這些數據。這似乎很難看。

有誰知道是否有可能實現我想要做的?

回答

0

關閉我的頭頂,這應該工作(假設你使用內置的圖形類型有明確的graph_traits之一):

typedef boost::graph_traits<Graph>::vertex_descriptor Vertex; 
Vertex v = Graph[my_vertex_descriptor]; 
v.setX(4); 
v.setY(10); 

實際上你可以訪問大量的這種方式,採取看看BGL的圖概念的更多信息:http://www.boost.org/doc/libs/1_45_0/libs/graph/doc/graph_concepts.html

1

我用捆綁的屬性和:

Bundled_vertex_property prop_v = get(vertex_bundle, my_graph) // or get(vertex_bundle, v, my_graph) 
Bundled_edge_property prop_e = get(edge_bundle, my_graph) // or get(edge_bundle, v, my_graph) 

拿到捆綁的直接財產LY。

+0

上面實際上應該是: `Bundled_vertex_property prop_v = GET(vertex_bundle,my_graph,vertex_descriptor的)`` Bundled_edge_property prop_e = GET(edge_bundle,my_graph,vertex_descriptor的)` 還要注意的是`edge_bundle`和`vertex_bundle`不是變量,它們是預定義的描述符。 – 2012-11-18 00:40:51