使用 Boost adjacency_list 执行连接组件,其中 VertexList=listS
我在一个项目中使用 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[](类型名 boost::property_traits::key_type) const [与 RandomAccessIterator = __gnu_cxx::__normal_iterator , IndexMap = boost::adj_list_vertex_property_map, boost::detail::error_property_not_found, 常量 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 等时,我都必须更新每个顶点的此信息?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
vertex_index
属性添加到图形类型的定义中(在adjacency_list
的顶点属性模板参数中,将TrackInformation
更改为属性)。在调用算法之前,您需要使用循环填充属性映射,例如:
You can add a
vertex_index
property to the definition of your graph type (in the vertex property template argument toadjacency_list
, changeTrackInformation
toproperty<vertex_index_t, size_t, TrackInformation>
). Before calling the algorithm, you will need to fill in the property map using a loop such as: