使用Boost adjacency_list执行connected_components,其中VertexList = listS

时间:2010-07-06 02:39:32

标签: c++ graph boost-graph

我在项目中使用Boost Graph Library,它被声明为:

typedef adjacency_list <listS, listS, undirectedS, TrackInformation, LinkInformation> TracksConnectionGraph;

在我必须在图表上调用connected_components之前,情况一切正常。

typedef std::map<TracksConnectionGraph::vertex_descriptor, TracksConnectionGraph::vertices_size_type> component_type;
component_type component;
boost::associative_property_map< component_type > component_map(component);

int num_components = connected_components(tracks_connection_graph_, component_map);

问题似乎是如果VertexList = listS,我没有vertex_index作为我的顶点的属性。这使得connected_components给我错误,如:

  

/usr/local/include/boost-1_39/boost/property_map.hpp:   在成员函数'R   提高:: iterator_property_map ::运算符[](类型名   提高:: property_traits :: key_type的)   const [with RandomAccessIterator =   __gnu_cxx :: __ normal_iterator   ,IndexMap = boost :: adj_list_vertex_property_map,   提高::详细:: error_property_not_found,   常量   提高::详细:: error_property_not_found和放大器;,   boost :: vertex_index_t&gt;,T =   boost :: default_color_type,R =   升压:: default_color_type&安培;]':

所以问题是:如何将vertex_index添加为我的顶点的属性?

如果我添加它,是否意味着每当我调用add_vertex,remove_vertex等时,我必须为每个顶点更新此信息?

1 个答案:

答案 0 :(得分:2)

您可以将vertex_index属性添加到图表类型的定义中(在adjacency_list的顶点属性模板参数中,将TrackInformation更改为property<vertex_index_t, size_t, TrackInformation>)。在调用算法之前,您需要使用循环填写属性映射,例如:

size_t index = 0;
BGL_FORALL_VERTICES(v, tracks_connection_graph_, TracksConnectionGraph) {
  put(vertex_index, g, v, index++);
}
相关问题