GraphStream Demos

Demonstrations of Sample Code Projects

Politechnika Poznańska – April 24th 2018

Outline

Installation of GraphStream

Get the tutorial workspace

  • Go to the tutorial page at github: github.com/graphstream/gs-talk
  • Get the code:
    • with the “Download Zip” button on github (will download an archive)
    • or through git:

In that project, we want the Demos/ folder.

Demo 1 – A simple static graph

Basic tasks with GraphStream

Create and display

Simple triangle
Simple triangle

Change the Display with CSS

We can improve the display with some CSS:

Triangle with CSS
Triangle with CSS

Access Elements

Constructive API vs. Events

  • Nodes and edges are removed the same way:

  • Each change, at anytime, is considered as an “event”.
  • The sequence of changes is seen as the dynamics of the graph.
  • There are many other ways to modify the graph.

Attributes

Data stored in the graph, on nodes and edges, are called “attributes”. An attribute is a pair (name,value).

Triangle with more CSS
Triangle with more CSS

Define Attributes

  • Not all attributes appear in the viewer.
  • Notice the way you can add arrays with setAttribute() and a variable number of arguments:

Retrieve Attributes

Several ways to retrieve attributes:

Special methods are here to simplify access:

Traversing the graph

GraphStream 2.0 uses Java 8 streams.

Access all nodes:

Equally for edges:

Index-based access

Indices for nodes:

Indices for edges:

⚠ indices remain the same as long as the graph is unchanged. ⚠

Travers from nodes and edges

You can also travel the graph using nodes:

  • Each node and edge allow to iterate on their neighborhood.
  • Toolkit is set of often used functions and small algorithms (see the API).

Orientation-based interaction

Directed edges stream from a given node:

Get a node’s degree, entering degree or leaving degree:

Demo 2

Dynamic Graphs

Sinks

  • A graph can receive events. It is a sink.
  • A sink is connected to a source using the Source.addSink(Sink) method.
  • Events are filtered by type (Elements Events and Attributes Events) :
    • addElementSink(ElementSink). Nodes and edges are Elements.
    • addAttributeSink(AttributeSink). Data attributes are stored on every element.
  • A Sink is both an ElementSink and AttributeSink.

ElementSink

ElementSink is an interface

AttributeSink

An attribute sink must follow the interface:

Source

A source is an interface that only defines methods to handle a set of sinks.

A first dynamic graph

Since Graph is a sink let’s create a graph from a set of events generated by a source.

  • A file with information about graphs (in a proper file format) can be a source of events.
  • A few graph file formats can handle dynamic.
  • GraphStream provides a file format (DGS) that allows to store and load dynamic graphs.
A graph from a file
A graph from a file

The GDS File Format

  • an for “add node”.
  • ae for “add edge”. ae "AB" "A" > "B" adds a directed edge between nodes A and B.
  • cn, ce and cg change or add one or more attributes on a node, an edge or the graph.
  • dn and de allow to remove nodes, edges.

How to handle dynamics

  • Storing temporal information is tricky.
  • Timestamps on events is a good way to encode time
  • But some events occur at the same time.
  • Let’s define time steps within events
  • st <number>

Steps in DGS

The ability to remove nodes and edges makes the format support dynamic.

Read the whole file

The file can be read entirely :

  • However this will send all events as fast as possible.
  • We have no control over the speed at which events occur.

Read the file event by event

We can read the DGS file event by event using an input source:

FileSource Pipeline
FileSource Pipeline

Read the file step by step

  • The nextEvents() method reads the file event by event (line by line in the file)
  • The nextStep()methods reads events up to the next st command (all the lines between two st lines)

Graph Layout

  • By default spacial positions of nodes on the display are automatically computed.
  • However one may want to position nodes by ourself.
  • One can do this using the x and y attributes:

Then one have to tell the viewer not to compute nodes positions:

Demo 3

Geographic Graphs

Working with geographic data

The gs-geography project brings the opportunity to read geographical data file format and produce graphs.

For instance, one can read an OpenStreetMap map to produce a graph of the road network, where nodes would be intersections and edges would be roads.

Simplifies road network of Poznan
Simplifies road network of Poznan

Graph Algorithms for geographic data

Betweenness Centrality of the road network of Poznan
Betweenness Centrality of the road network of Poznan