CoCalc Public Files2014-10-19-120435-python-igraph.sagewsOpen with one click!
Authors: Gihan Marasingha, Harald Schilly, ℏal Snyder, William A. Stein
Views : 47
Description: We now have python-igraph --
Compute Environment: Ubuntu 18.04 (Deprecated)


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

There is a tutorial here --

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__
g = igraph.Graph() g
<igraph.Graph object at 0x7fa889001de0>
g.add_edges([(0,1), (1,2)])
# expected error g.add_edges((5, 0))
Error in lines 2-2 Traceback (most recent call last): File "/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/.sagemathcloud/", 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/", 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)]) g.add_vertices(3) g.add_edges([(2,3),(3,4),(4,5),(5,3)]) 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 with 127 vertices and 2 dimensions>
p = igraph.plot(g, layout = layout); p
<igraph.drawing.Plot object at 0x7fa88901a110>'a.png') salvus.file('a.png')