2.3 Graph-Based Specifications
2.3.1 Typed Attributed Graph Transformations Systems
Typed attributed GTS[EEPT06] extend GTS by a type graph and node attributes. The type graphdefines which types of nodes exist and by which types of edges they may be connected. Node attributes enable to store values like integers or strings inside a node. Both features are essential for modeling reconfiguration (cf. Section 3.3).
Figure 2.6 shows an example of a simple type graph that defines two nodes types and six edge types. The two nodes types,RailCabandTrackSection, represent RailCabs and track sections. The node typeRailCabdefines an attribute of type Integer that stores the size of the convoy that the RailCab is currently driving in. The edge types define how nodes of type
RailCabandTrackSectionmay be connected.
RailCab convoySize : int railcabs on 0..* 1 TrackSection 0..1next 0..1 prev 0..1 coordinator 0..* member
Figure 2.6: Example of a Type Graph
ATrackSection has a nextand a prev TrackSection. These edge types define the outline of the track system. In addition, the edge typerailcabsis used to refer to all RailCabs currently driving on a track section. The edge typeonenables to define on whichTrackSectionaRailCab
is currently located. Finally,coordinatorandmemberenable aRailCabto refer to its coordinator or its members.
A typed attributed graph is always typed over exactly one type graph, while an arbitrary number of typed attributed graphs may use the same type graph. All nodes and edges of a typed attributed graph must be typed over exactly one node type or edge type, respectively, of the type graph. The type of a node or edge is immutable. In the course of this thesis, we will assume that the type graph is given by a metamodel [Küh06].
Figure 2.7 shows an example of a typed attributed graph that is typed over the type graph in Figure 2.6. It contains five nodes and five edges. It specifies the situation where two
RailCabs drive on two consecutive track sections. The RailCabs are not yet driving in a convoy because they are not connected with each other by acoordinatorormemberedge.
ts3 : TrackSection rc1 : RailCab convoySize = 0 prev ts2 : TrackSection next ts1 : TrackSection prev next rc2 : RailCab convoySize = 0 on on railcabs railcabs
Figure 2.7: Typed Attributed Graph
Each node of a typed attributed graph has values for all of its attributes. In Figure 2.7, the nodesrc1andrc2both have value 0 for theirconvoySizeattribute.
A typed attributed GTS consists of a type graph, an initial graph that is typed over the type graph, and a set of graph transformation rules that define how graphs may be modified. A graph transformation rule specifies a left hand side (LHS), a right hand side (RHS), a so- called rule morphism, and a set of negative application conditions (NAC) [EEPT06]. LHS, RHS, and NACs are typed attributed graphs based on the type graph. The rule morphism associates nodes in the LHS to nodes in the RHS to denote which nodes are the same. In addition, each NAC defines its own morphism that associates nodes in the LHS to nodes in the NAC. Rule: startConvoy LHS ::= RHS NAC1 ts2 : TrackSection rc1 : RailCab ts1 : TrackSection next rc2 : RailCab on on ts2 : TrackSection rc1 : RailCab convoySize = convoySize + 1 ts1 : TrackSection next rc2 : RailCab on on coordinator member rc3 : RailCab rc2 : RailCab coordinator NAC2 rc1 : RailCab rc2 : RailCab member
Figure 2.8: Graph Transformation Rule for Starting a Convoy
Figure 2.8 shows an example of a graph transformation rulestartConvoythat starts a convoy between two RailCabs that are positioned on two consecutive track sections. The LHS spec- ifies this situation. The RHS specifies the same situation butrc2is now amemberof a convoy that is coordinated byrc1. In our example, we implicitly define the rule morphism by using the same names, e.g.,rc1andrc2for nodes in the LHS and RHS. The graph transformation rulestartConvoydefines two NACs.NAC1defines a situation whererc2is already amemberof
a convoy that is coordinated by a differentRailCab rc3. NAC2defines a situation whererc2is
already amemberof a convoy that is coordinated byrc1.
The application of a graph transformation rule such asstartConvoy to a typed attributed graph is performed in three steps. In the first step, we search a match of the LHS to the typed attributed graph, the so-called host graph. Basically, a match is an occurrence of the LHS
in the host graph. The match needs to consider both, the type of the node and the attribute values of the node. That means, nodes of typeRailCabin the LHS may only be matched to nodes of typeRailCabin the host graph. If a node in the LHS specifies an attribute value, the matched node in the host graph needs to have the same attribute value. Attributes that are not used in the LHS are ignored while searching the match. A match for a graph transformation rule is only valid, if no NAC of the graph transformation rule can be matched to the host graph. In the second step, we remove all nodes and edges that occur in the LHS but not in the RHS of the graph transformation rule. To determine this set of nodes, we use the rule morphism. In the third step, we add all nodes and edges that occur in the RHS but not in the LHS. In this step, we also modify attribute values if necessary.
When applying the graph transformation rule startConvoy in Figure 2.8 to the typed at- tributed graph in Figure 2.7, we proceed as follows. For obtaining a match, we search for an occurrence of the LHS in the graph. The occurrence is given by the nodesrc1,rc2,ts2, and
ts3in Figure 2.7. Next, we need to check whether this match may be extended such that any NAC is completely matched. This is not the case becauserc2in Figure 2.7 is not yet mem- ber of a convoy. Thus,startConvoyhas been successfully matched and we perform the graph rewriting. Therefore, we create acoordinatoredge fromrc2torc1and amemberedge fromrc1
torc2. In addition, we update the value of the attributeconvoySizeofrc1by incrementing it by 1.
For the application of graph transformation rules, we follow the single pushout approach with injective matches (SPO, [Roz97]). In essence, that means that different nodes of the LHS need to be matched to different nodes in the host graph. For example,rc1andrc2in the LHS ofstartConvoy need to be matched to differentRailCabnodes in the host graph. In addition, if the graph transformation rule specifies to delete a node without deleting all of its incident edges, then the incident edges are implicitly deleted as well to avoid dangling edges.