Why does my digraph think it has multiple edges?

42 views
Skip to first unread message

sac...@gmail.com

unread,
Feb 24, 2014, 4:41:18 PM2/24/14
to sage-s...@googlegroups.com
I want to construct a poset from a digraph, but, for some reason, the digraph thinks it has multiple edges, so sage constructs a poset whose Hasse diagram is a multi-digraph (and this is inconvenient, but a surmountable problem). Any ideas what is causing this? (It's entirely possible this is sensible behavior and I've missed something in the documentation.)

sage: vertices = [1,2,3,-1,-2,-3]
sage: roots = [[1,-2],[1,-3],[3,2],[1,-1]]
sage: G = DiGraph(dict.fromkeys(vertices,dict()))
sage: for v in roots:
    if v[0]==-v[1]:
        G.add_edge(v[0],v[1])
        G.show()
    else:
        G.add_edge(v[0],-v[1])
        G.add_edge(v[1],-v[0])
        G.show()
....:
sage: G
Multi-digraph on 6 vertices
sage: G.edges()
[(-3, -1, None),
 (-2, -1, None),
 (1, -1, None),
 (1, 2, None),
 (1, 3, None),
 (2, -3, None),
 (3, -2, None)]
sage: G.has_multiple_edges()
False

MartinX

unread,
Feb 25, 2014, 3:47:51 PM2/25/14
to sage-s...@googlegroups.com
The DiGraph constructor checks the data to determine the graph characteristics from the data if they are left as defaults, which for multiedges is None. In your case you are constructing a graph with vertices but no edges for which the constructorsets multiedges to True. (digraph.py lines 809-817)   Add `multigraph=False` to the DiGraph constructor arguments if you do not want a multi-Digraph:

vertices = [1,2,3,-1,-2,-3]

roots
= [[1,-2],[1,-3],[3,2],[1,-1]]

G
= DiGraph(dict.fromkeys(vertices,dict()), multiedges=False);G

giving:

Digraph on 6 vertices
Reply all
Reply to author
Forward
0 new messages