Ticket #3928 (closed enhancement: invalid)

Opened 3 months ago

Last modified 3 months ago

additional docs for creating multiedge graphs

Reported by: jason Assigned to: rlm
Priority: minor Milestone: sage-duplicate/invalid/wontfix
Component: graph theory Keywords:
Cc:

Description

Say, I want to define a multigraph with selfloops, and edge labels..
One way to do this is:

import networkx
G=networkx.XDiGraph(selfloops=True,multiedges=True)
for i in range(3): G.add_node(i)
for i in [(1,1,'hola'),(1,1,'hi'),(1,2,'two'),(1,2,'dos'),
(2,1,'one')]: G.add_edge(i)
G=DiGraph(G)

Now, I would be tempted to just do the following:
G=DiGraph({1:{1:'hola',1:'hi',2:'two',2:'dos'},2:{1:'one'}},
loops=True, multiedges=True)

or trying

import networkx
G=networkx.XDiGraph({1:{1:'hola',1:'hi',2:'two',2:'dos'},2:{1:'one'}},
selfloops=True, multiedges=True)

But in each case  I get:

G.edges()

(1, 1, 'h'), (1, 1, 'i'), (1, 2, 'd'), (1, 2, 'o'), (1, 2, 's'), (2,
1,
'o'), (2, 1, 'n'), (2, 1, 'e')]


Which is not as intended for two reasons:  One is that the labels are
wrong, and the other one is that it created three edges from 1 to 2.

Change History

08/22/2008 02:48:39 PM changed by rlm

This is an error in input. I don't know how well the documentation explains this, but a dict-of-dicts representing a graph with multi-edges requires that the entries of the inner dicts be lists. That is the syntax. So if the documentation doesn't explain this carefully, it needs to.

The behavior you are getting is *exactly* as intended.

08/22/2008 08:56:31 PM changed by jason

  • status changed from new to closed.
  • resolution set to invalid.

Indeed, the following works:

sage: G=DiGraph({1:{1:['hola','hi'], 2:['two','dos']},2:{1:['one']}}, loops=True, multiedges=True)
sage: G.edges()
[(1, 1, 'hi'), (1, 1, 'hola'), (1, 2, 'dos'), (1, 2, 'two'), (2, 1, 'one')]

08/26/2008 08:43:31 AM changed by jason

  • priority changed from major to minor.
  • status changed from closed to reopened.
  • type changed from defect to enhancement.
  • resolution deleted.
  • summary changed from multiedge graphs create an edge for each character of a label to additional docs for creating multiedge graphs.

As per Robert's comment and the suggestion on sage-devel to add documentation, I'm reopening this to add the following to the documentation:

For a digraph with multiple edges and labels, one must provide a list
within the dictionary:

sage: G=DiGraph({1:{1:['hola','hi'], 2:['two','dos']},2:{1:['one']}},
loops=True, multiedges=True)
sage: G.edges()
[(1, 1, 'hi'), (1, 1, 'hola'), (1, 2, 'dos'), (1, 2, 'two'), (2, 1,
'one')]

08/26/2008 09:53:15 AM changed by mabshoff

  • status changed from reopened to closed.
  • resolution set to invalid.
  • milestone changed from sage-3.1.2 to sage-duplicate/invalid.

This is a *new* ticket - don't reopen closed tickets and reuse them for something related.

Cheers,

Michael