Skip to content
This repository was archived by the owner on Sep 17, 2019. It is now read-only.

GuideTutorialMarkedGraph

Xavier Crégut edited this page Nov 10, 2015 · 48 revisions

Tutorial: Make Marked Graph models executable with the GEMOC Studio

What is expected at the end of this tutorial

This tutorial aims at demonstrating the power of the GEMOC studio to define an executable semantics and provide graphical animation for a DSML. It relies of the marked graph language.

The following animation shows the expecting results of this tutorial: according to the fired transitions, tokens move from place to place.

Expected animation for Marked Graph models
Figure 1. Expected animation for Marked Graph models

Install the projects defining the Marked Graph AS and CS

The domain model is implemented with several EMF projects that you need to import into your workspace. A graphical editor defined with Sirius is also available to visualize and edit Marked Graph models.

Import the Marked Graph AS and CS

Download the provided archive containing the projects and unzip it. Then, with the GEMOC Studio, select import…​ / General / Existing Projects into Workspace and import all the projects from the archive file.

Abstract Syntax

Marked Graph is a kind of Petri net in which every place has exactly one incoming arc and exactly one outgoing arc. As a consequence, it a concurrent language (several transitions may be fired) and has no conflict.

The Domain Model, also called Abstract Syntax or Metamodel, defines :

  • A marked graph as a set of places and transitions.

  • Each Place has exactly one input transition and one output transition and a token count.

  • A transition has several input places and several output places.

MarkedGraph Domain Model (Metamodel)
Figure 2. Abstract Syntax (Metamodel) of MarkedGraph

Concrete Syntax and Sample Model

The graphical concrete syntax draws places as circles and transitions as squares. Inputs and outputs of places and transitions are designated by arrows. The following picture shows the graphical representation of the Marked Graph model of wikipedia (using a graphical syntax defined using Sirius).

Example of a Marked Graph model (from wikipedia)
Figure 3. Example of a Marked Graph model (from wikipedia)

Set up an xDSML project

In this section, we first create an xDSML project for MarkedGraph and initialize it with the provided Abstract Syntax (AS) and Concrete Syntax (CS).

Create an xDSML Project

Select an xDSML project (New > Project > GEMOC Project / new xDSML Project).

Create an xDSML Project
Figure 4. Create an xDSML Project

The first dialog of the wizard asks for the name of the project. Define it as org.gemoc.sample.markedgraph.xdsml.

Define the name of the project
Figure 5. Define the name of the project

Click on Next and define the name of the language (markedgraph).

Define the name of the language
Figure 6. Define the name of the language

Open xDSML View

A file project.xml has been created in the org.gemoc.sample.markedgraph.xdsml project.

Content of the xDSML Project
Figure 7. Content of the xDSML Project

When opened, it provides the xDSML view which summarizes all the important resources used in an xDSML project (which are part of and managed by other projects). This view is a kind of control center to have quick access to the main resources of the project.

The xDSML Editor
Figure 8. The xDSML Editor

Select the AS

In the "Domain Model" section, click on the "Browse" button to select the project defining the AS: org.gemoc.sample.markedgraph.model.

Browse to select the AS project
Figure 9. Browse to select the AS project

Then, select the "Genmodel URI".

Browse to select the genmodel resource
Figure 10. Browse to select the genmodel resource

Finally, select the "Root container model element" thanks to the "Select" buttons.

Browse to select the root container
Figure 11. Browse to select the root container

Select the Graphical Editor

The Graphical Editor defines a graphical concrete syntax which is user-friendly to view and edit a model.

In the "Concrete syntax definition / Graphical editor" of the project.xdsml editor, click on "Browse" to select the "org.gemoc.markedgraph.design" project.

Select Sirius graphical editor
Figure 12. Select Sirius graphical editor

Define the Execution Semantics

A transition can be fired if there is at least one token in every of each input place. When fired, one token is removed from each of its input places and one token is added to each of its output places. Several transitions can be fired as the same time.

Defining the execution semantics consists in implementing the previous behavior. In the GEMOC approach, it is split in different concerns:

  • The definition of Execution Data (ED) like the runtime count of tokens in a place and Execution Functions (EF) like fire a transition. ED and EF constitute the DSA.

  • The definition of the model of concurrency as a set of events and constraints on these events. It is the MoCC concern that is defined in a DSE project (using ECL, Event Constraint Language) possibly completed with MoCCML projects to define libraries of constraints.

  • The mapping between the DSA and the MoCC.

