CoCalc Shared Files2014-10-19-120435-python-igraph.sagews
Authors: Harald Schilly, ℏal Snyder, William A. Stein
Views : 6
Description: We now have python-igraph -- https://pypi.python.org/pypi/python-igraph/0.7

python-igraph

We now have the python-igraph package, which provides high performance graph data structures and algorithms:

https://pypi.python.org/pypi/python-igraph/0.7

There is a tutorial here -- http://igraph.org/python/doc/tutorial/tutorial.html

We use a little bit here, fixing a little mistake in the tutorial...

It has many interesting graph layout algorithms, so could be useful to Sage users, in addition to the standard Sage graph functionality.

import igraph

print igraph.__version__

0.7.0
g = igraph.Graph()
g

<igraph.Graph object at 0x7fa889001de0>
g.add_vertices(3)

g.add_edges([(0,1), (1,2)])

# expected error

Error in lines 2-2 Traceback (most recent call last): File "/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/.sagemathcloud/sage_server.py", line 841, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/usr/local/sage/sage-6.3.beta6/local/lib/python2.7/site-packages/igraph/__init__.py", line 230, in add_edges return GraphBase.add_edges(self, es) TypeError: iterable must return pairs of integers or strings
g.add_edges([(2,0)])
print g

IGRAPH U--- 6 7 -- + edges: 0--1 1--2 0--2 2--3 3--4 4--5 3--5
g.get_eid(2,3)
g.delete_edges(3)
igraph.summary(g)

3 IGRAPH U--- 6 6 --
g = igraph.Graph.Tree(127, 2)
igraph.summary(g)

IGRAPH U--- 127 126 --
layout = g.layout_reingold_tilford(root=2)

layout

<Layout with 127 vertices and 2 dimensions>
p = igraph.plot(g, layout = layout); p

<igraph.drawing.Plot object at 0x7fa88901a110>
p.save('a.png')
salvus.file('a.png')