djhenderson / python-graph

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

edges() and neighbors() behavior #75

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create the graph with some nodes (with one loop)
{{{
from pygraph.classes.graph import graph
g = graph()
map(g.add_node,["Me","You","We"])
edges = [("Me","You"),("Me","We"),("You","We"),("Me","Me")]
for e in edges:
   g.add_edge(e)
}}}
2. Retrieve the list of edges using the method edges()
3. Retrieve the list of neighbors of the node with the loop using the
method neighbors(node)

What is the expected output? What do you see instead?
When calling edges() I expect
[('Me', 'Me'), ('Me', 'You'),  ('You', 'We'), ('Me', 'We')]
since is an undirected graph by construction.
But the function outputs
[('Me', 'Me'), ('Me', 'You'), ('You', 'Me'), ('You', 'We'), ('We', 'Me'),
('Me', 'We'), ('We', 'You')]
which si the correct answer for a directed graph. Being g an undirected
graph, this answer of edges() implies a multigraph.

When calling g.neighbors("Me") I expect
['You', 'We', 'Me']
but (consequence of the behavior of edges(), I guess) one gets
['You', 'We', 'Me', 'Me']
which again implies a double loop on Me, i.e. a multigraph

What version of the product are you using? On what operating system?
1.7.0, Ubuntu 9.10

Please provide any additional information below.

Original issue reported on code.google.com by ajuanpi on 6 May 2010 at 11:50

GoogleCodeExporter commented 9 years ago
This function may be useful to solve the problem. Though is like a hack.
It should be solved in a lower level

def unique(seq, keepstr=True):
  t = type(seq)
  if t in (str, unicode):
    t = (list, ''.join)[bool(keepstr)]
  seen = []
  return t(c for c in seq if not (c in seen or seen.append(c)))

source: http://code.activestate.com/recipes/502263/

Original comment by ajuanpi on 7 May 2010 at 12:11

GoogleCodeExporter commented 9 years ago
Sorry for taking so long to reply. I'm accepting the issue.

Original comment by pmatiello on 25 May 2010 at 10:45

GoogleCodeExporter commented 9 years ago
I believe it's fixed in r705.

Feel free to test it downloading the code from the trunk. If something was left 
out,
let us know.

Thank you for your report.

Original comment by pmatiello on 26 May 2010 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by pmatiello on 2 Jun 2010 at 3:21