简体   繁体   English

使用不带print_graph()的boost filter_graph

[英]Using boost filtered_graph without print_graph()

I was hoping if there is any other way to use boost::filtered_graph () without the print_edges() or print_graph() functions. 我希望是否还有其他方法可以使用boost :: filtered_graph()而不使用print_edges()或print_graph()函数。

in the link here , it seems that the filter works on every node only when the print graph or print edge function is called. 这里的链接中,似乎只有在调用print graph或print edge函数时,过滤器才能在每个节点上运行。

I do understand that the predicate acts on every node or edge of the graph when it is getting printed to std::cout 我确实了解谓词在打印到std :: cout时会作用在图的每个节点或边上

Is there any other way, I could use it ? 还有其他方法可以使用吗? could I use may be for_each( begin_iter, end_iter ) or something like that? 我可以使用for_each(begin_iter,end_iter)还是类似的东西? please suggest. 请提出建议。

You can use #include <boost/graph/graph_utility.hpp> where plenty of iterator macros are defined: BGL_FORALL_EDGES, BGL_FORALL_VERTICES, BGL_FORALL_OUTEDGES, etc. 您可以使用#include <boost/graph/graph_utility.hpp> ,其中定义了很多迭代器宏:BGL_FORALL_EDGES,BGL_FORALL_VERTICES,BGL_FORALL_OUTEDGES等。

Your typical code could look like: 您的典型代码如下所示:

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 ...
    }
}

This code will work regardless whether MyGraph_t is a filtered_graph or adjacency_list or any other BGL graph type. 无论MyGraph_t是filtered_graph还是adjacency_list或任何其他BGL图形类型,此代码都将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM