Chapter 4. Define the Execution Semantics

A transition can be fired if there is at least one token in every of each input place. When a transition is 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:

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

4.1. 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.

4.1.1. 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 step replaced by the use of Melange to automatically extend the AS with ED and EF.

The ED and EF are already defined on the provided metamodel. Thus, there is no need to 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 4.1. Abstract Syntax of MarkedGraph extended with Execution Data (ED) and Execution Functions (EF)


4.1.2. Create the DSA Project

In the Project Explorer, right click on any file of the xDSML project and choose GEMOC Languge > Create DSA Project for language to start the wizard.

Create a DSA Project

Figure 4.2. Create a DSA Project


The wizard first add for the language: select 'MarkedGraphL' and click OK. On the next screen, the project name is already initialized. Click 'Finish' and the 'org.gemoc.sample.markedgraph.k3dsa' is created and the Melange file is completed with references to aspects implemented the ED and EF.

The Melange file with references to aspects implementing ED and EF

Figure 4.3. The Melange file with references to aspects implementing ED and EF


4.1.3. Implement the DSA

Open the markedgraphAspects.xtend file. It is located in the org.gemoc.sample.markedgraph.k3dsa project in src/markedgraph.aspects. The file has been initialized with a template that can be discarded and replaced with the following text.

package markedgraph.aspects

import fr.inria.diverse.k3.al.annotationprocessor.Aspect
import markedgraph.MarkedGraph
import markedgraph.Place
import markedgraph.Transition

import static extension markedgraph.aspects.PlaceAspect.*

@Aspect(className=MarkedGraph)
class MarkedGraphAspect {
	def public void initialize() {
		println("Graph " + _self.name + " initialized.")
		_self.places.forEach [ pl | pl.initialize ]
	}
}

@Aspect(className=Place)
class PlaceAspect {
	public int runtimeTokenCount

	// @Helper
	def public void initialize() {
		println("Place " + _self.name + ": initialized.")
		_self.runtimeTokenCount = _self.tokenCount
	}
}

@Aspect(className=Transition)
class TransitionAspect {
	def public void fire() {
		println("Transition " + _self.name + ": fired.")
		_self.inputs.forEach[ runtimeTokenCount = runtimeTokenCount - 1 ]
		_self.outputs.forEach[ runtimeTokenCount = runtimeTokenCount + 1 ]
	}
}
Definition of the DSA (ED and EF)

Figure 4.4. Definition of the DSA (ED and EF)


There is an error in the Melange file because no aspect has been defined on the NamedElement metaclass. Just comment out the corresponding line.

Corrected Melange file

Figure 4.5. Corrected Melange file