On Tue, 2003-03-04 at 21:44, Louis Lavery wrote: [I'm cross posting this to the main list as it contains some discussion wrt. BGL in general as well] I've got it sorted now after having another look at the BGL code, and having made my own version of undirected_dfs...
In an algorithm I'm working on I need to do an undirected_dfs using a visitor for analysis. I know my starting vertex, and I also want the DFS to skip one of the starting vertex's adjacent vertices (i.e. don't proceed in the "direction" from the starting vertex). Example:
d-e-f / a-b-c \ g-h-i
Starting vertex is 'c' and I want to eliminate the "d-e-f" branch, so the DFS finds "c-b-a" and "c-g-h-i".
My first idea was to set up a vertex color map, and set the color to black for vertex 'd' in the example above, but that doesn't do much good as the undirected_dfs sets all colors to white initially.
Doesn't it invoke dfs_visitor::initialize_vertex(u,g) on every vertex before the start of the search?
Yes.
My second thought was to feed the vertex I want to eliminate and the vertex color map to my dfs_visitor implementation, something like:
discover_vertex(u, g) { if (u == blocked) { vertex_colormap[u] = black; } }
If so, you could do something similar in there?
Although I can't find in the documentation that it's invoked after the colours have been set (but it is if you look in depth_first_search.hpp).
Failing that, dfs_visitor::start_vertex(s,g) is invoked on the source vertex once before the start of the search, so you could look for 'd' in there.
Hmm, it doesn't say that dfs_visitor::start_vertex(s,g) is called after the colours have been set (at least I can't find it in the docs), but it doesn't seem sensible to do it the other way round.
Yes, the colours are set before any of the vistor events are invoked and
this is now part of my solution after first having overlooked
start_vertex (initialize_vertex is called first on all vertices, then
start_vertex, and then the DFS proceeds with discover_vertex etc.)
My visitor now has two constructors, one for non-restrictive operation
which just takes an output iterator where I store the wanted results,
and one which also takes a reference to a vertex descriptor and
the vector containing the vertex colors. I've got pointers in the
visitor to both a vertex descriptor and a vector of vertex colours which
are initialized to NULL in the first, non-restrictive version so that I
can block 'd' if wanted. To outline (a bit pseudo-codish again):
template