Boost logo

Boost Users :

From: Aaron Windsor (aaron.windsor_at_[hidden])
Date: 2008-03-26 09:06:19


On Sun, Mar 23, 2008 at 6:21 PM, Bernhard Lippmann
<bernhard.lippmann_at_[hidden]> wrote:
>
> 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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net