[BGL] Problem while "clearing" a graph
Hi all, i'm trying to clear an adjacency_list. I do the following, as described in the documentation : void MPPRectangleGraph::Clear(unsigned int flags) { bool erase_nodes = false, erase_edges = false, erase_all = false; if ( flags&GraphErase::eERASE_ALL ) erase_all = true; else { if ( flags&GraphErase::eERASE_NODES ) erase_nodes = true; if ( flags&GraphErase::eERASE_EDGES ) erase_edges = true; } if ( erase_nodes || erase_all ) { std::cout << "begin" << std::endl; MPPRectangleGraph::vertex_iterator vi, vi_end, next; boost::tie(vi, vi_end) = vertices(*this); unsigned int i=0; std::cout << num_vertices(*this) << std::endl; //clear_vertex(*vi, *this); //remove_vertex(*vi, *this); for (next = vi; vi != vi_end; vi = next) { std::cout << i++ << std::endl; ++next; clear_vertex(*vi, *this); remove_vertex(*vi, *this); } } std::cout << "end" << std::endl; } The MPPRectangleGraph is simply derived from adjacency_list. Containers are boost:vecS for both vertices and edges. When I have 100 vertices in my graph, I catch an unhandeld exception with catch(...) ("i" is printed only unitl 50), and, when my graph contains only 3 nodes, a std::exception is catched with this message : "vector<T> too long". Can you help ? Regards.
I tried something else which seems to work, however, it might be unefficient
:
if ( erase_nodes || erase_all )
{
while (num_vertices(*this)>0)
{
MPPRectangleGraph::vertex_iterator vi, vi_end, next;
boost::tie(vi, vi_end) = vertices(*this);
unsigned int i=0;
clear_vertex(*vi, *this);
remove_vertex(*vi, *this);
}
}
Any help would be appreciate.
Regards
2007/11/12, Olivier Tournaire
Hi all,
i'm trying to clear an adjacency_list. I do the following, as described in the documentation :
void MPPRectangleGraph::Clear(unsigned int flags) { bool erase_nodes = false, erase_edges = false, erase_all = false; if ( flags&GraphErase::eERASE_ALL ) erase_all = true; else { if ( flags&GraphErase::eERASE_NODES ) erase_nodes = true; if ( flags&GraphErase::eERASE_EDGES ) erase_edges = true; } if ( erase_nodes || erase_all ) { std::cout << "begin" << std::endl; MPPRectangleGraph::vertex_iterator vi, vi_end, next; boost::tie(vi, vi_end) = vertices(*this); unsigned int i=0; std::cout << num_vertices(*this) << std::endl; //clear_vertex(*vi, *this); //remove_vertex(*vi, *this); for (next = vi; vi != vi_end; vi = next) { std::cout << i++ << std::endl; ++next; clear_vertex(*vi, *this); remove_vertex(*vi, *this); } } std::cout << "end" << std::endl; }
The MPPRectangleGraph is simply derived from adjacency_list. Containers are boost:vecS for both vertices and edges. When I have 100 vertices in my graph, I catch an unhandeld exception with catch(...) ("i" is printed only unitl 50), and, when my graph contains only 3 nodes, a std::exception is catched with this message : "vector<T> too long". Can you help ?
Regards.
-- Le temps des cerises reviendra. Dans l'immédiat, c'est le temps des noyaux. Courage.
Olivier Tournaire wrote:
Any help would be appreciate.
This is the function that I came up with to erase a graph.
/*
* Note the use of the reverse_iterator
*/
template<typename T1> void
EraseGraph(T1& g)
{
typedef typename std::vector
Thank you, this is perfect
2007/11/13, Jeffrey Holle
Olivier Tournaire wrote:
Any help would be appreciate.
This is the function that I came up with to erase a graph.
/* * Note the use of the reverse_iterator */ template<typename T1> void EraseGraph(T1& g) { typedef typename std::vector
Vertices; Vertices vertices; typename boost::graph_traits<T1>::vertex_iterator vi,vi_end; for (boost::tie(vi,vi_end)=boost::vertices(g);vi!=vi_end;++vi) vertices.push_back(*vi); for (typename Vertices::reverse_iterator iter=vertices.rbegin();iter!=vertices.rend();++iter) { boost::clear_vertex(*iter,g); boost::remove_vertex(*iter,g); } } _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Le temps des cerises reviendra. Dans l'immédiat, c'est le temps des noyaux. Courage.
participants (2)
-
Jeffrey Holle
-
Olivier Tournaire