MDSD Example: Transportation Network - Sources
Exercise 04 - Model-to-Model Transformation
This repository includes the resources of the fourth task of the MDSD Example "Transportation Network".
Task Description
The main task of the exercise is to introduce model transformations for the domain of transportation networks.
In this exercise, we will focus on model-to-model transformations using the Epsilon language family1, particularly the Epsilon Transformation Language (ETL), to transform, rewrite, and extend our transportation network models.
- 
At first, you need to prepare an Epsilon ETL environment:
- 
Install
Epsilon 2.4from theEclipse Marketplace - 
Open an Eclipse workspace with your transportation network metamodel projects and id list metamodel projects (
Metamodel,Edit, andEditor) or import them in a new workspace.Runone metamodel projectasanEclipse Applicationto register both metamodels in Eclipse. In the new Eclipse instance you can start using Epsilon. - 
Epsilon does not need specific projects to work. Create a new general
Projectin your workspace and create a new*.etlfile. - 
You can now declare your model-to-model transformation rules in this
*.etlfile (see Task 3 for details). To familiarize yourself with ETL and Epsilon, you can use the documentation23, examples4, or the playground5. - 
To run the transformation,
right-clickon the*.etlfile and chooseRun As -> Run Configuration. In the next window, create a newETL Transformationconfiguration, select your*.etlfile underSource, and add both yoursourceand yourtarget(for the beginning, just create an empty one) underModels(asEMF Models,sourceandtargetare example names, the names of the models should be the same as the ones used in your ETL file). Select or deselectRead on loadandStore on disposalfor the models depending on your use case (see the following tasks). After that, you can always re-run the configuration and start the transformation by clicking onRunin the menu. 
 - 
 
- 
For the first transformation task, we will need a target model type. For that, you can think of any metamodel you want. If you do not have any ideas, id scaping is a common task. You could define a simple Id-List metamodel as follows:
An
id listhas aRootas its core. That root a list ofelement ids. Each of these element ids includes atype, which is the name of the class to which the id belongs, and anid value.- Try to model the Id-List metamodel, or any other metamodel you like, as practice.
 
 - 
The first use case for model transformation is model-to-model transformations. In this case, you transform a model to another model with the same or another metamodel. In our simple example, we want to transform our transportation network to an id list, scraping all ids of the transformation network in the process. A more complex example would be the transformation of state machines to Petri nets, retaining their semantics (this older example can be found here6)
- Write an 
.etlfile that transforms all elements with anameor anidentifierof a transportation network into element ids of an id-list, including their element type name astypeinformation and their name or identifier asid value. - If you want to run the transformation, use a transportation network model as a 
source(Read on load: true,Store on disposal: false) and an empty id-list model as atarget(Read on load: false,Store on disposal: true) 
Please note the following hints:
- 
There should be one rule for each element type of the transportation network metamodel, as well as one rule to transform the root elements of each metamodel into each other.
 - 
Newly created nodes of the transformation target are not integrated into any structure. You need to do that within the rules. You have two options for this:
- Use 
@lazyrules for the elements (they will only run if called by.equivalent()) and a normal rule for the root transformation. Inside the root transformation, go through the model and call the prepared lazy rules. - Only use normal rules. Inside these, you can use 
all()oreContainer().equivalent()to get a variable referring to the target root. 
 - Use 
 
 - Write an 
 
- 
The second use case for model transformation is model rewriting/repairing transformations. In this case, we have no real target model and can only rewrite parts of the source model.
- Write an 
.etlfile that rewrites thelengthof allRoad Networkswith the sum of thelengthof all theirRoads. - If you want to run the transformation, use a transportation network model as a 
source(Read on load: true,Store on disposal: true) and the same model as atarget(Read on load: false,Store on disposal: false). 
Please note the following hints:
- The target of a transformation rule does not matter here since it will be neither loaded nor saved.
 
 - Write an 
 - 
The last use case for model transformation is model rewriting by adding new model elements. In this case, we also have no real target model and only rewrite parts of the source model.
- Write an 
.etlfile that splitsRoad Networkswith multipleRoads into multiple road networks with one road each. Between the networks, create newLocationswithout aname. - (Optional) After the first step, try to merge road networks that have the same road by splitting them to the same length and merging the parts with the same length.
 - If you want to run the transformation, use a transportation network model as a 
source(Read on load: true,Store on disposal: true) and the same model as atarget(Read on load: false,Store on disposal: false). 
Please note the following hints:
- You can define multiple target elements in a transformation rule. A transformation does not need to be one-to-one.
 - You can have multiple rules for one source element. A stepwise approach is possible.
 - Variables defined in the pre-block are global and can be used for data transfer between the rules.
 
 - Write an 
 
How To Run the Base Solution
- 
Importthestgroup.mdsd.*.metamodel.*projects in your Eclipse workspace. AndRunthemÁs Eclipse Application. - In the runtime Eclipse instance 
importthemodel_examplesproject and thestgroup.mdsd.transportation_network.transformation. - Run the 
.etltransformation scripts like described above. You can find the target and source models as well as the configuration in each task.*_originalmodel files can be copied to work with model rewriting task, which change the source models.