0

I was hoping if there is any other way to use boost::filtered_graph () without the print_edges() or print_graph() functions.

in the link here, it seems that the filter works on every node only when the print graph or print edge function is called.

I do understand that the predicate acts on every node or edge of the graph when it is getting printed to 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? please suggest.

Pogo
  • 475
  • 3
  • 19

1 Answers1

1

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.

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.

Michael Simbirsky
  • 3,045
  • 1
  • 12
  • 24
  • agreed, but will it work for predicate which I use for filtered_graph? for example, fg( G, edge_predicate) --> fg is filtered graph over G with a edge predicate. Now, how do I use BGL_FORALL_XX () ?? .. my edge predicate takes input as an edge from graph and modifies its properties. when print graph is called, it passes over each edge and calls the predicate on every edge. how do I realize this using BGL_FORALL_xxx ?? – Pogo Jan 22 '14 at 02:56