User Tools

Site Tools


chicoutimi_2016:tulip_api_first_step

Visual Analytics Course

Instructor: Guy Melançon (email: Guy dot Melancon at labri dot fr)

Chicoutimi Summer 2016 roadmap / May 3, 3pm course

Tulip API first step

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.

python

Tulip's scripting language is python.

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.

  • Open a python view and have a look

Properties, properties, properties, ...

To properly use the API you need to understand a bit about Tulip's internal data model of a graph.

  • Tulip takes care of managing nodes and edges for you. You do not need to care about how these nodes and edges are stored. The API offers ways to access them and ask about values associated woth them.
  • Anything about nodes and edges are stored in properties. Take a graph with node set (vertices) and edge set .
    • A property is a (pair of) map(s) , mapping nodes and edges to values in a set .
    • The set can take different value types: real numbers (doubles), integers, boolean, string.
    • Properties can also be a color (a triple of integers), a coordinate in the plane or space (a couple or triple of double values), a size (a quadruple of double values, RGB and opacity).
  • Tulip uses properties itself to internally deal with different views. All internal properties are viewsomething: viewMetric (a statistics stored as double), viewLayout to store node positions, viewSize, viewColor, etc.
  • Tulip allows you to access any property you like
prop = graph.getDoubleProperty('viewMetric')
  • or create a new (user defined) property
prop = graph.getDoubleProperty('my_property')

The spreadsheet view lets you see all properties (and values assigned to all nodes or edges).

Graph topology

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

Graph distance and Dijkstra's algorithm

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.

  • We need a map storing distance to node source node
    • With the special case
    • All other nodes are initialized with
  • We keep track of nodesuntil every node has been visited
  • We additionally store parent nodes: a map
    • that is, for each node we store which node (its neighbor) from which is reached b a shortest path from
  • We first set , None for all vertices
  • We keep looping until all nodes have been visited
    • We grab a non-visited node with minimum distance from (minimum value for ), mark it as visited
    • We visit its neighbors and update their distance to and parent node if needed

Solution. Le fichier Tulip (.tlpx) téléchargeable contient deux scripts, l'un à la mode “impérative”, l'autre à la mode “objet”.

/net/html/perso/melancon/Visual_Analytics_Course/data/pages/chicoutimi_2016/tulip_api_first_step.txt · Last modified: 2016/05/26 03:47 by melancon