我希望是否有任何其他方法可以在没有 print_edges() 或 print_graph() 函数的情况下使用 boost::filtered_graph ()。
在链接中here ,似乎过滤器仅在调用打印图形或打印边缘函数时才对每个节点起作用。
我确实理解谓词在打印到 std::cout 时作用于图形的每个节点或边缘
有没有其他方法,我可以使用它?我可以使用 for_each(begin_iter, end_iter) 或类似的东西吗?请建议。
最佳答案
您可以使用 #include <boost/graph/graph_utility.hpp>
其中定义了大量迭代器宏:BGL_FORALL_EDGES、BGL_FORALL_VERTICES、BGL_FORALL_OUTEDGES 等。
您的典型代码可能如下所示:
BGL_FORALL_VERTICES(src, g, MyGraph_t )
{
BGL_FORALL_OUTEDGES(src, ed, g, MyGraph_t )
{
MyGraph_t::vertex_descriptor tgt = target(ed, g);
... do something ...
}
}
无论 MyGraph_t 是 filtered_graph 还是 adjacency_list 或任何其他 BGL 图类型,此代码都将起作用。
关于c++ - 在没有 print_graph() 的情况下使用 boost filtered_graph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21263667/