2011-07-18 101 views
1

我生成一個boost::graph,邊緣有一些300k。我在循環中創建了一組邊,我還計算邊的一些屬性。由於我需要所有邊緣來創建圖形,因此我還無法訪問edge_descriptor。有沒有辦法做到這一點,而不必再次通過整個集合?當我創建我的邊緣時,我使用std::pair<int, int>,這與描述符兼容嗎?創建圖形之前設置邊緣屬性

回答

1

如果你知道頂點的數量(那麼你可以初始化一個圖形,然後你可以稍後添加邊)。如果你事先不知道頂點的數目,我不知道你是怎麼做出圖形的。

,如果你有個頂點(即,如果你讓vertex_descriptors只要你得到一個價值 - 頂點),那麼你可以使用函數boost::add_edge(u,v,the_graph)添加邊緣曲線,在同一迴路 假設你有圖形和vertex_descriptors這樣的:

//Note: this code is just a guideline, i hope you'd be able to take up from here 
typedef typename boost::adjacency_list<boost::listS, boost::vecS, 
          boost::directedS,Vertex_t*> Graph_t; 

typedef typename boost::graph_traits<Graph_t>::vertex_descriptor Vd_t; 

然後

Graph_t the_graph(Num_vertices); 
Vd_t u,v; 
//assign u,v 
boost::add_edge(u,v,the_graph)