[boost] [Graph] need help on remove_vertex ....

Hi, I need some help on the remove_edge, remove_vertex functions. What is wrong with my two functions, removing edges or vertex from a graph with a given name in the coressponding property map. pls. see code snippet after calling my function a second time I get a run time error. I did the code as shown under http://www.boost.org/libs/graph/doc/adjacency_list.html but I feel the rebuild of the vectors did not work, any input is welcome Best Bernhard this is the code in the main program: // ok MyElementList.RemoveVertexByName("vss!",g, VertexNamesMap); // now the run time error ... MyElementList.RemoveVertexByName("vss!s",g, VertexNamesMap); this is the called sub routine: /*$ **************************************************************************** ** Method Name RemoveVertexByName ()... Parameters std::string AE_Name Return long , Index in Map Description remove vertex with a given name see http://www.boost.org/libs/graph/doc/adjacency_list.html for troubles **************************************************************************** ****** */ void TElementList::RemoveVertexByName(std::string elementname, TGraph &g, TVertexNameMap &VertexNamesMap) { Tvertex_iter vi, vi_end, next; tie(vi, vi_end) = vertices(g); for (next = vi; vi != vi_end; vi = next) { ++next; if (VertexNamesMap[*vi] == elementname) { remove_vertex(*vi, g); } } } /*$ **************************************************************************** ** Method Name RemoveEdgeByName () Parameters std::string AE_Name Return long , Index in Map Description Removes the edge (u,v) from the graph. void remove_edge(vertex_descriptor u, vertex_descriptor v, adjacency_list& g) void remove_edge(edge_descriptor e, adjacency_list& g) **************************************************************************** ****** */ void TElementList::RemoveEdgeByName(std::string elementname, TGraph &g, TEdgeNameMap &EdgeNamesMap) { Tedge_iter xei, xei_end; for (tie(xei, xei_end) = edges(g); xei != xei_end; ++xei) { Tedge_descriptor e = *xei; if (EdgeNamesMap[e] == elementname) { remove_edge (e,g); } // Tvertex_descriptor u = source(e, g), v = target(e, g); // if .... (option 29 } } No virus found in this outgoing message. Checked by AVG. Version: 7.5.519 / Virus Database: 269.21.8/1339 - Release Date: 22.03.2008 16:43

On Sun, Mar 23, 2008 at 6:21 PM, Bernhard Lippmann
Hi,
I need some help on the remove_edge, remove_vertex functions. What is wrong with my two functions, removing edges or vertex from a graph with a given name in the coressponding property map. pls. see code snippet after calling my function a second time I get a run time error. I did the code as shown under http://www.boost.org/libs/graph/doc/adjacency_list.html but I feel the rebuild of the vectors did not work, any input is welcome
Best
Bernhard
this is the code in the main program:
// ok MyElementList.RemoveVertexByName("vss!",g, VertexNamesMap); // now the run time error ... MyElementList.RemoveVertexByName("vss!s",g, VertexNamesMap);
this is the called sub routine:
/*$ **************************************************************************** ** Method Name RemoveVertexByName ()... Parameters std::string AE_Name Return long , Index in Map Description remove vertex with a given name see http://www.boost.org/libs/graph/doc/adjacency_list.html for troubles **************************************************************************** ****** */ void TElementList::RemoveVertexByName(std::string elementname, TGraph &g, TVertexNameMap &VertexNamesMap) { Tvertex_iter vi, vi_end, next; tie(vi, vi_end) = vertices(g); for (next = vi; vi != vi_end; vi = next) { ++next; if (VertexNamesMap[*vi] == elementname) { remove_vertex(*vi, g); } }
}
Hi Bernhard, Your RemoveVertexByName function will work only if the vertices in your graph are stored in a list, but your email seems to suggest that you have them stored in a vector. If your vertices are stored in a vector, you're not going to be able to remove them in a single loop like this because you'll invalidate the underlying std::vector iterators you're using when you remove vertices. If you are using a list to store your vertices, this code should work as long as VertexNamesMap is populated with all of the vertices in your original graph. Regards, Aaron
participants (2)
-
Aaron Windsor
-
Bernhard Lippmann