[Boost-users] Remove edge

67 views
Skip to first unread message

Gianni Loiacono

unread,
Feb 16, 2009, 12:14:07 PM2/16/09
to boost...@lists.boost.org
Hi all,
I have defined my graph like this:
typedef adjacency_list<vecS, vecS, undirectedS,NodoProperty, ArcoProperty> Graph2;
And also:
graph_traits < Graph2 >::edge_iterator ei, ei_end;
Now, I want to delete all edges where the capacity is less than 10. Than I have write this code:
for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
  {
      if (capacity2[*ei] < 10)
      {
         remove_edge(source(*ei,g),target(*ei,g),g);
      }
  }

But the program after 2 cicles....it crashs :(...Why?
Thanks a lot





Passa a Yahoo! Mail.
La webmail che ti offre GRATIS spazio illimitato, antispam e messenger integrato.            

Michael Olea

unread,
Feb 16, 2009, 12:23:39 PM2/16/09
to boost...@lists.boost.org

On Feb 16, 2009, at 9:14 AM, Gianni Loiacono wrote:

> Hi all,
> I have defined my graph like this:
> typedef adjacency_list<vecS, vecS, undirectedS,NodoProperty,
> ArcoProperty> Graph2;
> And also:
> graph_traits < Graph2 >::edge_iterator ei, ei_end;
> Now, I want to delete all edges where the capacity is less than 10.
> Than I have write this code:
> for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
> {
> if (capacity2[*ei] < 10)
> {
> remove_edge(source(*ei,g),target(*ei,g),g);
> }
> }
>
> But the program after 2 cicles....it crashs :(...Why?
> Thanks a lot

remove_edge invalidates the edge iterators. You could use the
"remove_edge_if" function, or use listS for edges.

-- Michael


_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Gianni Loiacono

unread,
Feb 16, 2009, 12:39:59 PM2/16/09
to boost...@lists.boost.org
Hi Michael,
thanks for the answer.
Can you write me an example for to use the remove_edge_if() function?
I have read the docs on the site, but there isn't an example :(
Thanks a lot

Michael Olea

unread,
Feb 16, 2009, 1:53:25 PM2/16/09
to boost...@lists.boost.org

On Feb 16, 2009, at 9:39 AM, Gianni Loiacono wrote:

> Hi Michael,
> thanks for the answer.
> Can you write me an example for to use the remove_edge_if() function?
> I have read the docs on the site, but there isn't an example :(
> Thanks a lot

There's a little example attached below. I tried it with Boost 1.37.0
on Mac OS X 10.4.11 with g++ 4.0.1:

Graph Before remove_edge_if:
A <--> C E
B <--> B B D E C E
C <--> A B D
D <--> B C E
E <--> B D A B

Graph After remove_edge_if:
A <--> E
B <--> B B E C
C <--> B D
D <--> C
E <--> B A

-- Michael

ex_remove_if.cpp
Reply all
Reply to author
Forward
0 new messages