In the current version of the GEMOC studio, the MoCC and the mapping are tightly coupled and described in ECL (Event Constraint Language).

Define DSA

During execution of a MarkedGraph, the number of tokens of a place has to be recorded and changed according to the fired transitions. Thus, we have to manage an execution data (ED) called runtimeTokenCount and an execution function (EF) on Transition called fire(). Furthermore, the runtimeTokenCount of each place must be initialized at the start of the execution. It is the purpose of the EF called initialize() on the MarkedGraph element.

The DSA of Marked Graph is composed of :

  • one ED called runtimeTokenCount defined on Place . It represents the number of token in a place when the model is executed.

  • one EF called initialize() defined on MarkedGraph. It initializes the runtime token count of each place with the initial token count.

  • one ED called fire() on Transition. It to remove one token from each of its input places and add one token to all its output places.

Extend the AS with ED and EF

At the moment, we need to complete the AS (markedgraph.ecore) with the ED and EF. In the next release of the GEMOC Studio this steps will disappear and extended the AS will be done automatically thanks to Melange

Add the 'runtimeTokenCount' ED on Place, 'fire()' on Transition and 'initialize()' on MarkedGraph.

Abstract Syntax of MarkedGraph extended with Execution Data (ED) and Execution Functions (EF)
Figure 13. Abstract Syntax of MarkedGraph extended with Execution Data (ED) and Execution Functions (EF)

Create the DSA Project

Click on K3 project in the project.xdml editor (Behavioral definition / DSA definition). The wizard to create of new Kermeta 3 project is launched with the name of the project initialized (k3dsa is the last name). Click "Finish". The project has been created.

Create a K3 Project
Figure 14. Create a K3 Project

Implement the DSA

Click again on K3 project to open markedgraph.xtend. It has been initialized with a template that can be discarded and replaced with the following text.

link:MarkedGraph/markedgraph.xtend[role=include]
Definition of the DSA (ED and EF)
Figure 15. Definition of the DSA (ED and EF)

Define DSE

The purpose of the DSE project is to define events (called DSE) on AS elements that will trigger EF calls when they occurs. Furthermore, constraints can be defined on these events to define when they may occur.

Create the DSE Project

  • Click on the "ECL Project" in the project.xdsml editor ("Behavior definition / DSE definition").

  • Check that the name is org.gemoc.sample.markedgraph.dse.

Create a DSE Project
Figure 16. Create a DSE Project
  • Click "finish" and the project is created.

  • Click on "ECL Project" to edit the "markedgraph.ecl" file and replace its content with the following:

Template of the ECL file
Figure 17. Template of the ECL file

Define DSE

Replace the content of the ECL file with the following code (explanations on this code are given bellow):

The file markedgraph.ecl
link:MarkedGraph/markedgraph.ecl[role=include]
Definition of the DSE (events and constraints)
Figure 18. Definition of the DSE (events and constraints)

This step has three main purposes:

  1. First, it specifies DSE in the context of metaclasses of the AS. For Marked Graph xDSML, we identify 2 DSE:

    • fireIt: defined in the context of a Transition

    • initIt: defined in the context of a MarkedGraph

  2. Then, it links them to EF form DSA --- when a DSE will occurs the associated EF will be executed.

    • fireIt is linked to the EF 'fire' of Transition

    • initIt is linked to the EF 'initialize' of MarkedGraph

  3. Finally, it defines constraints on the DSE to rule the possible scheduling. Constraints generally rely on relations which are defined in MoCC libraries. Here constraints are expressed in CCSL and only relies on relations and expression from the CCSL core library.

    • A first constraint applies on the fireIt events. It is depends on the number of token in a place. Indeed, if there is no tokens, then the fireIt of the output transition can only occur after the fireIt event of the input transition has occured. It is expressed by the first invariant defined in the context of a Place. If there is some tokens in a place, then the fireIt event of the output transition may occur as many times as there is tokens in this place. After, it will only occur when the fireIt on the input transition of the place has occured. It is expressed using the DelayFor expression in the second envariant of Place.

    • Two other constraints are defined in the context of the MarkedGraph element. The first one expresses that the first initIt event must occur before any fireIt event. The second one expresses that the initIt event can occur only one time.

Note
Please notice that, as often, DSE are defined at the language level, but at runtime they are instantiated as MSE on each object instance of the metaclasse they are defined on. For example, there will be one fireIt MSE for each Transition element of MarkedGraph model. For the wikipedia example, there will a fireIt event for transitions t1, t2, t3 and t4. In the same way, constraints apply to the MSE.

Define Animation Viewpoint

