[Graph] problem with arguments of transitive closure algorithm ?

Hello. Using Boost 1.34.1 (with g++-3.4.2) and more specifically the Boost Graph library, I stumbled on a small problem with the transitive_closure algorithm. I saw in the documentation that I can get a map containing the mapping between the vertices of the original graph and the ones in the transitive closure graph (the orig_to_copy parameter). But every time I call the method, I get an empty map as a result. To sum up my code, I use the following data structures for the graph: typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS > graph_t; typedef boost::graph_traits < graph_t >::vertex_descriptor vertex_t; and the following one for the expected map: typedef std::map < vertex_t, vertex_t > ioMap_t; The graphs and map are declared the following way: graph_t myGraph; graph_t myTCGraph; ioMap_t ioMap; I used both versions of the algorithm: 1) using named parameters, I call: transitive_closure(myGraph, myTCGraph, orig_to_copy(ioMap)); 2) using "standard" parameters, I call: transitive_closure(myGraph, myTCGraph, ioMap, get(vertex_index, myGraph)); So, the main question is easy: Where did I write something wrong ? :-) A remark though. I see that the declaration in the case of "standard" parameters is the following : template <typename Graph, typename GraphTC, typename G_to_TC_VertexMap, typename VertexIndexMap> void transitive_closure(const Graph& g, GraphTC& tc, G_to_TC_VertexMap g_to_tc_map, VertexIndexMap index_map); So, if I understand everything (I'm far from speaking C++ fluently), this means that the g_to_tc_map parameter is passed by value. Shouldn't it be rather passed by reference (this would explain my problem as, when debugging my code, I saw that the map is correctly filled in the transitive_closure method but the caller gets back nothing at all) ? Hope I managed to be clear and thanks for your help. Best regards, Emmanuel

Hi Emmanuel, On 8/1/07, Emmanuel Viaud <emmanuel.viaud@gmail.com> wrote:
You did not pass transitive_closure a property map. Instead you give the algorithm a std::map. typedef std::map < vertex_t, vertex_t > ioMap_t; ioMap_t vertex_vertex_map; boost::associative_property_map< std::map<vertex_t, vertex_t> > ioMap(vertex_vertex_map); Should work. To speed things up, you could also use a std::vector and let the specialization of property maps for pointers kick in. Create the container: std::vector<vertex_t> ioMap(num_vertices(myGraph)); and use it: transitive_closure(myGraph, myTCGraph, &ioMap[0], get(vertex_index, myGraph)); An additional function_requires < Mutable_LvaluePropertyMapConcept < G_to_TC_VertexMap, vertex > >(); in transitive_closure would have spotted that problem. HTH, Stephan

On 8/2/07, Stephan Diederich <stephan.diederich@googlemail.com> wrote:
Hi Emmanuel
Hi Stephan
And it works indeed. Thanks for showing me the error and for the tip using vector container (which, if I understood well, will only work if I use a vecS as the container for my vertices in the graph ?) Best regards, emmanuel
participants (2)
-
Emmanuel Viaud
-
Stephan Diederich