Hi, I have a question about the BGL. I'm trying to get remove_edge_if to work with a multigraph. The documentation doesn't seem to prohibit this: http://www.boost.org/libs/graph/doc/MutableGraph.html http://www.boost.org/libs/graph/doc/adjacency_list.html However, the following sample code crashes. It is intended to add two vertices v0 and v1, and to add two edges from v0 to v1, and then to remove all of the edges by passing an always-true predicate to remove_edge_if. ------------------- #include <boost/config.hpp> #include <iostream> // for std::cout #include <utility> // for std::pair #include <boost/utility.hpp> // for boost::tie #include <boost/graph/graph_traits.hpp> // for boost::graph_traits #include <boost/graph/adjacency_list.hpp> #include <boost/graph/graphviz.hpp> using namespace std; using namespace boost; typedef adjacency_list<vecS, vecS, bidirectionalS > UnderlyingGraphType; typedef boost::graph_traits<UnderlyingGraphType>::vertex_descriptor vertexType; typedef boost::graph_traits<UnderlyingGraphType>::edge_descriptor edgeType; class truePredicate { public: truePredicate() {} bool operator()(edgeType e){ cout << "edgePred got " << e <<endl; cout << "about to return true!!!" << endl; return true; } }; int main(int,char*[]) { UnderlyingGraphType G = UnderlyingGraphType(); vertexType v0, v1; edgeType e01_1, e01_2; bool inserted; v0 = boost::add_vertex(G); v1 = boost::add_vertex(G); cout << "v0: " << v0 << endl; cout << "v1: " << v1 << endl; boost::tie(e01_1, inserted) = boost::add_edge(v0,v1,G); cout << "e1: " << e01_1 << endl; cout << "ins1: " << inserted << endl; boost::tie(e01_2, inserted) = boost::add_edge(v0,v1,G); cout << "e2: " << e01_1 << endl; cout << "ins2: " << inserted << endl; boost::write_graphviz(cout,G); boost::remove_edge_if(truePredicate(), G); boost::write_graphviz(cout,G); } ------------------- I'm using Boost 1_31_0 on Debian GNU/Linux with g++-3.0. The result of running the above code on my system is: ------------------- v0: 0 v1: 1 e1: (0,1) ins1: 1 e2: (0,1) ins2: 1 digraph G { 0; 1; 0->1 ; 0->1 ; } edgePred got (0,1) about to return true!!! edgePred got (0,1) about to return true!!! edgePred got (0,1) about to return true!!! edgePred got (4294967295,1919379812) about to return true!!! Segmentation fault ------------------- thanks for your help, bayle p.s. btw, i'm in the process of wrapping BGL for Python using Boost::Python, in case anyone is interested.
participants (1)
-
Bayle Shanks