c++ - 在没有 print_graph() 的情况下使用 boost filtered_graph

标签 c++ boost graph iterator boost-graph

我希望是否有任何其他方法可以在没有 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/

相关文章:

c++ - 如何在括号下获取用户输入?

c++ - CImg 编译器错误

c++ - 灵气 : rule for char [5]

c++ - 如何抑制 boost::spirit 中的跳过来解析带引号的字符串?

c++ - 为什么 "auto"在这种情况下不起作用?

javascript - 无法在 Canvas 上画细线?

c++ - 模板多重定义问题

c++ - dynamic_cast 还是冗余?

c++ - 拓扑排序算法不能正常工作

algorithm - 估计一棵树的大小