Re: [Boost-users] Remove edge

Hi Mr. Michael Olea, thanks for the replay, for the example code and for the help :-) I have tested your code and it works perfectly. But I have a problem, my graph isn't static but dynamic. In fact, the arcs weights are assigned dynamicaly and I don't understand how to adapt your code to my code. Can you help me? Sorry for my poor english, Best regards. This is an example of my code that I want to adapt with remove_edge_if(): #include <iostream> #include <ctime> #include <utility> #include <boost/graph/graph_traits.hpp> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/graph_utility.hpp> using namespace std; using namespace boost; HINSTANCE hInst; namespace boost { enum vertex_idNodo_t { vertex_idNodo = 1111 }; enum edge_arcoProprieta_t { edge_arcoProprieta = 2222 }; BOOST_INSTALL_PROPERTY(vertex, idNodo); BOOST_INSTALL_PROPERTY(edge, arcoProprieta); } typedef property<vertex_idNodo_t, int> NodoProperty; typedef property<edge_capacity_t, long> ArcoProperty; typedef adjacency_list<vecS, vecS, undirectedS, NodoProperty, ArcoProperty> Graph; Graph g; property_map<Graph, vertex_idNodo_t>::type idNodo = get(vertex_idNodo, g); property_map <Graph, edge_capacity_t >::type capacityCut = get(edge_capacity, g); graph_traits < Graph >::edge_iterator ei, ei_end; void deleteEdges() { for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) { if (capacityCut[*ei] < 10) { remove_edge(source(*ei,g),target(*ei,g),g); //Error invalidates the edge iterators :( } } } void main() { for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) { srand(static_cast<unsigned int>(time(NULL))); capacityCut[*ei] = rand() % 8 + 4; } } Passa a Yahoo! Mail. La webmail che ti offre GRATIS spazio illimitato, antispam e messenger integrato. http://it.mail.yahoo.com/

On Feb 16, 2009, at 11:37 PM, Gianni Loiacono wrote:
Hi Mr. Michael Olea, thanks for the replay, for the example code and for the help :-) I have tested your code and it works perfectly. But I have a problem, my graph isn't static but dynamic. In fact, the arcs weights are assigned dynamicaly and I don't understand how to adapt your code to my code. Can you help me? Sorry for my poor english, Best regards.
Ciao, signore Gianni Loiacono. It does not matter that the arc weights are assigned dynamically; what matters is that when deleteEdges is called they are stored in a property map that you have called "capacityCut". So, using the "Remover" class from ex_remove_if.cpp, you could write deleteEdges something like this: void deleteEdges() { Remover< property_map<Graph, edge_capacity_t>::type > r (capacityCut, 10); remove_edge_if(r, g); } However, if removing edges is a frequent operation, you might get better performance if you use an std::list rather than an std::vector to store edges. That is, replace this statement: typedef adjacency_list<vecS, vecS, undirectedS, NodoProperty, ArcoProperty> Graph; with this statement: typedef adjacency_list<listS, vecS, undirectedS, NodoProperty, ArcoProperty> Graph; Good luck, -- Michael

Hi Michael, Thanks thanks thanks thanks a lot :) It works perfectly ;) Best regards, Gianni. ________________________________ Da: Michael Olea <oleaj@sbcglobal.net> A: boost-users@lists.boost.org Inviato: Martedì 17 febbraio 2009, 22:26:20 Oggetto: Re: [Boost-users] [BGL] Remove edge On Feb 16, 2009, at 11:37 PM, Gianni Loiacono wrote:
Hi Mr. Michael Olea, thanks for the replay, for the example code and for the help :-) I have tested your code and it works perfectly. But I have a problem, my graph isn't static but dynamic. In fact, the arcs weights are assigned dynamicaly and I don't understand how to adapt your code to my code. Can you help me? Sorry for my poor english, Best regards.
Ciao, signore Gianni Loiacono. It does not matter that the arc weights are assigned dynamically; what matters is that when deleteEdges is called they are stored in a property map that you have called "capacityCut". So, using the "Remover" class from ex_remove_if.cpp, you could write deleteEdges something like this: void deleteEdges() { Remover< property_map<Graph, edge_capacity_t>::type > r(capacityCut, 10); remove_edge_if(r, g); } However, if removing edges is a frequent operation, you might get better performance if you use an std::list rather than an std::vector to store edges. That is, replace this statement: typedef adjacency_list<vecS, vecS, undirectedS, NodoProperty, ArcoProperty> Graph; with this statement: typedef adjacency_list<listS, vecS, undirectedS, NodoProperty, ArcoProperty> Graph; Good luck, -- Michael _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users Passa a Yahoo! Mail. La webmail che ti offre GRATIS spazio illimitato, antispam e messenger integrato. http://it.mail.yahoo.com/
participants (2)
-
Gianni Loiacono
-
Michael Olea