Hi,
I'm new to the BGL and I'm trying to use the strong_components
algorithm, defined this way:
template & params = all defaults)
with a graph
defined like this:
typedef adjacency_list
Stephane Grabli wrote:
Hi,
I'm new to the BGL and I'm trying to use the strong_components algorithm, defined this way:
template
typename property_traits<ComponentMap>::value_type strong_components(Graph& g, ComponentMap comp, const bgl_named_params & params = all defaults)
with a graph defined like this:
typedef adjacency_list
Graph; (in particular using listS for vertices storage).
Does anyone know how I should declare the ComponentMap property map? I couldn't figure this out from the documentation and the examples I've seen all assume that a vecS type storage is used for vertices in the graph. Thanks!
you could use this: typedef std::mapGraph::vertex_descriptor,Graph::vertices_size_type CN; CN v2comp; associative_property_map<CN> compmap(v2comp); HTH, -- Grégoire Dooms
Thanks Gregoire, Unfortunatly, I couldn't get this solution compiled... This might be a compilation issue as I don't see the problem in this approach. Stephane Grégoire Dooms wrote:
Stephane Grabli wrote:
Hi,
I'm new to the BGL and I'm trying to use the strong_components algorithm, defined this way:
template
typename property_traits<ComponentMap>::value_type strong_components(Graph& g, ComponentMap comp, const bgl_named_params & params = all defaults)
with a graph defined like this:
typedef adjacency_list
Graph; (in particular using listS for vertices storage).
Does anyone know how I should declare the ComponentMap property map? I couldn't figure this out from the documentation and the examples I've seen all assume that a vecS type storage is used for vertices in the graph. Thanks!
you could use this: typedef std::mapGraph::vertex_descriptor,Graph::vertices_size_type CN; CN v2comp; associative_property_map<CN> compmap(v2comp);
HTH, -- Grégoire Dooms
On 11/15/05, Stephane Grabli
Hi,
I'm new to the BGL and I'm trying to use the strong_components algorithm, defined this way:
template
typename property_traits<ComponentMap>::value_type strong_components(Graph& g, ComponentMap comp, const bgl_named_params & params = all defaults)
with a graph defined like this:
typedef adjacency_list
Graph; (in particular using listS for vertices storage).
Does anyone know how I should declare the ComponentMap property map? I couldn't figure this out from the documentation and the examples I've seen all assume that a vecS type storage is used for vertices in the graph. Thanks!
Stephane
Here's one way to do it:
(1) declare an interior vertex index map.
(2) initialize the interior vertex index map.
(3) compose the interior vertex index map with a vector property map.
For step (1), just replace your graph declaration with
typedef adjacency_list
Thanks Aaron, it seems to work. Could you please confirm that the key to use to access the vector_property_map is of type Graph::vertex_descriptor (and not of the type graph_traits<Graph>::vertices_size_type) ? In other words, to access this property map, the code should look like: for(tie(vi,vend) = vertices(g); vi != vend; ++vi){ v_size_t ind = get(index, *vi); cout << "Vertex " << ind<<" is in component " << get(componentMap,*vi) << endl; } and not with "get(componentMap, ind)". Thanks again! Stephane Aaron Windsor wrote:
On 11/15/05, Stephane Grabli
wrote: Hi,
I'm new to the BGL and I'm trying to use the strong_components algorithm, defined this way:
template
typename property_traits<ComponentMap>::value_type strong_components(Graph& g, ComponentMap comp, const bgl_named_params & params = all defaults)
with a graph defined like this:
typedef adjacency_list
Graph; (in particular using listS for vertices storage).
Does anyone know how I should declare the ComponentMap property map? I couldn't figure this out from the documentation and the examples I've seen all assume that a vecS type storage is used for vertices in the graph. Thanks!
Stephane
Here's one way to do it: (1) declare an interior vertex index map. (2) initialize the interior vertex index map. (3) compose the interior vertex index map with a vector property map.
For step (1), just replace your graph declaration with
typedef adjacency_list
> Graph; For step (2), see the code in the BGL FAQ, #5 (http://tinyurl.com/9skck)
For step (3), first #include
, then: typedef graph_traits<Graph>::vertices_size_type v_size_t; //the range of ComponentMap vector_property_map< v_size_t, property_map
::type > component_map( num_vertices(g), get(vertex_index,g) ); //g is an instance of Graph Now your component_map is ready to use. I haven't tested this code, of course.
Aaron
On 11/16/05, Stephane Grabli
Thanks Aaron, it seems to work. Could you please confirm that the key to use to access the vector_property_map is of type Graph::vertex_descriptor (and not of the type graph_traits<Graph>::vertices_size_type) ? In other words, to access this property map, the code should look like:
for(tie(vi,vend) = vertices(g); vi != vend; ++vi){ v_size_t ind = get(index, *vi); cout << "Vertex " << ind<<" is in component " << get(componentMap,*vi) << endl; }
and not with "get(componentMap, ind)". Thanks again!
Stephane
Yes, that sounds right. The ComponentMap should map vertex_descriptors to things of type vertices_size_type, so the key would be a vertex_descriptor. Aaron
On 11/15/05, Stephane Grabli
Hi,
I'm new to the BGL and I'm trying to use the strong_components algorithm, defined this way:
template
typename property_traits<ComponentMap>::value_type strong_components(Graph& g, ComponentMap comp, const bgl_named_params & params = all defaults)
with a graph defined like this:
typedef adjacency_list
Graph; (in particular using listS for vertices storage).
Does anyone know how I should declare the ComponentMap property map? I couldn't figure this out from the documentation and the examples I've seen all assume that a vecS type storage is used for vertices in the graph. Thanks!
When you use vecS for vertices storage, BGL provides a default property : vertex_index A lot of BGL algorithms (like strong_components) need a vertex_index_map and the default value is get(vertex_index, g). Unfortunately, when you use a different vertices container, there isn't the vertex_index property by default (because there isn't an efficient way to do it). So you have 2 solutions: 1) Add a vertex_index property in your graph 2) Provide a vertex_index_map when you call the strong_components algorithm (never use the default vertex_index_map unless the vertex_index property is defined) How to do 1) is explained by Aaron Windsor in this thread, and to do 2) follow the instuctions provide by Gregoire Dooms in this thread too, add call the algorithm with your vertex_index map: strong_components(g, comp, vertex_index_map (make_associative_property_map (your_map))); -- Johan
participants (4)
-
Aaron Windsor
-
Grégoire Dooms
-
Johan Oudinet
-
Stephane Grabli