Automatically Generating Instances of Metamodels

Karsten Ehrig, Jochen M. Küster, Gabriele Taentzer and Jessica Winkelmann

Department of Computer Science, University of Leicester, UK,
karsten@mcs.le.ac.uk,
IBM Zurich Research Laboratory, CH-8803 Rüschlikon, Switzerland,
EMail: jku@zurich.ibm.com, and
Department of Computer Science, Technical University of
Berlin, Germany, EMail: {gabi,jessiw}@cs.tu-berlin.de

Metamodeling is a wide-spread technique to define visual languages, with the UML being the most prominent one. Despite several advantages of metamodeling such as ease of use, the metamodeling approach has one disadvantage: It is not constructive i. e. it does not offer a direct means of generating instances of the language. This disadvantage poses a severe limitation for certain applications. For example, when developing model transformations, it is desirable to have a large set of valid instance models available for large-scale testing. Producing such a large set by hand is tedious.
In the related problem of compiler testing, a context-free grammar together with a simple generation algorithm is typically used to produce words of the language automatically.

In this work, we present a model transformation, that, given an arbitrary metamodel, generates the corresponding instance-generating graph grammar, thereby overcoming the main deficit of the metamodeling approach for defining languages.

Instance-generating graph grammars for creating instances of meta models are introduced in the paper Generating Instance Models from Meta Models, and a  a restricted form of OCL constraints that can be translated to graph constraints which can be checked during the instance generation process is described in Translation of Restricted OCL Constraints into Graph Constraints for Generating Meta Model Instances by Graph Grammars.

First step: Creation of meta model by some CASE tool

Starting with a meta model, it has to be created by some CASE tool such as RationalRose, Poseidon, OMONDO EclipseUML, etc. Nowadays most of these CASE tools support XMI as export format. Unfortunately, each CASE tool supports its own variant of XMI such that an exchange of meta models between different CASE tools is not that easy.
Fig. 1 shows an example metamodel for simple state machines.


Fig. 1: Example metamodel for simple state machines

Second step: Model transformation to an instance-generating graph grammar

Using the graph transformation engine AGG for this transformation, the meta model stored in XMI has to be first
translated to GXL, the standard exchange format for graphs. The result of this translation is an abstract syntax graph such as the one for state machines shown in Fig. 2 in GXL format. The whole AGG graph transformation system for this model transformation can be downloaded from here (AGG Version 1.4.1 or higher is required).

Click here for a detailed description of the model transformation rules.

The result is the graph grammar ruleSetSM.ggx which represents an instance-generating graph grammar. It is a graph representation of a graph transformation system that has to be converted into an executable AGG graph grammar. The converter which translates such a graph into an AGG graph grammar in GGX, the storing format used by AGG can be downloaded: Class-File, Java-Source, the resulting instance generating graph grammar can be downloaded from here.

Abb. 2: Meta model for simple state machines as AGG Graph

Third step: Generation of arbitrary meta model instances

Given an instance-generating graph grammar in AGG, it can be used now to generate arbitrary instance graphs of the given meta model. The example instance generating graph grammar for simple start chart can be downloaded from here (AGG Version 1.4.1 or higher is required). Please note that the graph grammar has three layers. The first layer creates an abitrary number of instance classes and has to be stopped manually. The second layer consists of rules for link creation for associations with multiplicity [1,1] at one association end. The rules have to be applied as long as possible. This layer has rules that create links between existing instances and rules that create an instance (of a concrete type) and a link to this instance starting at an instance that is not yet connected to another instance. The third layer consists of rules creating links for associations with multiplicity [0,1] or [0,*] at the association ends. The graph grammar derivation rules in layer 3 are terminating. But in order to generate all possible instances, the rule application can be interrupted by user interaction or after a random time period. The rules create links between existing instances, so they have negative application conditions prohibiting the insertion of more links than allowed by the meta model cardinalities.
See a sample instance graph of the state machine meta model in Figure 3. Due to the non-deterministic choice of applicable rules the variety of generated instances is not restricted at all.



Fig. 3: Sample instance graph of the state machine meta model

Usage of instances e.g. for testing:

Having created instance graphs of the given metamodel, they can be stored in GXL format and converted to some suitable format for testing. E.g. for testing model transformations written in Java, a converter from GXL graphs to Java test classes is needed.

Other Examples

Two other example metamodels were transformed to an instance-generating graph grammar as described above. They are shown here.