我在一个项目中使用 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 boost::iterator_property_map::operator[](typename boost::property_traits::key_type) const [with RandomAccessIterator = __gnu_cxx::__normal_iterator , IndexMap = boost::adj_list_vertex_property_map, boost::detail::error_property_not_found, const boost::detail::error_property_not_found&, boost::vertex_index_t>, T = boost::default_color_type, R = boost::default_color_type&]':
所以问题是:如何添加 vertex_index 作为我的顶点的属性?
如果我添加它,是否意味着每当我调用 add_vertex、remove_vertex 等时,我必须为每个顶点更新此信息?