Skip to content
Snippets Groups Projects
Select Git revision
  • 4c4edcb7b1c896ce6afcf2669e27a7ac3aa620f2
  • main default protected
2 results

pnml-relast-engine

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.

  1. At first, you need to prepare an Epsilon ETL environment:

    1. Install Epsilon 2.4 from the Eclipse Marketplace

    2. Open an Eclipse workspace with your transportation network metamodel projects and id list metamodel projects (Metamodel, Edit, and Editor) or import them in a new workspace. Run one metamodel project as an Eclipse Application to register both metamodels in Eclipse. In the new Eclipse instance you can start using Epsilon.

    3. Epsilon does not need specific projects to work. Create a new general Project in your workspace and create a new *.etl file.

    4. You can now declare your model-to-model transformation rules in this *.etl file (see Task 3 for details). To familiarize yourself with ETL and Epsilon, you can use the documentation23, examples4, or the playground5.

    5. To run the transformation, right-click on the *.etl file and choose Run As -> Run Configuration. In the next window, create a new ETL Transformation configuration, select your *.etl file under Source, and add both your source and your target (for the beginning, just create an empty one) under Models (as EMF Models, source and target are example names, the names of the models should be the same as the ones used in your ETL file). Select or deselect Read on load and Store on disposal for 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 on Run in the menu.

  1. 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 list has a Root as its core. That root a list of element ids. Each of these element ids includes a type, which is the name of the class to which the id belongs, and an id value.

    1. Try to model the Id-List metamodel, or any other metamodel you like, as practice.
  2. 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)

    1. Write an .etl file that transforms all elements with a name or an identifier of a transportation network into element ids of an id-list, including their element type name as type information and their name or identifier as id value.
    2. 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 a target (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:

      1. Use @lazy rules 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.
      2. Only use normal rules. Inside these, you can use all() or eContainer().equivalent() to get a variable referring to the target root.
  1. 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.

    1. Write an .etl file that rewrites the length of all Road Networks with the sum of the length of all their Roads.
    2. 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 a target (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.
  2. 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.

    1. Write an .etl file that splits Road Networks with multiple Roads into multiple road networks with one road each. Between the networks, create new Locations without a name.
    2. (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.
    3. 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 a target (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.

How To Run the Base Solution

  1. Import the stgroup.mdsd.*.metamodel.* projects in your Eclipse workspace. And Run them Ás Eclipse Application.
  2. In the runtime Eclipse instance import the model_examples project and the stgroup.mdsd.transportation_network.transformation.
  3. Run the .etl transformation scripts like described above. You can find the target and source models as well as the configuration in each task. *_original model files can be copied to work with model rewriting task, which change the source models.
  1. https://www.eclipse.org/epsilon/

  2. https://www.eclipse.org/epsilon/doc/etl/

  3. https://www.eclipse.org/epsilon/doc/eol/

  4. https://www.eclipse.org/epsilon/examples/#epsilon-transformation-language

  5. https://eclipse.dev/epsilon/playground/

  6. https://git-st.inf.tu-dresden.de/open-teaching-resources/model-driven-software-development/statemachine-eclipseplugin/-/tree/main/model2model?ref_type=heads