I now get it, when I said {1:{1:'hola'}... it understood {1:
{1:list('hola').... and hence treated hola as a list.
I don't recall reading that one should input as a list if one selects
multiedges, at least I don't recall seeing an example with that
notation. This is, I think a little bit of a tricky thing, since the
notation works for regular graphs.
At least I know what to do now. But I don't know if the behavior here
is intended. Probably it works like that to have a short way of
entering several edges with one level. Or the authors did not intend
it to work that way, in which case it could be fixed.
One example with that behavior in the documentation would be great.
Thanks a bunch.
-Adrian.
On Aug 22, 9:55 pm, Jason Grout <[EMAIL PROTECTED]> wrote:
> 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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---