Programming

<<[AToM3 Types]  ::: [The ATOM3 class]>>

6. Graph Grammars

In AToM3, graph grammars are a way to specify model manipulations. Graph Grammars can be created visually with the commands under the Transformation menu. The following is a UML Class Diagram showing the main parts of the Graph Grammar module in AToM3.


Figure 1: UML Class Diagram of the Graph Grammar module.

Editing graph grammars is done by editing a GraphGrammarEdit object. In this object you can specify a list of rules (objects of type GGruleEdit), and Initial and Final Actions. These actions are specified in Python, and are evaluated before and after the graph grammar is executed. When you finish creating a graph grammar and click on Transformation|Generate code for Transformation, AToM3 generates the following classes:

And as stated before, GraphRewritingSys class is responsible to execute a list of GraphGrammar objects. That is, GraphGrammarEdit and GGruleEdit are used for modelling graph grammars, whereas GGrule, GraphGrammar and GraphRewritingSys are used to execute graph grammars. The structure of these three latter classes is explained in the following subsections.

6.1 The GraphRewritingSys class

As stated before, the GraphRewritingSys class is responsible to execute a list of GraphGrammar objects. Its structure is shown in the next figure:


Figure 2: Structure of the GraphRewritingSys class.

The meaning of the attributes are as follows:

The meaning of the method is as follows:

6.2 The GraphGrammar class

GraphGrammar class objects are executed by GraphRewritingSys objects on graphs (objects of children of the class ASG). Its structure is shown in the next figure:


Figure 3: Structure of class GraphGrammar.

The meaning of the attributes is as follows: The meaning of the methods is as follows:

6.3 The GGrule class

The GGrule class is the base for all graph grammar rules defined by the user. Its attributes and its main methods are shown in figure 4:
 
 


 

Figure 4: Structure of class GGrule.

The meaning of the attributes is as follows:

The meaning of the methods is as follows:

6.4 Example

Suppose we have modified the meta-model defined in the previous example to add a relationship aRel connecting two aTest entities.These modifications are shown in figure 5.

Figure 5: Adding a relationship to the example in section 1.

Then using the defined formalism we can draw model such as the following:

Figure 6: A simple model specified with the meta-model in figure 5.

As an example of building a graph grammar, we will define one to break loops between two aTest entities. For this purpose, we just need one rule with the following left and right hand sides:
 

Left Hand Side

 
 





Right Hand Side

Figure 7: A simple graph grammar rule to break loops.

Observe how, in the LHS, when you specify "Any" as the matching condition for an attribute, and that attribute is being shown in the canvas,  it appears labeled as "<ANY>". In the RHS, you have three posibilities to assign values to attributes:

When you click on Transformation|Generate code for Transformation two Python files are generated in our case: Note also that when you edit the RHS of a rule, a button appears in the user interface ("copy LHS") that allows you to copy the current graph in the LHS. The following figure shows the result of the application of the previous graph grammar to the model in figure 6:

Figure 8: Result of the application of the previous graph grammar.


<<[AToM3 Types]  ::: [The ATOM3 class]>>



Maintained by Juan de Lara. Last modified 25 July 2002.