Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] remove all children of a given vertex in a directed graph
From: Alex Hagen-Zanker (ahh34_at_[hidden])
Date: 2012-05-11 11:12:47


On 11/05/2012 15:36, NsPx wrote:
>
> I would like to delete a vertex and all its children vertices in a
> directed graph. For example,
>
<>
> typedef adjacency_list<boost::vecS, boost::vecS,
> boost::bidirectionalS, vertex_info> Graph;
<>
> // remove all children and the given vertex : doesn't work
> for( it=allChildren.begin(), ite=allChildren.end(); it!=ite; ++it)
> {
> remove_vertex(*it, *myGraph);
> }
>

It doesn't work because removing a vertex invalidates existing vertex
descriptors when vertices are stored in a vector.

See also the second table in:
http://www.boost.org/doc/libs/1_49_0/libs/graph/doc/adjacency_list.html.

You could use the following instead:

typedef adjacency_list<boost::vecS, boost::listS, boost::bidirectionalS,
vertex_info> Graph;



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