[BGL] dfs on graphs with bundled-properties
I am trying to use an adjacency list with bundled properties and running
into lots of problems. I'm wondering if bundled properties is mature
enough, or if I should resort to the older style using property maps.
Here's a description of one problem I've run into:
So I define my graph class with bundled properties as so:
struct MyV {
int numStars;
};
struct MyE {
int numStars;
};
typedef adjacency_list
On Wed, 2007-03-21 at 19:15 -0400, Naomi Fox wrote:
So I define my graph class with bundled properties as so:
struct MyV { int numStars; };
struct MyE { int numStars; };
typedef adjacency_list
MyGraph; Then in my main function, I make a MyGraph object and put in vertices and edges, and assign property values. That works fine. [snip] Then I perform dfs on my graph
depth_first_search(g, visitor(star_vis));
The problem in this case isn't the bundled properties, it's that
depth_first_search needs either a color map or an index map, neither of
which is available to it. I really wish we could make those error
messages make some sense, though :(
So, there are a couple of fixes. The goal is to associate each vertex
with an index, which is used to efficiently store extra data needed
inside the depth_first_search algorithm. There are two ways to do it.
The first involves putting the index into MyV, and then explicitly
passing an index map to depth_first_search:
struct MyV {
int numStars;
int index;
};
// after you build the graph...
int idx = 0;
BGL_FORALL_VERTICES(v, g, Graph)
g[v].index = idx++;
// calling DFS
depth_first_search(g, visitor(star_vis).
vertex_index_map(get(&MyV::index, g)));
Alternatively, only could use the more traditional properties approach
for the vertex index (MyV still works like it always did!), like this:
struct MyV {
int numStars;
}; // as you originally had written
// Tweak the graph type to stick a vertex_index in each vertex
typedef adjacency_list
participants (2)
-
Douglas Gregor
-
Naomi Fox