Jason Grout wrote: > adrian wrote: >> Now, there is another problem: >> >> 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. >> >> Any help? > > It looks like it is creating an edge for every character in every other > label, which I think is a bug. I've created a ticket to track the > status of this bug: http://trac.sagemath.org/sage_trac/ticket/3928 > > Thanks for reporting it.
As Robert Miller noted on the ticket, there is nothing wrong going on here. The correct way to create the graph that you want is: 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')] Thanks, Jason --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---