2011-07-18 52 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)