Instructor: Guy Melançon (email:
Guy dot Melancon at labri dot fr)
Tulip is an amazingly powerful software library. Tulip comes packaged with a default GUI, but it mainly is a graph computing library; it offers routines to layout graphs (graph drawing), compute statistics on nodes and edges, different ways to assign and control visual variables on nodes and edges in a node-link view of a graph. It also offers alternative views on graphs and/or statistics on a graph: matrix views, histograms, scatterplots, parallel coordinates, etc.
The power of Tulip as a framework also holds from its scripting capabilities. All possibilities cannot be encapsulated under a GUI button. But you can always write a piece of code to do exactly what you want.
Tulip's scripting language is
from tulip import *
The default GUI offers a
python view – this is just a view on the graph, but a special one where you can run code that computes stuff on the graph and can modify it.
To properly use the API you need to understand a bit about Tulip's internal data model of a graph.
viewMetric(a statistics stored as double),
viewLayoutto store node positions,
prop = graph.getDoubleProperty('viewMetric')
prop = graph.getDoubleProperty('my_property')
The spreadsheet view lets you see all properties (and values assigned to all nodes or edges).
Any, all, algorithms on graphs rely on the possibility to know who is a neighbor of who. Given a node , you need to be able to iterate over 's neighbors, that is all nodes connected to .
prop = graph.getDoubleProperty('my_property') max_node_value = prop.getNodeMax() max_node = None for n in graph.getNodes(): if prop[n] == max_node_value: max_node = n
As an illustration, let's write code implementing Dijkstra's algorithm computing the distance of all nodes to a given source node .
Dijkstra's algorithm is quite simple.
Nonefor all vertices
Solution. Le fichier Tulip (
.tlpx) téléchargeable contient deux scripts, l'un à la mode “impérative”, l'autre à la mode “objet”.