[Graph] depth_first_search and specifying the edge order
Hello. I have a graph that I'd like to run a depth first search on. Is it possible to control the order that edges for each node are traversed? I read through the documentation, but I didn't see anything that would do this. Thanks, David
I don't think you can do that. Can't you implement whatever rule you want on
with a custom visitor?
[]'s
Pedro
On Wed, Jul 30, 2008 at 5:52 PM, David Walthall wrote: Hello. I have a graph that I'd like to run a depth first search on. Is it
possible to control the order that edges for each node are traversed? I
read through the documentation, but I didn't see anything that would do
this. Thanks,
David _______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Aug 2, 2008, at 4:54 PM, Pedro Teixeira wrote:
I don't think you can do that. Can't you implement whatever rule you want on with a custom visitor?
The problem with using a visitor is that it's too late to sort the edges at that time (would slow down search considerably). What I think you want to do is maintain the edges in the correct order - i.e. customize the edge storage container.
On Wed, Jul 30, 2008 at 5:52 PM, David Walthall
wrote: Hello. I have a graph that I'd like to run a depth first search on. Is it possible to control the order that edges for each node are traversed? I read through the documentation, but I didn't see anything that would do this.
I believe that this is possible with BGL adjacency_list, but I haven't tried it myself. What you would do is to specify your own edge container with your own custom ordering - see http://www.boost.org/doc/libs/1_35_0/libs/graph/doc/using_adjacency_list.htm... :choosing-graph-type and especially the container generator stuff here: http://www.boost.org/doc/libs/1_35_0/libs/graph/doc/using_adjacency_list.htm... :custom-storage You would probably use a set (ordered however you want) and then tell BGL it's a non-associative sequence so it doesn't try to check for parallel edges that way. Again, I haven't tried this myself, but it is my understanding that the customized storage mechanism is there expressly to allow alternate ordering and multi-indexing, etc. Gordon
Hi Gordon, Gordon Woodhull wrote:
On Wed, Jul 30, 2008 at 5:52 PM, David Walthall
wrote: Hello. I have a graph that I'd like to run a depth first search on. Is it possible to control the order that edges for each node are traversed? I read through the documentation, but I didn't see anything that would do this. I believe that this is possible with BGL adjacency_list, but I haven't tried it myself.
What you would do is to specify your own edge container with your own custom ordering - see http://www.boost.org/doc/libs/1_35_0/libs/graph/doc/using_adjacency_list.htm...
and especially the container generator stuff here: http://www.boost.org/doc/libs/1_35_0/libs/graph/doc/using_adjacency_list.htm...
I didn't see anything in the documentation of adjacency_list that specified the order that they would be visited, and I don't want to rely on an implementation detail of the depth first search. Did I miss a mention of the ordering in there, or is it just implicit? Thanks, David
On Aug 6, 2008, at 1:17 PM, David Walthall wrote:
Hi Gordon,
Gordon Woodhull wrote:
On Wed, Jul 30, 2008 at 5:52 PM, David Walthall
wrote: Hello. I have a graph that I'd like to run a depth first search on. Is it possible to control the order that edges for each node are traversed? I read through the documentation, but I didn't see anything that would do this.
I believe that this is possible with BGL adjacency_list, but I haven't tried it myself. What you would do is to specify your own edge container with your own custom ordering - see http://www.boost.org/doc/libs/1_35_0/libs/graph/doc/using_adjacency_list.htm... :choosing-graph-type and especially the container generator stuff here: http://www.boost.org/doc/libs/1_35_0/libs/graph/doc/using_adjacency_list.htm... :custom-storage
I didn't see anything in the documentation of adjacency_list that specified the order that they would be visited, and I don't want to rely on an implementation detail of the depth first search. Did I miss a mention of the ordering in there, or is it just implicit?
The ordering comes from the container that is used to store the edges in each node. Again, I'm only an observer of the BGL and haven't written extensive code with it, but I would assume that if you used vector or list for your edge container type then you would get edge traversal in the order that the edges were created, because all it's doing is putting the edges into the source and target nodes' edge containers as you create them. If that's not the ordering that you want, then there are customization options so that you can substitute your own edge container with whatever ordering predicate you want. Gordon
participants (3)
-
David Walthall
-
Gordon Woodhull
-
Pedro Teixeira