[BGL] Problem with color maps for undirected_dfs_visit
I'm trying to implement a DFS visitor and using it with undirected_dfs_visit, but I'm getting a segfault which relates to the edge color map. I've made the following test app for illustration: **************** START CODE **************** #include <vector> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/undirected_dfs.hpp> using namespace boost; struct Types { typedef adjacency_list<vecS, vecS, undirectedS, property<vertex_color_t, default_color_type>, property<edge_color_t, default_color_type, property<edge_index_t, int> > > GraphType; typedef std::vector<default_color_type> ColorVec; typedef color_traits<default_color_type> Color; }; int main() { Types::GraphType g(6); add_edge(0,1,g); add_edge(1,2,g); add_edge(2,3,g); add_edge(2,4,g); add_edge(4,5,g); Types::ColorVec v_colors(num_vertices(g), Types::Color::white()); Types::ColorVec e_colors(num_edges(g), Types::Color::white()); default_dfs_visitor visitor; undirected_depth_first_visit(g, 0, visitor, make_iterator_property_map(&v_colors[0], get(vertex_index, g)), make_iterator_property_map(&e_colors[0], get(edge_index, g))); }; **************** END CODE **************** The code crashes in undirected_dfs.hpp line 73 the first time it's trying to access a color from the edge color map: EColorValue uv_color = get(edge_color, *ei); Valgrind turns up a lot of illegal reads/writes to the edge_color_map as well, so I'm guessing that I've screwed up on the colormap creation. Could anyone point out my error? Also, is this an error that could be caught compile time by adding some sort of concept check? Thanks in advance for any help! Regards, -- Tarjei
Hi Tarjei, You need to initialize the edge index property map (only the vertex index map is automatically initialized, and then only for VertexList=vecS). Cheers, Jeremy On Thu, 13 Nov 2003, Tarjei Knapstad wrote: tarjei> I'm trying to implement a DFS visitor and using it with tarjei> undirected_dfs_visit, but I'm getting a segfault which relates to the tarjei> edge color map. I've made the following test app for illustration: tarjei> tarjei> **************** START CODE **************** tarjei> tarjei> #include <vector> tarjei> #include <boost/graph/adjacency_list.hpp> tarjei> #include <boost/graph/undirected_dfs.hpp> tarjei> tarjei> using namespace boost; tarjei> tarjei> struct Types tarjei> { tarjei> typedef adjacency_list<vecS, vecS, undirectedS, tarjei> property<vertex_color_t, default_color_type>, tarjei> property<edge_color_t, default_color_type, tarjei> property<edge_index_t, int> > > GraphType; tarjei> tarjei> typedef std::vector<default_color_type> ColorVec; tarjei> typedef color_traits<default_color_type> Color; tarjei> }; tarjei> tarjei> int main() tarjei> { tarjei> Types::GraphType g(6); tarjei> tarjei> add_edge(0,1,g); tarjei> add_edge(1,2,g); tarjei> add_edge(2,3,g); tarjei> add_edge(2,4,g); tarjei> add_edge(4,5,g); tarjei> tarjei> Types::ColorVec v_colors(num_vertices(g), Types::Color::white()); tarjei> Types::ColorVec e_colors(num_edges(g), Types::Color::white()); tarjei> tarjei> default_dfs_visitor visitor; tarjei> undirected_depth_first_visit(g, 0, visitor, tarjei> make_iterator_property_map(&v_colors[0], tarjei> get(vertex_index, g)), tarjei> make_iterator_property_map(&e_colors[0], tarjei> get(edge_index, g))); tarjei> }; tarjei> tarjei> **************** END CODE **************** tarjei> tarjei> The code crashes in undirected_dfs.hpp line 73 the first time it's tarjei> trying to access a color from the edge color map: tarjei> tarjei> EColorValue uv_color = get(edge_color, *ei); tarjei> tarjei> Valgrind turns up a lot of illegal reads/writes to the edge_color_map as tarjei> well, so I'm guessing that I've screwed up on the colormap creation. tarjei> Could anyone point out my error? Also, is this an error that could be tarjei> caught compile time by adding some sort of concept check? tarjei> tarjei> Thanks in advance for any help! tarjei> tarjei> Regards, tarjei> -- tarjei> Tarjei tarjei> tarjei> tarjei> _______________________________________________ tarjei> Boost-users mailing list tarjei> Boost-users@lists.boost.org tarjei> http://lists.boost.org/mailman/listinfo.cgi/boost-users tarjei> ---------------------------------------------------------------------- Jeremy Siek http://php.indiana.edu/~jsiek/ Ph.D. Student, Indiana Univ. B'ton email: jsiek@osl.iu.edu C++ Booster (http://www.boost.org) office phone: (812) 855-3608 ----------------------------------------------------------------------
On Thu, 2003-11-13 at 17:09, Jeremy Siek wrote:
Hi Tarjei,
You need to initialize the edge index property map (only the vertex index map is automatically initialized, and then only for VertexList=vecS).
Hmm, ok, but I still don't quite understand. I thought that initializing the std::vector holding the colors was sufficient...? To my understanding an iterator_property_map is just a property map which iterates through some other container (that can provide a RandomAccessIterator) actually holding the properties? Obviously there's some connection I don't quite get here... I also don't quite understand the EColorValue uv_color = get(edge_color, *ei); call in undir_dfv_impl. It asks for the edge_color at the edge_descriptor *ei, but from where? Anyway, I don't really even need an edge_index property here (or do I?), it was more or less to try to get this working. Could you please provide a bit more detailed description of how I should initialize the edge colormap properly? Thanks a lot, Tarjei
On Thu, 13 Nov 2003, Tarjei Knapstad wrote:
tarjei> I'm trying to implement a DFS visitor and using it with tarjei> undirected_dfs_visit, but I'm getting a segfault which relates to the tarjei> edge color map. I've made the following test app for illustration: tarjei> tarjei> **************** START CODE **************** tarjei> tarjei> #include <vector> tarjei> #include <boost/graph/adjacency_list.hpp> tarjei> #include <boost/graph/undirected_dfs.hpp> tarjei> tarjei> using namespace boost; tarjei> tarjei> struct Types tarjei> { tarjei> typedef adjacency_list<vecS, vecS, undirectedS, tarjei> property<vertex_color_t, default_color_type>, tarjei> property<edge_color_t, default_color_type, tarjei> property<edge_index_t, int> > > GraphType; tarjei> tarjei> typedef std::vector<default_color_type> ColorVec; tarjei> typedef color_traits<default_color_type> Color; tarjei> }; tarjei> tarjei> int main() tarjei> { tarjei> Types::GraphType g(6); tarjei> tarjei> add_edge(0,1,g); tarjei> add_edge(1,2,g); tarjei> add_edge(2,3,g); tarjei> add_edge(2,4,g); tarjei> add_edge(4,5,g); tarjei> tarjei> Types::ColorVec v_colors(num_vertices(g), Types::Color::white()); tarjei> Types::ColorVec e_colors(num_edges(g), Types::Color::white()); tarjei> tarjei> default_dfs_visitor visitor; tarjei> undirected_depth_first_visit(g, 0, visitor, tarjei> make_iterator_property_map(&v_colors[0], tarjei> get(vertex_index, g)), tarjei> make_iterator_property_map(&e_colors[0], tarjei> get(edge_index, g))); tarjei> }; tarjei> tarjei> **************** END CODE **************** tarjei> tarjei> The code crashes in undirected_dfs.hpp line 73 the first time it's tarjei> trying to access a color from the edge color map: tarjei> tarjei> EColorValue uv_color = get(edge_color, *ei); tarjei> tarjei> Valgrind turns up a lot of illegal reads/writes to the edge_color_map as tarjei> well, so I'm guessing that I've screwed up on the colormap creation. tarjei> Could anyone point out my error? Also, is this an error that could be tarjei> caught compile time by adding some sort of concept check? tarjei> tarjei> Thanks in advance for any help! tarjei> tarjei> Regards, tarjei> -- tarjei> Tarjei tarjei> tarjei> tarjei> _______________________________________________ tarjei> Boost-users mailing list tarjei> Boost-users@lists.boost.org tarjei> http://lists.boost.org/mailman/listinfo.cgi/boost-users tarjei>
participants (2)
-
Jeremy Siek
-
Tarjei Knapstad