使用BFSVisitor在连接的组件中传播值? (Boost,C ++)?

时间:2014-08-02 04:08:32

标签: c++ boost boost-graph

我正在构建一个提升图。对于图中的每个连接组件,我想为该连接组件中的每个顶点传播唯一的ID值。我想知道是否有办法使用Boost' BFSVisitor概念?

我猜这可以使用examine_edge函数(http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/BFSVisitor.html)完成,但我很难搞清楚这样的类的实现。任何见解/链接到示例都会有很大帮助!

1 个答案:

答案 0 :(得分:1)

听起来您只想实现自定义BFS访问者。已经回答here

特别是在您的discover_vertex方法中。你可以使用:

void discover_vertex(const graph_t::vertex_descriptor &s, const graph_t &g) const {
  std::cout << "Discover: " << g[s] << std::endl;
  g[s].component_id = myNewId;
}

或者您可以使用属性地图。

put(component_id,s,myNewId);

如果您将其作为顶点属性。您还可以向BFS访问者构造函数添加一个变量,该变量是您希望顶点具有的新ID。

Here是一个示例自定义DFS将变量传递给构造函数。它与BFS的原理相同。