for v in reversed(sorted(del_list)):
print 'deleting vertex', int(v)
## for ve in v.out_edges():
## print 'deleting edges', ve.source(), ve.target()
## g.remove_edge(ve)
g.remove_vertex(v, fast=True)
The above code will delete vertex 3 first, then vertex 1 as expected.
However, in order to keep correct topology, we should delete some related
edges first, like the three commented lines (start with "##").
But if you uncomment the three lines, weird thing happens: the program
will delete vertex 1 first, then vertex 3.
Of course I can sort the vertex index instead of vertex descriptor to avoid
the problem. But I am wondering where is wrong. Could anyone explain this?
You should never remove vertex or edge descriptors when iterating
over them, since this invalidates the iterators. If you plan to
remove vertices or edges during iteration, you must first store them
somewhere (such as in a list) and remove them only after no iterator
is being used. Removal during iteration will cause bad things to
happen.
This is what you are trying to do if you uncomment the lines, and it
might cause problems. Don't do that; store the edges in a list first.
Sorry to bother again. I am not sure how python build-in methods "sorted"
and "reversed" work on vertex descriptor list. The following code snippet
output:
vertex 3
vertex 5
vertex 1
code snippet:
del_list = [g.vertex(1), g.vertex(5), g.vertex(3)]
for v in reversed(sorted(del_list)):
print 'vertex', int(v)
Is it correct? I am using debian wheezy, and install graph-tool by adding
Be careful, if you use "wheezy" you will install a _very old_ version of
graph-tool! Newer versions do not compile in wheezy, so you must use
jessie or sid!
What you are seeing is probably a bug from a long time ago that already
got fixed...