【问题标题】:Perform connected_components with Boost adjacency_list where VertexList=listS使用 Boost adjacency_list 执行 connected_components where VertexList=listS
【发布时间】:2010-07-06 02:39:31
【问题描述】:

我在一个项目中使用了 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 [与 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等时,我都必须为每个顶点更新这个信息?

【问题讨论】:

    标签: c++ graph boost-graph


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 2020-04-23
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      • 2011-08-12
      • 2019-09-11
      相关资源
      最近更新 更多