Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Importing a Pajek Graph"

(Contributors)
(New Node)
 
(38 intermediate revisions by 5 users not shown)
Line 1: Line 1:
== PajekNetGraphGenerator Example Project  ==
+
==Multi-Population Pajek Graph Example==
  
STEM allows users to create a custom graph using Pajek. [[Image:Pajekscreenshot.jpg|frame|right|600px|Running the downloadable pajek scenario  (with edges displayed) the map view should appear as shown above.]] '''Pajek''' ([http://vlado.fmf.uni-lj.si/pub/networks/pajek/]) uses a kind of standardized language for describing networks. Some examples might be found here: http://vlado.fmf.uni-lj.si/pub/networks/pajek/testdata.zip. A subset of this language is interpreted by the PajekNetGraphGenerator to import arbitrary graphs into STEM. The PajekNetGraphGenerator allows creating user-defined graphs for STEM and is based on the Pajek format.  
+
This page is about the new '''Pajek''' format which is used in STEM releases since version 1.4.0 and in current milestone and integration builds. The old format that was used prior to 1.4.0 is still supported. Examples and documentation of the old format are available at the website download page for [http://www.eclipse.org/stem/download_sample.php?file=MultiPopulationExample_PajekGraphs.zip Multi-Population Pajek Graph Example].
  
An example project available for download may be found on the STEM website [http://www.eclipse.org/stem/download_sample.php?file=MultiPopulationExample_PajekGraphs.zip]. This is a standard STEM project that you may import into your workspace. It contains a graph generated using the Pajek Graph Generator. It also contains examples of the original Pajek files used to create the graphs found in the project. The files are located in the 'Doc' directory of the project. Also in that directory you can find additional documentation. Read the PajekStem_Format.doc for further information about the modified Pajek format. The PajekNetGraphGenerator is available in the graph creation dialogue of STEM. Please see the page [[Creating a new Graph]] for information on using this dialog.
+
==Create a Pajek file==
  
=== The Archive  ===
+
To create a Pajek file, download and use this ODS spreadsheet document [https://wiki.eclipse.org/images/b/bb/STEM_Pajek_Creator.zip here].
 +
Open the ODS spreadsheet, with LibreOffice [https://de.libreoffice.org/] and activate the macro element.
 +
Important: To do this, you must be running JRE [http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html] on your system.
  
The archive contains the STEM project MultiPopulationExample_PajekGraphs, a modification of the STEM project [http://wiki.eclipse.org/Sample_Projects_available_for_Download#Multi-Population_Example MultiPopulationExample]. The modification replaces the graph "3x3.graph" in the MultiPopulationNoVillageExample scenario with the imported graph "CC.graph".  
+
After modifying the spreadsheet, you can export the file as Pajek file. <br>
 +
Please click for this:
 +
<ol>
 +
<li>File</li>
 +
<li>ExportToPajek (The first option in the opened dialogue)</li>
 +
<li>Save it on your system (it will automatically be saved as a .net file) </li>
 +
</ol>
  
The imported Pajek NETs were created with the simple Excel macro Pajek2STEM.xls. This macro allows the easy modification of Pajek NETs; it is not necessary, but makes things far easier - especially for complex graphs. The macro imports a Pajek NET, allows for modification and adding of additional parameters and exports a Pajek NET that is still compatible with Pajek. The usage of this macro is straightforward. It is generally applicable to all Pajek NETs.  
+
 +
It is also possible to open and modify a Pajek file with a text editor, but it is much simpler to use the recommended spreadsheet.
  
'''Hint:'''
+
== File Format ==
Pajek allows (x,y,z)-coordinates between 0 and 1 only. STEM rounds coordinates to
+
two decimal places. This might result in strange shapes of the nodes. This
+
behaviour can be avoided if the coordinates are multiplied by a large factor, e.g.
+
by using the Excel macro.
+
'''Be aware:'''
+
the resulting file with coordinates larger than 1 cannot be imported into Pajek.
+
  
== Contributors  ==
+
STEM allows users to create a custom graph using a format similar to the '''Pajek''' ([http://vlado.fmf.uni-lj.si/pub/networks/pajek/]) format. The Libre Office spreadsheet produces a .net file that is in the correct format to be imported into STEM via the PajekNetGraphGenerator, which is available in the graph creation dialogue of STEM: [[Image:STEMDefineANewGraphIcon.png|50px]]
  
The PajekNetGraphGenerator was created and developed by the Department of Biological Safety of the Federal Institute for Risk Assessment in Germany.  
+
The format specification is as follows.  
  
  Armin A. Weiser, Matthias Filter
+
  *Vertices [number of nodes]
  Dept. Biological Safety
+
  [node number] [node name] [longitude] [latitude] [additional optional parameters] // spec for a new node
  Federal Institute for Risk Assessment
+
  [node number] [node URI] // spec for reference to existing node
  12277 Berlin
+
  ...
  Germany
+
  *Edges
   
+
  [origin node number] [destination node number] popID [populationID] rate [rate] // spec for migration edges
 +
[containing node number] [contained node number] // spec for containment edges
 +
...
  
=== Contact  ===
 
  
'''armin.weiser@bfr.bund.de'''
 
  
== PajekNetGraphGenerator and the STEM-related format extension to Pajek ==
+
== Node Format ==
  
The following reserved words are supported in the current Pajek Import implementation:
+
The keyword "*Vertices [number of nodes]" is the starting point for the nodes section. New nodes and references to existing nodes can be defined. Available formats appear below.
  
=== *Vertices n  ===
+
=== New Node ===
  
*n denotes the number of vertices in the graph.
+
'''[node number] [node name] [longitude] [latitude] [optional parameters]:'''
 +
*node number – unique node number (1, 2, 3, ...). Successive numbering of nodes is obligatory.
 +
*node name – unique name consisting of letters a..zA..Z and digits 0..9.
 +
*longitude, latitude – coordinates of the node. All values can be entered, but real world coordinates are: -180 <= longitude <= 180, 0 <= latitude <= 90.
  
In STEM nodes are the equivalent of vertices. The keyword "*Vertices n" is the starting point for the section, in which each vertex is described using following format:
+
'''Optional parameters:'''
 +
*popID – identifier of a population of the node. This parameter may be used repeatedly.
 +
*popCount – number of individuals living in the node. This parameter may be used repeatedly. The associated popID is the last mentioned one.
  
'''''vertexnum label x y [z] [shape] [additional optional parameters]'''''  
+
'''Example:'''
 +
1 Berlin 13.398889 52.500556 popID men popCount 1682900000 popID women popcount 1753500000
  
*vertexnum – vertex number (1; 2; 3&nbsp;:&nbsp;:&nbsp;: n). Successive numbering of vertices/nodes is obligatory.
+
Note: when using a Demographic Population Model in STEM you need only declare the main population name e.g. human in the list of nodes. You can refer to individual population subgroups (e.g., men, women) when declaring the populationID for the edges.
*label – if label starts with character a..zA..Z or 0..9 first blank determines end of the label (e.g., vertex1), labels consisting of more words must be enclosed in pair of special characters (e.g., ”vertex 1”). The definition of a label is obligatory.
+
*x, y, z – coordinates of vertex. The z coordinate is ignored in STEM. In Pajek the coordinates have values between 0 and 1, for STEM the values are not limited. x and y coordinates are obligatory for STEM.
+
  
*shape shape of object which represents vertex. The following shapes are supported by the PajekNetGraphGenerator: triangle, cross, ellipse, box, diamond. In STEM ellipse is represented as circle and box and diamond both are represented as box. box is the default value.
+
=== Node Reference ===
 +
'''[node number] [node URI]:'''
 +
*node number unique node number (1, 2, 3, ...). Successive numbering of nodes is obligatory.
 +
*node URI – URI of the node in STEM. If the URI starts with ''stem://org.eclipse.stem/node/geo/region/'', this prefix can be omitted.
  
'''Additional optional parameters:'''
+
'''Examples:'''
 +
1 stem://org.eclipse.stem/node/geo/region/FR-IF
 +
1 FR-IF
  
*s_size – size of the node. The default size is given by the parameter “Default Area” within the PajekNetGraphGeneratorImpl dialog in STEM. For STEM the size of the node is not limited. Overlaps of nodes are not checked by the importer, they are allowed.
+
== Edges Format  ==
  
''Example: 1 ”vertex one” 0.3456 0.1234 0.5 ellipse s_size 0.1''
+
The keyword "*Edges" is the starting point for the edges section. Two types of edges can be described; they are migration edges and containment edges. The formats are as follows.
  
''Parameters only valid in STEM (these parameters are ignored by Pajek):''
+
=== Migration Edges ===
  
*popid identifier of a population of the node. This parameter may be used repeatedly.
+
'''[origin node number] [destination node number] popID [populationID] rate [rate]:'''
 +
*origin node number number of the node the population migrates from. Has to be defined as node number in *Vertices.
 +
*destination node number – number of the node the population migrates from. Has to be defined as node number in *Vertices.
 +
*populationID – defines the ID of the migrating population.
 +
*rate - number population members migrating per day.
  
*popcount – number of individuals living in the node. This parameter may be used repeatedly. The associated popid is the last mentioned one.
+
'''Optional parameters:'''
 +
*date - specification a of date at which the migration rate is different from the standard value specified in the obligatory parameters. ISO 8601 standard is used (YYYY-MM-DD). This parameter may be used repeatedly.
 +
*rate - migration rate for the specified date. This parameter may be used repeatedly. The associated date is the last mentioned one.
  
''Example: 1 ”vertex one” 0.3456 0.1234 0.5 ellipse s_size 0.1 popid human popcount 24 popid anopheles popcount 1000''
+
'''Example:'''
 +
1 2 popID beef rate 1.0 date 2012-01-01 rate 10.0
  
<br>
+
Note: the optional parameters are not automatically implemented when you use the pajek graph in STEM. They are all specified in a single trigger which will be located in the "Triggers" folder of your project. The name of the trigger usually starts with "List platform:/resource" and ends with the name of your pajek graph. The trigger must be dragged into your scenario in order for the optional parameters to be implemented.
  
=== *Edges  ===
+
[[Image:STEMTriggerOptionalParametersPajekGraph.JPG|400px]]
  
The keyword "*Edges" is the starting point for the edges section. Each edge is described using the following format:
+
=== Containment Edges ===
  
'''''v1 v2 [borderlength] [additional optional parameters]'''''
+
'''[containing node number] [contained node number]:'''
 +
*containing node number – number of the node that contains the other node. Has to be defined as node number in *Vertices.
 +
*contained node number – number of the node that is contained by the other node. Has to be defined as node number in *Vertices.
  
*v1 – initial vertex number. The definition of v1 is obligatory. v1 has to be defined as node (see above: vertexnum).
+
'''Example:'''
*v2 – terminal vertex number. The definition of v2 is obligatory. v2 has to be defined as node (see above: vertexnum).
+
*borderlength – defines the borderlength for CommonBorderEdges
+
  
'''Additional optional parameters:'''
+
*Vertices 3
 +
1 Berlin 1 1 popID men popCount 100 popID women popCount 110
 +
2 Bonn 1.5 1 popID men popCount 100 popID women popCount 110
 +
3 Germany 1.2 1.2
 +
*Edges
 +
1 2 popID men rate 0.1
 +
2 1 popID women rate 0.2
 +
3 1
 +
3 2
  
''Parameters only valid in STEM (these parameters are ignored by Pajek):''
+
To edit the pajek graph in STEM, right-click on the graph and then select "display", as described here [https://wiki.eclipse.org/Visualizing_and_Editing_Graphs] and shown below:
  
*popid – identifier of a population migrating on the edge. This parameter may be used repeatedly. If this parameter and additionally “rateab” or “rateba” is set at least once then a MigrationEdge will be specified in STEM, otherwise a CommonBorderEdge will be defined.
+
[[Image:STEM_PajekExample.png|600px]]
  
*rateab – fraction of the population in node v1 migrating over the edge to the terminal node v2 in a given time period (see http://wiki.eclipse.org/Transportation_Models#Migration_Between_Regions). This parameter may be used repeatedly. The associated popid is the last mentioned one. The default value is 0.
+
== Using the dialog ==
  
*rateba – fraction of the population in node v2 migrating over the edge to the node v1 in a given time period. This parameter may be used repeatedly. The associated popid is the last mentioned one. The default value is 0.
+
[[Image:STEMDisplayPajekGraphGenerator.png|right|300px]]
 +
The dialog to import a Pajek graph from a file is shown on the right. It is available in the STEM Graph Dialog. The following parameters are available for importing:
 +
*Pajek File - The file from which the graph is imported. A file dialog is available to select the file.
 +
*Scaling Factor - A factor by which all coordinates specified in the file are scaled during import. If node has the coordinates 10.0/20.0 in the file and the scaling factor is 2.0, the node's resulting coordinates in STEM are 20.0/40.0.
 +
*Node Size - In STEM each imported node appears as a square for visualization. This parameter specifies the edge length of the squares for all imported nodes.
 +
*Use global Region Names - If selected, the URIs for the imported nodes will be of the type ''stem://org.eclipse.stem/node/geo/region/*****''. This has the advantage, that the nodes can be accessed by just using that last part of the URI ''*****''. This option should only be used if node names specified in the Pajek file are unique and do not occur in other STEM graphs. If not selected, the node URIs will contain the graph's URI.
 +
*Move Nodes to Containers - If selected, all nodes that are contained by another node from a different graph will be moved close to this container. That means that coordinates specified for these nodes in the Pajek file will be ignored.
 +
*Use Absolute Migration Rates- If selecting “yes” then the rate will be the exact number of individuals that are moving across migration edges. If selecting “no”, then a rate from 0-1 must be specified to move a proportion of individuals across the migration edge. Note that if a stochastic solver is used, then this will be a probability of movements, rather than an exact proportion.
  
''Example: 1 2 popid human rateab 0.2 rateba 0.1 popid anopheles rateab 0.5 rateba 0.1''
+
== Tutorial ==
  
=== *Arcs ===
+
A tutorial on how to import a Pajek graph that contains discrete migration events for a STEM graph is available at [[STEM Import Discrete Transportation Events|Import Discrete Transportation Events]]. Discrete events can be used to model commodity flows, e.g., the transportation of beef from slaughterhouses to supermarkets in order to model the spread of a foodborne disease.
  
The keyword "*Arcs" is interchangeable with "*Edges".
+
== Common Errors ==
  
 +
If you get an “out of bounds” exception, then it is likely that the numbers in your nodes do not match those used in your edges.
 +
If you are using data from an Excel spreadsheet and copying into the Libre Office spreadsheet, make sure you choose “paste special” > “unformatted code” > “unitext”.
  
 +
== Contributors  ==
  
=== Example files  ===
+
The PajekNetGraphGenerator was created and developed by the Department of Biological Safety of the Federal Institute for Risk Assessment in Germany.
  
In the [http://www.eclipse.org/stem/download_sample.php?file=MultiPopulationExample_PajekGraphs.zip downloadable project], you will find some examples that may be imported into STEM:
+
Armin A. Weiser, Matthias Filter, Christian Thöns
 
+
Dept. Biological Safety
*CC.NET_2stem.net
+
Federal Institute for Risk Assessment
*1.NET_2stem.net
+
12277 Berlin
 
+
Germany
The filename extension ".net" is not mandatory.
+

Latest revision as of 17:47, 18 October 2018

Multi-Population Pajek Graph Example

This page is about the new Pajek format which is used in STEM releases since version 1.4.0 and in current milestone and integration builds. The old format that was used prior to 1.4.0 is still supported. Examples and documentation of the old format are available at the website download page for Multi-Population Pajek Graph Example.

Create a Pajek file

To create a Pajek file, download and use this ODS spreadsheet document here. Open the ODS spreadsheet, with LibreOffice [1] and activate the macro element. Important: To do this, you must be running JRE [2] on your system.

After modifying the spreadsheet, you can export the file as Pajek file.
Please click for this:

  1. File
  2. ExportToPajek (The first option in the opened dialogue)
  3. Save it on your system (it will automatically be saved as a .net file)


It is also possible to open and modify a Pajek file with a text editor, but it is much simpler to use the recommended spreadsheet.

File Format

STEM allows users to create a custom graph using a format similar to the Pajek ([3]) format. The Libre Office spreadsheet produces a .net file that is in the correct format to be imported into STEM via the PajekNetGraphGenerator, which is available in the graph creation dialogue of STEM: STEMDefineANewGraphIcon.png

The format specification is as follows.

*Vertices [number of nodes]
[node number] [node name] [longitude] [latitude] [additional optional parameters] // spec for a new node
[node number] [node URI] // spec for reference to existing node
...
*Edges
[origin node number] [destination node number] popID [populationID] rate [rate] // spec for migration edges
[containing node number] [contained node number] // spec for containment edges
...


Node Format

The keyword "*Vertices [number of nodes]" is the starting point for the nodes section. New nodes and references to existing nodes can be defined. Available formats appear below.

New Node

[node number] [node name] [longitude] [latitude] [optional parameters]:

  • node number – unique node number (1, 2, 3, ...). Successive numbering of nodes is obligatory.
  • node name – unique name consisting of letters a..zA..Z and digits 0..9.
  • longitude, latitude – coordinates of the node. All values can be entered, but real world coordinates are: -180 <= longitude <= 180, 0 <= latitude <= 90.

Optional parameters:

  • popID – identifier of a population of the node. This parameter may be used repeatedly.
  • popCount – number of individuals living in the node. This parameter may be used repeatedly. The associated popID is the last mentioned one.

Example:

1 Berlin 13.398889 52.500556 popID men popCount 1682900000 popID women popcount 1753500000

Note: when using a Demographic Population Model in STEM you need only declare the main population name e.g. human in the list of nodes. You can refer to individual population subgroups (e.g., men, women) when declaring the populationID for the edges.

Node Reference

[node number] [node URI]:

  • node number – unique node number (1, 2, 3, ...). Successive numbering of nodes is obligatory.
  • node URI – URI of the node in STEM. If the URI starts with stem://org.eclipse.stem/node/geo/region/, this prefix can be omitted.

Examples:

1 stem://org.eclipse.stem/node/geo/region/FR-IF
1 FR-IF

Edges Format

The keyword "*Edges" is the starting point for the edges section. Two types of edges can be described; they are migration edges and containment edges. The formats are as follows.

Migration Edges

[origin node number] [destination node number] popID [populationID] rate [rate]:

  • origin node number – number of the node the population migrates from. Has to be defined as node number in *Vertices.
  • destination node number – number of the node the population migrates from. Has to be defined as node number in *Vertices.
  • populationID – defines the ID of the migrating population.
  • rate - number population members migrating per day.

Optional parameters:

  • date - specification a of date at which the migration rate is different from the standard value specified in the obligatory parameters. ISO 8601 standard is used (YYYY-MM-DD). This parameter may be used repeatedly.
  • rate - migration rate for the specified date. This parameter may be used repeatedly. The associated date is the last mentioned one.

Example:

1 2 popID beef rate 1.0 date 2012-01-01 rate 10.0

Note: the optional parameters are not automatically implemented when you use the pajek graph in STEM. They are all specified in a single trigger which will be located in the "Triggers" folder of your project. The name of the trigger usually starts with "List platform:/resource" and ends with the name of your pajek graph. The trigger must be dragged into your scenario in order for the optional parameters to be implemented.

STEMTriggerOptionalParametersPajekGraph.JPG

Containment Edges

[containing node number] [contained node number]:

  • containing node number – number of the node that contains the other node. Has to be defined as node number in *Vertices.
  • contained node number – number of the node that is contained by the other node. Has to be defined as node number in *Vertices.

Example:

*Vertices 3
1 Berlin 1 1 popID men popCount 100 popID women popCount 110
2 Bonn 1.5 1 popID men popCount 100 popID women popCount 110
3 Germany 1.2 1.2
*Edges
1 2 popID men rate 0.1
2 1 popID women rate 0.2
3 1
3 2

To edit the pajek graph in STEM, right-click on the graph and then select "display", as described here [4] and shown below:

STEM PajekExample.png

Using the dialog

STEMDisplayPajekGraphGenerator.png

The dialog to import a Pajek graph from a file is shown on the right. It is available in the STEM Graph Dialog. The following parameters are available for importing:

  • Pajek File - The file from which the graph is imported. A file dialog is available to select the file.
  • Scaling Factor - A factor by which all coordinates specified in the file are scaled during import. If node has the coordinates 10.0/20.0 in the file and the scaling factor is 2.0, the node's resulting coordinates in STEM are 20.0/40.0.
  • Node Size - In STEM each imported node appears as a square for visualization. This parameter specifies the edge length of the squares for all imported nodes.
  • Use global Region Names - If selected, the URIs for the imported nodes will be of the type stem://org.eclipse.stem/node/geo/region/*****. This has the advantage, that the nodes can be accessed by just using that last part of the URI *****. This option should only be used if node names specified in the Pajek file are unique and do not occur in other STEM graphs. If not selected, the node URIs will contain the graph's URI.
  • Move Nodes to Containers - If selected, all nodes that are contained by another node from a different graph will be moved close to this container. That means that coordinates specified for these nodes in the Pajek file will be ignored.
  • Use Absolute Migration Rates- If selecting “yes” then the rate will be the exact number of individuals that are moving across migration edges. If selecting “no”, then a rate from 0-1 must be specified to move a proportion of individuals across the migration edge. Note that if a stochastic solver is used, then this will be a probability of movements, rather than an exact proportion.

Tutorial

A tutorial on how to import a Pajek graph that contains discrete migration events for a STEM graph is available at Import Discrete Transportation Events. Discrete events can be used to model commodity flows, e.g., the transportation of beef from slaughterhouses to supermarkets in order to model the spread of a foodborne disease.

Common Errors

If you get an “out of bounds” exception, then it is likely that the numbers in your nodes do not match those used in your edges. If you are using data from an Excel spreadsheet and copying into the Libre Office spreadsheet, make sure you choose “paste special” > “unformatted code” > “unitext”.

Contributors

The PajekNetGraphGenerator was created and developed by the Department of Biological Safety of the Federal Institute for Risk Assessment in Germany.

Armin A. Weiser, Matthias Filter, Christian Thöns
Dept. Biological Safety 
Federal Institute for Risk Assessment
12277 Berlin
Germany

Back to the top