-1

I'm new to the boost graph library and given a directed graph, I'd like to build a level ordered vector of vertices, i.e. given vertices A,B,C,D,E,F and edges

A->B, A->C, B->D, C->E and E->F

get a vector of vertices which are at the same depth in the graph (or tree for that matter):

[ [A], [B, C], [D, E], [F] ]

Thanks for your help.

digital_revenant
  • 3,274
  • 1
  • 15
  • 24

1 Answers1

0

What have you tried so far?

Here is a general, high-level description of how I might tackle this.

  1. Create a data structure to hold the "level ordered vector"

  2. Create a visitor which holds this structure, and a current depth counter

  3. Do a graph traversal starting at A which updates the visitor with the depth from A and the current node in the correct place in the "level ordered vector"

Another way:

  1. Use the bundled properties feature to save the depth of each node

  2. Traverse the graph, updating the node property with the correct depth as you go.

  3. Iterate over the nodes to determine where each should be placed in your "level ordered vector" according to the depth property as set by the traversal in the previous step.

For reference, here are the breadth first traversal methods http://www.boost.org/doc/libs/1_54_0/libs/graph/doc/breadth_first_search.html

ravenspoint
  • 19,093
  • 6
  • 57
  • 103