During the execution of a Marked Graph model, we want to visualize :

  • the number of tokens in any place: the runtime token count will be printed in the circle of one place.

  • the firable transitions: they will be drawn in green.

As the animation view is close to the graphical concrete syntax, we extend the existing diagram description.

First, we will define a graphical representation based on the graphical Marked Graph syntax to the wizard called "Create GEMOC debug representation", then we will add a layer to describe the graphical animation of a Marked Graph model.

Create a debug representation (as an extension of the graphical editor viewpoint)

Run the wizard

Tun the wizard with New > Other / Create GEMOC debug representation.

Create GEMOC debug representation wizard
Figure 19. Create GEMOC debug representation wizard

On the first screen of the wizad, select "Extends an existing diagram description".

Select "Extends an existing diagram description"
Figure 20. Select "Extends an existing diagram description"

Select the viewpoint to extend "MarkedGraph diagram".

Select the viewpoint to extend
Figure 21. Select the viewpoint to extend

Finally, we can fill in the Project Name in which the newly creating viewpoint file will take place (org.gemoc.sample.markedgraph.animation), the name of the viewpoint file (markedgraph-animation.odesign), the viewpoint name (MarkedGraphViewpoint) and the diagram name (MarkedGraph).

Information of the animation viewpoint
Figure 22. Information of the animation viewpoint

The last screen allows to choose the name of the layer to be created. Debug is a good name.

Once the Finish button is pressed, the project is created.

Open the markedgraph-animation.odesign

Open the markedgraph-animation.odesign file and develop its content.

TODO: explain its contents.

Load markedgraph.odesign as a resource.

To be able to complete the definition of the odesign file, we first need to load the existing markedgraph.odesign as a resource :

  • Right click in the markedgraph.odesign editor to select Load Resource…​.

  • Select Browse workspace…​

  • Select markedgraph.odesign in the org.gemoc.sample.markedgraph.design project

  • Click OK

  • Click OK

Add markedgraph.ecore to the metamodels

  • Select "Diagram Extension MarkedGraph" element.

  • In the properties view, select metamodels.

  • Click on "Add from workspace".

  • Select "markedgraph.ecore" (unfold the project structure)

  • Click OK

Complete the debug representation

On the "Mapping Based Decoration Enabled breakpoint" and "Mapping Based Decoration Disabled breakpoint", select the "Place" and "Transition" element.

The debug view will show a symbol on the Place and Transition to show whether the corresponding breakpoint is enabled or disabled.

Complete the dependencies of the project

  • Open the plugin.xml file of the project.

  • Select the dependencies tab.

  • Click "Add…​" in the "Required Plug-ins" area.

  • Select "org.gemoc.gemoc_language_workbench.extensions.sirius"

  • Click OK

  • Save the plugin.xml resource.

Set the animation viewpoint in project.xml

In the xDSML editor, we can select the animation viewpoint by selecting the newly created project (org.gemoc.sample.markedgraph.animation)

Create an animation representation

After the debug presentation has been defined, we can complete it to add an animation layer.

Create the Animation Layer

  • Right click on "Diagram extension MarkedGraph" to select New Diagram Element / Additional Layer.

  • Set its "id" to "Animation".

Display the firable transition with a green background color

  • Right click on "Animation" to select "New Customization / Style Customizations".

  • Right click on "Style Customizations" to select "New Customization / Style Customization".

  • On "Style Customization", set the "Predicate Expression" to "[self.eGet('inputs')→forAll(p | p.eGet('runtimeTokenCount').toString().toInteger() > 0) /]"

  • Right click on "Style Customization" to select "New Customization / Property Customization (by selection)"

  • For "Applied On" property, select "Square white".

  • For "Property Name", set "color" (completion is available with CTRL-SPACE)

  • For "Value Selction", set "light_green"

Set the background color of a place to light_yellow

Perform the same action as above to set the background color of place to yellow.

Display the runtime token count in a place

  • Right click on "Style Customization" to select "New Customization / Property Customization (by expression)"

  • For "Applied On" property, select "Ellipse white".

  • For "Property Name", set "labelExpression" (completion is available with CTRL-SPACE)

  • For "Value Selction", set "feature:runtimeTokenCount"

Add the Animation service

  • Right click on "MarkedGraphViewpoint" to select "New Extension / Java Extension".

  • Set "Qualified Class Name" to "org.gemoc.sample.markedgraph.animation.services.MarkedgraphAnimationServices".

