[Boost-users] [BGL] Color Maps

54 views
Skip to first unread message

pablo barrio lópez-cortijo

unread,
Jan 28, 2010, 8:58:25 PM1/28/10
to boost...@lists.boost.org
Hi there! I'm new to Boost (and also to this mailing list). I'm using depth_first_search and it's vital for me to be able to specify the root vertex (4th argument), and that means also specifying the Color Map, which I don't care too much about. It'd be great to have a default color map but I'm a newbie and I didn't found anything in the docs. My initial options were:

a) Using sth like a "default_color_map" class. I ignore if there is such thing.

b) Creating a property map out of a vector, something like "vector_property_map<default_color_type>". I tried and it didn't work.

c) Including a property in my graph called "color" of type "default_color_type", and creating a property map out of it. Didn't work either. Actually, I get an error when trying to include the property with that type (compiles if the property is an int).

d) Just copying the color map that the algorithm uses when called without the color map argument. Hoping to find out how the BGL code works was simply unrealistic so I abandoned the idea.

Is there any way to easily instantiate a Color Map? I'd post my code, but I have 6 or 7 versions none of which work. Any help will be much appreciated. Thanks ahead!

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Andrew Sutton

unread,
Jan 29, 2010, 8:50:40 AM1/29/10
to boost...@lists.boost.org
 
Is there any way to easily instantiate a Color Map? I'd post my code, but I have 6 or 7 versions none of which work. Any help will be much appreciated. Thanks ahead!

 Yes. First, I would recommend using the named parameter version of the call since it lets you omit optional parameters. If you really want to pass an exterior color map, you could do it this like this.

// Set up an external property, initialized to white
// by default.
vector<default_color_type> colors(num_vertices(g), white_color);

// Call the DFS algorithm
// I forget the actual syntax of the call, but it should be similar to this.
depth_first_search(g,
    visitor(vis)
    .start_vertex(v)
    .color_map(colors(&colors[0]));

Hope that helps,

Andrew Sutton
andrew....@gmail.com

pablo barrio lópez-cortijo

unread,
Jan 30, 2010, 1:24:26 PM1/30/10
to boost...@lists.boost.org
Hi Andrew, thanks for your help.

I would recommend using the named parameter version of the call since it lets you omit optional parameters.

It seems like the right approach. So now my code is as follows:

    typedef graph_traits<graph_t>::vertex_descriptor Vertex;
    Vertex source;

... some code that finds the appropriate vertex

    // DFSActions is the DFS visitor, with actions on vertex discover and finish
    DFSActions actions(this);

    // Calling DFS with named parameters
    depth_first_search(*g, visitor(actions), root_vertex(source));

Problem: the code doesn't compile, and I'm sure the fault is in "root_vertex(source)". This is the (very synthesized) error thrown by the compiler:

property_map.hpp: In instantiation of ‘boost::property_traits<boost::bgl_named_params<long unsigned int, boost::root_vertex_t, boost::no_property> >’:
depth_first_search.hpp:192:   instantiated from ‘void boost::depth_first_search( long line ) [ with REALLY long line ]’
depth_first_search.hpp:222:   instantiated from ‘void boost::depth_first_search( long line ) [ with REALLY long line ]’
graphdef.cpp:134:   instantiated from here

graphdef.cpp:134:   instantiated from here
property_map.hpp:31: error: no type named ‘key_type’ in ‘struct boost::bgl_named_params<long unsigned int, boost::root_vertex_t, boost::no_property>’
property_map.hpp:33: error: no type named ‘reference’ in ‘struct boost::bgl_named_params<long unsigned int, boost::root_vertex_t, boost::no_property>’
property_map.hpp:34: error: no type named ‘category’ in ‘struct boost::bgl_named_params<long unsigned int, boost::root_vertex_t, boost::no_property>’

And many other errors, but this is the first one. To check if the problem was in my "source" vertex, I changed the call to DFS with the default value for the root_vertex (looked up in the header file):

    depth_first_search(*g, visitor(actions), root_vertex(*vertices(*g).first));

The error keeps showing. Having a look at the DFS source code, it seems that the named param function expects a root_vertex of type root_vertex_t, which appears several times in the error msg. The Boost docs specify a type of graph_traits<graph_t>::vertex_descriptor, which is what I'm using now. I suppose it's the same type, but I've not found the type definition. I'm sure it must be a very stupid mistake, but I can't see it.

Any clues?

Andrew Sutton

unread,
Jan 31, 2010, 12:09:33 PM1/31/10
to boost...@lists.boost.org
    // Calling DFS with named parameters
    depth_first_search(*g, visitor(actions), root_vertex(source));

 The named parameter DFS only takes two parameters - sort of. The graph and a named_params composition. You probably need to write:

dfs(*g, visitor(actions).root_vertex(source));

Note the "." instead of a ",".

Andrew Sutton
andrew....@gmail.com
Reply all
Reply to author
Forward
0 new messages