Boost logo

Boost Users :

From: Stephane Grabli (Stephane.Grabli_at_[hidden])
Date: 2005-11-16 13:09:30


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 <Stephane.Grabli_at_[hidden]> wrote:
>
>>Hi,
>>
>>I'm new to the BGL and I'm trying to use the strong_components
>>algorithm, defined this way:
>>
>>template <class Graph, class ComponentMap, class P, class T, class R>
>>typename property_traits<ComponentMap>::value_type
>>strong_components(Graph& g, ComponentMap comp,
>> const bgl_named_params<P, T, R>& params = all defaults)
>>
>>with a graph
>>defined like this:
>>
>>typedef adjacency_list<listS,listS,directedS> 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<listS, listS, directedS,
> property<vertex_index_t, std::size_t> > Graph;
>
> For step (2), see the code in the BGL FAQ, #5 (http://tinyurl.com/9skck)
>
> For step (3), first #include <boost/vector_property_map.hpp>, then:
>
> typedef graph_traits<Graph>::vertices_size_type v_size_t; //the range
> of ComponentMap
> vector_property_map< v_size_t, property_map<Graph, vertex_index_t>::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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net