wting / python-graph

Automatically exported from code.google.com/p/python-graph
Other
5 stars 4 forks source link

g.del_edge(e) failed but e is indeed in g.edges() #109

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The nodes of my graph is a set of tuples, e.g., (1.2, 3), (2, 4.5)
Basically, here's the bit of code that tries to delete some edge:

for edge in g.edges():
    if test(edge): 
        g.del_edge(edge)
# the test function does not alter the structure of the graph

At some point, the 3rd line throws an exception:

File "/home/blurrcat/PycharmProjects/pathPlan/world.py", line 234, in add_dobs
     self.g.del_edge(e1)
   File "/usr/local/lib/python2.7/dist-packages/pygraph/classes/graph.py", line 178, in del_edge
     self.node_neighbors[u].remove(v)
 ValueError: list.remove(x): x not in list

When I catch the excetpion in debug mode, I can see that `edge in g.edges()` is 
True, but `g.has_edge(edge)` is False. There must be some integrity errors..

I'm using Pygraph 1.8.1, python 2.7, Ubuntu 12.04

Original issue reported on code.google.com by blurr...@gmail.com on 27 Jun 2012 at 6:35

GoogleCodeExporter commented 9 years ago
Hello, blurrCat. I failed to reproduce the problem here. Could you provide a 
small program that produces the bug?

Also, as you are using a graph, trying to remove all edges listed in g.edges() 
will produce an exception as:
- g.edges() returns a pair of tuples (a,b) and (b,a) for each edge connecting 
nodes a and b;
- g.del_edge((a,b)) removes both (a,b) and (b, a)
- the for-each loop will call both g.del_edge((a,b)) (which should succeed) and 
g.del_edge((b,a)) (which should fail)

Original comment by pmatiello on 14 Jul 2012 at 9:05