0

I need to iterate over a graph(DFS), but without using the standard DFS visitor callback technique.

Is there a way to iteratively traverse the graph in this manner ?

for(each edge in my graph visited in dfs) {
    do some complicated stuff;
}
subzero
  • 27
  • 5
  • 1
    wait, you want DFS but not DFS? Do you simply mean you don't like the BGL API? – sehe May 20 '14 at 09:23
  • Yes. I am integrating boost into some existing code and it would be much simpler if it worked this way. – subzero May 20 '14 at 09:38

1 Answers1

0

Yes, depending on the concrete graph type, you can just do

auto e = edges(g);
for (auto it = e.first; it != e.second; ++it)
{
}

You might want in_edges(g) or out_edges(g) if your graph models different concepts: http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/graph_concepts.html

Edit Update to the comments:

You'll have to wrap it yourself then. You could force a pull interface using Boost Coroutine. Or you can use the visitor to fill a queue, which you consumer after the DFS completed.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thanks for the quick response. But how would I go about accessing the edges in DFS order ? – subzero May 20 '14 at 09:37
  • How is this DFS? It looks like it just iterates the edges in no particular order. – pbible May 20 '14 at 13:47
  • @pbible If you look at the conversation, you'll see I said exactly that. The answer is, the OP will have to write it himself, because BGL has no such API – sehe May 20 '14 at 13:48