c++
I use Boost Graph Library in a project and it is declared as:
typedef adjacency_list <listS, listS, undirectedS, TrackInformation, LinkInformation> TracksConnectionGraph;
Things are going fine until I have to call connected_components on my graph.
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);
The problem seems to be that if the VertexList=listS, I do not have vertex_index as a property of my vertex. This makes connected_components give me errors like theses:
/usr/local/include/boost-1_39/boost/property_map.hpp: In member function '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&]':
So the question is: how do I add vertex_index as a property of my vertices?
If I add it, does it mean that whenever I call add_vertex, remove_vertex and such, I have to update this information for each vertex?
You can add a vertex_index
property to the definition of your graph type (in the vertex property template argument to adjacency_list
, change TrackInformation
to property<vertex_index_t, size_t, TrackInformation>
). Before calling the algorithm, you will need to fill in the property map using a loop such as:
size_t index = 0;
BGL_FORALL_VERTICES(v, tracks_connection_graph_, TracksConnectionGraph) {
put(vertex_index, g, v, index++);
}
链接地址: http://www.djcxy.com/p/51052.html
上一篇: 如何在Ubuntu上安装boost?
下一篇: C ++