GraphStream Tutorials

Interactions between GAMA and GraphStream

Thibaut Démare
LITIS - Université du Havre
NeX Days' 2015 - Agadir, Morocco
28 - 30 April 2015

Overview

  1. Netstream and gs-gama
  2. Tutorial: interaction with GAMA
    1. The GAMA Model
    2. Demo of interactions with GAMA

Netstream and gs-gama

What is Netstream ?

Netstream is basically a network protocol aiming at opening the GraphStream project access to other tools/projects/programs especially those written in other languages than Java. The interface is managed through a network interface (client/server approach).

The gs-gama Plug-in

gs-gama allows to connect a GAMA simulation with an external software supporting the NetStream protocol, such as GraphStream-based applications..
https://github.com/graphstream/gs-gama/wiki

Installation of gs-gama

  • From the USB key provided: none! It is already integrated in the special version of GAMA.
  • Otherwise: for future versions of gs-gama, install it as a plug-in from the Market Place.

Tutorial: interaction with GAMA

The GAMA Model

A model of mobility simulation

  • Some people over an environment move randomly.
  • Each person has a device which establishes a connection with closest devices.
  • This connection disappears as soon as they are too far.

Demo of interactions with GAMA

Installation of the GAMA model

From a GAMA version with gs-gama installed: import the
GAMAProject
folder as a project. Go to:
File > Import... > General > Existing projects into workspace

And then, select the folder
Demo_NeX2015
and click on
Finish
.
And you need to use the version 1.1.2 of GraphStream.

Demo of interactions with GAMA

GraphStream side

Open the connection and create a view:

NetStreamReceiver receiver = new NetStreamReceiver("localhost", 2001);
Viewer v = new Viewer(receiver.getDefaultStream());
v.addDefaultView(true);
						

Demo of interactions with GAMA

GAMA side

Open the connection :

gs_clear_senders;
gs_add_sender gs_host:"localhost" gs_port:2001 gs_sender_id:"humans";
						

Demo of interactions with GAMA

GAMA side

Create the nodes for each human agent

init {
	gs_add_node gs_sender_id:"humans" gs_node_id:name;
	gs_add_node_attribute gs_sender_id:"humans" gs_node_id:name gs_attribute_name:"x" gs_attribute_value:location.x;
	gs_add_node_attribute gs_sender_id:"humans" gs_node_id:name gs_attribute_name:"y" gs_attribute_value:location.y*-1;
}
						

Demo of interactions with GAMA

GAMA side

Update the position of agents

reflex move {
	if(tar.x = location.x and tar.y = location.y){
		tar <- any_location_in(world.shape);
	}
	do goto target:tar speed: 5;
	gs_add_node_attribute gs_sender_id:"humans" gs_node_id:name gs_attribute_name:"x" gs_attribute_value:location.x;
	gs_add_node_attribute gs_sender_id:"humans" gs_node_id:name gs_attribute_name:"y" gs_attribute_value:location.y*-1;
}
						

Demo of interactions with GAMA

GAMA side

Delete edges when two humans are no more connected

if(distance_to(self, humans_connected[i]) > length){
	gs_remove_edge gs_sender_id:"humans" gs_edge_id:(name + humans_connected[i].name);
	remove index:i from: humans_connected;
}
						
And add new edges for new connection

if(!contains(humans_connected, humans[i])){
	humans_connected <- humans_connected + humans[i];
	gs_add_edge gs_sender_id:"humans" gs_edge_id:(name + humans[i].name) gs_node_id_from:name gs_node_id_to:humans[i].name gs_is_directed:true;
}
						

Slides and Material



Get the Slides and Materials on-line:

http://graphstream.github.io/doc/Talks/NeX-2015/
https://github.com/graphstream/gs-talk/tree/NeX2015 (branch
NeX2015
)