Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converting between Graph and DiGraph naturally #5046

Closed
jasongrout opened this issue Jan 21, 2009 · 5 comments
Closed

converting between Graph and DiGraph naturally #5046

jasongrout opened this issue Jan 21, 2009 · 5 comments

Comments

@jasongrout
Copy link
Member

This should work. At the very minimum, there should be a sensible error message:

sage: DiGraph(graphs.PathGraph(4))                                             
---------------------------------------------------------------------------
NetworkXError                             Traceback (most recent call last)

/home/grout/.sage/<ipython console> in <module>()

/home/grout/sage-3.2.3/local/lib/python2.5/site-packages/sage/graphs/graph.pyc in __init__(self, data, pos, loops, format, boundary, weighted, implementation, sparse, vertex_labels, **kwds)
   8362             else:
   8363                 if implementation == 'networkx':
-> 8364                     self._backend = NetworkXGraphBackend(networkx.XDiGraph(data, selfloops=loops, **kwds))
   8365                 elif implementation == 'c_graph':
   8366                     if data is None:

/home/grout/sage-3.2.3/local/lib/python/networkx/xdigraph.py in __init__(self, data, name, selfloops, multiedges)
    118         self.multiedges=multiedges
    119         if data is not None:
--> 120             convert.from_whatever(data,create_using=self)
    121         self.name=name
    122 

/home/grout/sage-3.2.3/local/lib/python/networkx/convert.py in from_whatever(thing, create_using)
    114 
    115     raise networkx.NetworkXError, \
--> 116           "Input is not a known data type for conversion."
    117 
    118     return 

NetworkXError: Input is not a known data type for conversion.
sage: Graph(DiGraph({0:[1,2],1:[0,3]}))
---------------------------------------------------------------------------
NetworkXError                             Traceback (most recent call last)

/home/grout/.sage/<ipython console> in <module>()

/home/grout/sage-3.2.3/local/lib/python2.5/site-packages/sage/graphs/graph.pyc in __init__(self, data, pos, loops, format, boundary, weighted, implementation, sparse, vertex_labels, **kwds)
   7022                         self.add_vertices(xrange(data))
   7023                     else:
-> 7024                         self._backend = NetworkXGraphBackend(networkx.XGraph(data, selfloops=loops, **kwds))
   7025                 elif implementation == 'c_graph':
   7026                     if data is None:

/home/grout/sage-3.2.3/local/lib/python/networkx/xgraph.py in __init__(self, data, name, selfloops, multiedges)
    111         self.multiedges=multiedges
    112         if data is not None:
--> 113             self=convert.from_whatever(data,create_using=self)
    114         self.name=name
    115 

/home/grout/sage-3.2.3/local/lib/python/networkx/convert.py in from_whatever(thing, create_using)
    114 
    115     raise networkx.NetworkXError, \
--> 116           "Input is not a known data type for conversion."
    117 
    118     return 

NetworkXError: Input is not a known data type for conversion.

Component: graph theory

Issue created by migration from https://trac.sagemath.org/ticket/5046

@jasongrout
Copy link
Member Author

comment:1

Currently, there are to_directed and to_undirected methods, but the above is the natural way to convert things in Sage.

@jasongrout
Copy link
Member Author

comment:2

Oh, and don't forget that you can specify whether loops are allowed or not. That replaces the to_simple function.

@rlmill
Copy link
Mannequin

rlmill mannequin commented Feb 17, 2009

comment:3

Fixed by the patch at #5171, I believe.

@rlmill
Copy link
Mannequin

rlmill mannequin commented Feb 17, 2009

comment:4

I just checked this example:

sage: DiGraph(graphs.PathGraph(4))
Path Graph: Digraph on 4 vertices

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Feb 18, 2009

comment:5

Fixed via #5171.

Cheers,

Michael

@sagetrac-mabshoff sagetrac-mabshoff mannequin modified the milestones: sage-3.4.1, sage-3.3 Feb 18, 2009
@sagetrac-mabshoff sagetrac-mabshoff mannequin closed this as completed Feb 18, 2009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant