[bgl] depth_first_search does not compile. color_map howto?

Hi,
When using visitors with the depth_first_search algorithm I can
successfully compile and run this code:
//=========================================================
template<class Graph>
class Visitor: public default_dfs_visitor
{
public:
typedef typename
graph_traits<Graph>::vertex_descriptor Vertex;
void discover_vertex(Vertex v, const Graph& g)const
{cout << v << " "; return;}
};
void GLV_visit()
{
typedef adjacency_list
1. Do I need to provide a color_map parameter here? 2. If so, what is the simplest way to do that and provide an object of the appropriate type? I'd greatly appreciate a working code example. Examples and best practices for defining and handling external propery maps in general would be helpful. TIA, Joachim -- Interval Container Library [Boost.Icl] http://www.joachim-faulhaber.de

... forgot to attach the error message, here it is.
2012/6/25 Joachim Faulhaber
-- Interval Container Library [Boost.Icl] http://www.joachim-faulhaber.de

On Mon, 25 Jun 2012, Joachim Faulhaber wrote:
Yes, that is the issue; BGL can't create a default color map because your graph does not have a built-in vertex index map (which is provided automatically for vecS as vertex container but needs to be built manually for listS).
1. Do I need to provide a color_map parameter here?
Yes, or vertex_index_map.
2. If so, what is the simplest way to do that and provide an object of the appropriate type?
The simplest way is probably to use associative_property_map; see lines 129-140 of http://www.informatik.uni-koeln.de/scil/documentation/html/SteinerArborescen... for an example. You can also look at http://boost.2283326.n4.nabble.com/BGL-dijkstra-shortest-paths-with-listS-td... for other places where associative_property_map can be used.
There are several examples of external properties around; it's just hard to find examples that match up with graphs using listS since most people probably use vecS as their vertex container for performance. -- Jeremiah Willcock

Dear Jeremiah,
thank you for your answer. Unfortunately, it doesn't solve my
problems. I admit, I am pretty much frustrated with BGL usability.
Generally I am fond of boost and I recommend using it to my
colleagues. But currently my experiences with BGL is very
unsatisfactory. I hope there are solutions.
2012/6/28 Jeremiah Willcock
Using a generic library, I expect, that it is working for all instantiations of template parameters (particularly adjacency_list here), as long as the requirements for the Concepts of the parameters are not violated. In my use case I am experimenting with different Types for the edge and vertex lists and I had hoped, that the use of a very basic algorithm like depth_first_search would gracefully support any of those admissible instantiations.
From your recommendation ...
... I have tried to fix my example:
//=========================================================
template<class Graph>
class Visitor: public default_dfs_visitor
{
public:
typedef typename
graph_traits<Graph>::vertex_descriptor Vertex;
void discover_vertex(Vertex v, const Graph& g)const
{cout << v << " "; return;}
};
struct Int{
Int(): _value(0){}
Int(int val): _value(val){}
int _value;
};
void GLL_visit()
{
typedef adjacency_list

On Fri, 29 Jun 2012, Joachim Faulhaber wrote:
BGL can be quite frustrating to use, especially since diagnosis of errors is not always good. The trunk version should be better by a little bit, but it still does require some experience to track down errors.
Yes, and one of the requirements in the documentation is that if you do not provide a color map as an argument, a default version will be used and that version needs a vertex index map (either as an argument or a built-in property map in the graph).
You are mixing named parameters and positional parameters -- try either: boost::depth_first_search(g, vis, pm_color); or: boost::depth_first_search(g, visitor(vis).color_map(pm_color)); and see if either of those work. -- Jeremiah Willcock

2012/6/29 Jeremiah Willcock
yes, this was it! Thanks for the answer. This is little trap one can fall into. When extending examples from the documentation using different overloads of an algorithm it is easy to overlook that parameter types are changing from 'named' to 'positional' mode... Thanks for helping :) Cheers, Joachim -- Interval Container Library [Boost.Icl] http://www.joachim-faulhaber.de
participants (2)
-
Jeremiah Willcock
-
Joachim Faulhaber