AMW Use Case - Calculating the difference between models

AMW Logo

This use case presents a Model Driven Engineering solution to calculate automatically the difference between two KM3 models. Calculating the difference between two models is an essential process to control the changes and evolutions of models. The result of the difference is used to apply a patch in one of the models.

Overview

Consider a distributed development environment in which a KM3 model can be modified by different persons. There is one centralized repository that contains the "official" version M(v1). A developer recuperates M(v1), creates a personal working copy M(v2), and modifies it. Both versions must be synchronized (i.e., a new up to date version is created). The operation that synchronizes these two versions is called Patch. Before the patch can be executed, it is necessary to discover the differences between these models (see below).



Difference and Patch overview

The calculation of the difference is divided in two phases:
  • Matching : the matching phase identifies the elements that did not change between the two models (see the matching use case). The result of a matching is saved in a weaving model. The weaving model contains equivalence links between the elements that were not modified in both KM3 models.
  • Difference calculation : the result of the matching is used to compute which elements were added, removed or modified. The difference algorithm is implemented using ATL transformations. It produces another weaving model that represents the difference between the two versions. This weaving model conforms to a metamodel extension for difference (as illustrated below).

This extension supports deletion or inclusion of elements. Added links are created for the elements that were added in the repository model. Deleted links are created for the elements that were removed. For instance, if a Class A is added in the Package B of the repository model, the addition element links the Package B (from reference) with Class A (to reference).



Difference metamodel extension

The screenshot below shows the difference between the two KM3 models (Relational). The selected element is an Added link that indicates the value Attribute was added into the class Named in the new version.



Difference in the Atlas Model Weaver

The difference weaving model is used as input to a Patch transformation. This transformation analyses the different kinds of links and executes the patch operation, i.e., addition or deletion of elements.

We illustrated this use case using KM3 models. The equivalence and the difference between the models elements are captured by weaving models. The operations (Match, Diff and Patch) are implemented using ATL transformations.

We generalize our solution to perform the difference and patch independently of the metamodel. In this case higher-order transformations are used to analyse the input metamodels (e.g., KM3, SQL) and to produce ATL transformations that execute the metamodel-specific Match, Diff and Patch operations.

Download and examples

Model difference

This is a complete example of generic model difference and match. It contains the ATL transformations that generate the difference and the patch operations, and the weaving models that were produced.

Example HowTo

This document is a step-by-step HowTo that explains how to execute the example.

Related use cases

Matching

Matching is the generic process that creates weaving models. This use case gives a general overview of the matching process, and how it is handled by AMW and ATL.

Metamodel comparison

This use case demonstrates how weaving models are used to compare different metamodels and to produce executable model transformations (we use two metamodels used to define embedded software in the avionics industry).