In the project, org.gemoc.sample.markedgraph.animation project, in src/org.gemoc.sample.markedgraph.animation.services, copy the MarkedgraphDebugServices.java class to MarkedgraphAnimationServices.java. Then, change AbstractGemocDebuggerServices to AbstractGemocAnimatorServices in its source code (two times: import and extends). Finally, change "Debug" to "Animation".

Animate a Model

The executable MarkedGraph Language is now defined. We can use the GEMOC Modeling Workbench to execute MarkedGraph models.

Launch the Modelling WorkBench

First, we will create a run configuration. Select "run / run Configurations" Double click on "Eclipse Application" and change the name "New Configuration" into "Marked Graph Modeling Workbench". We can now click "Run" to start the new runtime Eclipse which indeed corresponds to the Modeling Workbench for Marked Graph.

Define the Marked Graph Modeling Workbench configuration
Figure 23. Define the Marked Graph Modeling Workbench configuration

Import the project with a sample model

Import the modeling project org.gemoc.sample.markedgraph.sample in the Modeling Workbench (Import / General / Existing project into Workspace). It contains the wikipedia.markedgraph file which corresponds to the Wikipedia example.

Select the Modeling perspective

  • Select "Window / Open Perspective / Others…​"

  • Select "Modeling" in the list.

Create a Launch Configuration

  • Select Debug / Debug Configurations

  • Double click on "Gemoc eXecutable Model"

  • Change the name of the new configuration to "run wikipedia example"

  • Browse to select the model to run (wikipedia.markedgraph)

  • Select its language (xDSML field): markedgraph

  • Browse to select the animator

  • Check that the "Decider" is set to "Step by step user decider" (the user will decide which well be the next step to execute).

  • Click on Run

Define the configuration to run the wikipedia example
Figure 24. Define the configuration to run the wikipedia example

Launch the execution of the model

We can now run the "gemoc" configuration. It opens the different views related to the execution on an xDSML model:

  • Logical Steps (top left): the list of the logical steps that may be selected at this execution step.

  • Gemoc Engine Status (middle left): the list on the running GEMOC engines. The red button stops the selected engine.

  • Stimuli Manager (bottom left): the list of MSE.

  • VCD (top right): a graphical visualisation of the events manages by the MoCC (first ones correspond to the MSE).

  • Graphical visualization (middle right) of the model (with animation information)

  • Time Line (bottom middle): the logical steps available at each steps and the selected one.

  • Console: several consoles are available. The dispolayed one is the "Default MessaginSystem Console". There is one console the the main component of the Modeling Workbench.

The wikipedia model is just started
Figure 25. The wikipedia model is just started

Select a logical step

The Logical Steps view, presents the possible steps, and for each step, the MSE that will occur if it is selected.

One logical step selected
Figure 26. One logical step selected

Double-click on a Logical Step to choose it. The corresponding MSE occur, they are visible on the VCD, and they trigger the associated execution functions which make the state of the model evolve.

Execute a logical step
Figure 27. Execute a logical step

Then, we can select a new logical step (here we selected the the logical step which fires the t2 transition).

Transition t1 fired
Figure 28. Transition t1 fired
Transition t2 fired
Figure 29. Transition t2 fired
Some logical steps later
Figure 30. Some logical steps later

Stop the execution

To stop the execution:

  • Select the "Gemoc Engine Status" view

  • Select the engine to stop

  • Click on the red button to actually stop the engine (the left icon becomes red)

Define a MoCCML library

To avoid the ECL file to become too large and to favor capitalization and reuse of MoCC elements, it is possible (and encourage) to define libraries. Those libraries looks like the predefined ones that we have already used like kernel.lib and CCSL.lib.

Define a MoCCML library using CCSL

Using it in the ECL file

To use this new library, we only have to import it at the beginning of the ECL file and the we can use it as kernel.lib and CCSL.lib libraries.

Here is the new corresponding file.

The file markedgraph.ecl using the MoCCML library
link:MarkedGraph/markedgraph-library.ecl[role=include]

Use constraint automata to define the MoCC

Sometimes, it may be easier to define the MoCC using an automata. For example, we can see a place as something on which we can read a token (the output transition reads one token) or we can write a token (the input transition writes one token). A token can only be read if there is at least one in the place. Initially, there is as much token in the place as in the initial token count of the place.

Here is the textual representation of this constraint automata.

To go gurther…​

  • The DSE part may be defined using a MoCCML library. It favors reuse of MoCC and clarity of ECL file.

  • Rather than using CCSL syntax, it is possible to use constraint automata (defined using MoCCML).

Clone this wiki locally