I looked over the code in sage/graphs/graph.py and when you pass dict
of sets sage just calls the networkx library. However, its a bug that
the loops parameter is not passed correspondingly.

This is easy to get around:

sage: e = {1 : set([1,2,3])}
sage: import networkx
sage: G=networkx.XDiGraph(e,selfloops=True)
sage: G.edges()

Since this G is a networkx graph, you might want to make it a Sage
graph:
sage: G=Graph(G,loops=True)
sage: G.edges()

Rado
On Sep 22, 10:39 am, Sébastien Labbé <sla...@gmail.com> wrote:
> Hi sage-devel,
>
> I am currently using Graphs and it is practical for me to create them
> from dictionary of sets instead of dictionary of lists :
>
> {{{
> sage: e = {1 : set([2,3])}
> sage: Graph(e).edges()
> [(1, 2, None), (1, 3, None)]
>
> }}}
>
> Everything is fine, but loops are ignored :
>
> {{{
> sage: d = {1 : set([1,2,3])}
> sage: Graph(d).edges()
> [(1, 2, None), (1, 3, None)]
>
> }}}
>
> Same problem with digraphs :
>
> {{{
> sage: DiGraph(d).edges()
> [(1, 2, None), (1, 3, None)]
>
> }}}
>
> Using the ``loops`` parameter doesn't help :
>
> {{{
> sage: Graph(d, loops=True).edges()
> [(1, 2, None), (1, 3, None)]
> sage: DiGraph(d, loops=True).edges()
> [(1, 2, None), (1, 3, None)]
>
> }}}
>
> If I convert the sets to lists, then loops are considered :
>
> {{{
> sage: d2 = dict( (x,list(y)) for (x,y) in d.items())
> sage: Graph(d2).edges()
> [(1, 1, None), (1, 2, None), (1, 3, None)]
> sage: DiGraph(d2).edges()
> [(1, 1, None), (1, 2, None), (1, 3, None)]
>
> }}}
>
> I know the dictionary of sets doesn't belong to the official input
> listed in the Graph? documentation, but it could work no? I can create
> the ticket is somebody confirm me that it's a good idea to fix this
> behavior.
>
> Sébastien Labbé
> PhD Student, Montréal-Montpellier
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to