[bgl] Problem with topological_sort

Hello, When I run the example code of topo_sort.cpp in the BGL examples folder, it works perfectly. However, if I replace in this example: typedef adjacency_list<vecS, vecS, directedS, property<vertex_color_t, default_color_type> > Graph; By: typedef adjacency_list<listS, listS, directedS, property<vertex_color_t, default_color_type, property<vertex_index_t, int > > > Graph; It compiles, but during execution, some assert occurs. This assert occurs deep within my std::vector implementation (msvc8.0), in the call stack, the latest reference to boost is > TopoSort.exe!boost::iterator_property_map<std::_Vector_iterator<enum boost::default_color_type,std::allocator<enum boost::default_color_type> >,boost::adj_list_vertex_property_map<boost::adjacency_list<boost::listS,boost::listS,boost::directedS,boost::property<enum boost::vertex_color_t,enum boost::default_color_type,boost::property<enum boost::vertex_index_t,int,boost::no_property> >,boost::no_property,boost::no_property,boost::listS>,int,int const &,enum boost::vertex_index_t>,enum boost::default_color_type,enum boost::default_color_type &>::operator[](void * v=0x00355eb8) Line 349 + 0x67 bytes C++ Or, for people who don't read msvc on a daily basis, it indicated the line 350 of property_map.cpp : /*template<...> class iterator_property_map : ... { */ inline R operator[](key_type v) const { return *(iter + get(index, v)) ; } Does anybody have any idea of what the problem might be ? Best regards, -- Loïc

On 7/20/06, Loïc Joly <loic.joly@reportive.com> wrote:
Hello,
When I run the example code of topo_sort.cpp in the BGL examples folder, it works perfectly. However, if I replace in this example:
typedef adjacency_list<vecS, vecS, directedS, property<vertex_color_t, default_color_type> > Graph;
By:
typedef adjacency_list<listS, listS, directedS, property<vertex_color_t, default_color_type, property<vertex_index_t, int > >
Graph;
It compiles, but during execution, some assert occurs.
<snip>
Does anybody have any idea of what the problem might be ?
Best regards,
-- Loïc
Hi Loïc, Did you initialize the vertex index map? If you're using a std::vector to store the vertices, you get a vertex index map for free, but if you use anything else, (a std::list, for example) you must actually go through all of the vertices and set their index, like so: property_map<graph_t, vertex_index_t>::type index = get(vertex_index, G); graph_traits<graph_t>::vertex_iterator vi, vend; graph_traits<graph_t>::vertices_size_type cnt = 0; for(tie(vi,vend) = vertices(G); vi != vend; ++vi) put(index, *vi, cnt++); Regards, Aaron

Aaron Windsor a écrit :
Did you initialize the vertex index map? If you're using a std::vector to store the vertices, you get a vertex index map for free, but if you use anything else, (a std::list, for example) you must actually go through all of the vertices and set their index, like so:
Thank you for the information. I solved my problem in another way, using the topological_sort overload where I specify the color property map manually, and which does not need vertex indexes, but your code will prove useful when I used other algorithms that use the index. Thank you. Best regards, -- Loïc
participants (2)
-
Aaron Windsor
-
Loïc Joly