Sie sind auf Seite 1von 6

Theory of Graph Transformations

Helge Wiemann
University of Bremen
studies of computer science
hwiemann@tzi.de

Abstract
This paper shall give an introduction into the theory
of rule-based graph transformation which is itself a wellstudied area in the context of computer science. It begins
with a short introduction to the topic of graphs and continues with the description of some quite important notions
which are essential for the understanding of the theory of
graph transformation. The topic of the algebraic approach
as the central method for graph transformations is presented as the main topic in this paper, strengthened by illustrations of the two sub approaches SPO (single-pushout approach) and DPO (double-pushout diagram) which is more
frequently used in practice than the SPO. All theoretical aspects are often accompanied by an application example to
illustrate them related to practice. At the end of this paper
you will find a comparison of the two sub approaches as a
final conclusion and a special application example of the
DPO.

1. Introduction
Die grossartige Schonheit eines Graphen besteht darin,
dass er unklare, schwer durchschaubare Ratsel auf ein
wunderbares Ding aus Linien und Knotenpunkten
reduzieren kann.
(D. Olivastro. Das chinesische Dreieck: die kniffligsten
mathematischen Ratsel aus 10000 Jahren. Droemer
Knauer, Munchen, 1995, S.273)
When we talk about graphs, we talk about a powerful
and well-established tool to represent various data structures as well as states of concurrent and distributed systems.
More generally speaking you can describe whole sets of
objects including the relations between them [2].
Famous examples and various kinds of graphs are the
following ones [2] :

Figure 1. Petri net

flow diagrams
Petri nets
UML diagrams
Entity-Relationship diagrams
finite automata
maps (e.g. of roads or countries)
In many cases you do not only want to build up graphs as
a static structure with a static behavior of its objects. If you
need to have a dynamical structure you need a graph which
is able to transform. For instance you are firing transitions
in Petri Nets or UML state diagrams or you want to transform a graph by deleting nodes or edges in the case of other
UML object diagrams. Graphs are quite generic structures
and therefore graph transformations combine the concepts
of graphs and the application of rules to transform them.
Graphs are well-suited and often used structures and
because of their quite different applications, you can find
graphs in many different application areas as various kinds.
They can be directed or undirected, maybe labeled or unlabeled. They can be simple or multiple and they are
equipped with binary edges or hyperedges [2]. Sometimes,

2.1. category theory

Figure 2. crossover as a graph [3]

in the case of Petri nets, graphs even provide two different


types of nodes, just called either condition or transition.
By the way a graph with this attribute is called bipartite
graph. Because of their possible attribute to be a directed
graph, the graph is a quite famous data structure for transportation and tour planning problems (maps, Konigsberger
Bruckenproblem , e.g. in the area of theoretical computer
science and mathematics). With their directed edges from
one node to another one, you can also easily represent various control flows, e.g. test results with a switch between
TRUE and FALSE.
In this paper we only focus on directed, edge-labeled and
multiple graphs with binary edges. Furthermore we concentrate on the double-pushout approach as the one of the most
frequently used approaches for a graph transformation.
This kind of graph is a closed system G = (V,E,s,t,l). The
capital letter V describes in this case a finite set of nodes
whereas the capital letter E describes a finite set of edges.
These two sets of objects build up the graph together. The
letters s, t and l qualify three different mappings. s: E
V is a mapping which assigns a source s(e) node to every
edge in the set of E. The other analog mapping t: E V
assigns a target t(e) node to every edge in E so that you have
the confirmation that every edge is suspended on two nodes
[3]. If there is an edge in the graph with s(e) = t(e) it is
also called a loop. Of course you can also have a node with
more than one entry or exit edge. The last mapping l: E
V is needed to assign a label (l(e)) to every edge in E. The
description of these kinds of graphs is absolutely flexible
and has the possibility to cover also other types of graphs.

2. graph rewriting
Before we will go further to the explicit approaches of
graph transformations, we first have to introduce some important notions around the topic graph rewriting for the better understanding.

The category theory occupies a central position not only


in contemporary mathematics, but also in the area of the
theoretical computer science and is therefore also the basis
for the algebraic approach of graph transformations. It can
roughly be described as an abstract way to deal with different algebraic mathematical structures and the relationships
between them. Furthermore it is at the very least a quite
powerful language and conceptual framework which allows
to see how structures of different kinds are related to one
another as well as the universal components of a family of
structures of a given kind. In our case and context we will
have a look at the category of graphs, with its components
nodes and edges.
Generally speaking a category C can be described as a
class ob(C) of objects, with the following additional auxiliary attributes:
There also exists an other class mor(C) of morphisms
for every pair of objects (a,b) with a unique source object a
and target object b, we write f: a b. Furthermore, for a
triple a, b and c of objects, there is also a partial operation
from pairs of morphisms (f: a b and g: b c) to a final
morphism h: a c, which is also called the composition
of morphisms in the category C. Finally, for every single
object a, there is a morphism 1x: x x, called the identity
morphism of a, often written as id(a). To sum it up, all
morphisms in the category C have to satisfy the two axioms
associativity and identity [4].
Therefore an interesting feature of the category theory is
that it provides a uniform treatment of the notion of structure. Especially the algebraic approach with its methods of
pushouts as graph morphisms which will be described later
on, based upon this category theory (category of graphs).

2.2. subgraphs
Formally a graph G is a real subgraph of another graph
H, if it satisfies the following conditions: all nodes of G
also consist in H (VG in VH ), all edges of G also consist in
H (EG in EH ), every edge in G has the same source node
in H (s(e)G = s(e)H ), analog has every edge in G the same
target node in H (t(e)G = t(e)H ) and finally every edge in
G must have the same label in the other graph H.
With a given graph, you can simply obtain a subgraph
by removing some nodes and edges, with the essential
condition that the removal of a node is accompanied by the
removal of all its adjacent edges. More formally speaking:
the given graph, as is generally known, is a system G =
(V,E,s,t,l). You want to remove nodes and edges, so that
you have in this case additionally a pair of nodes and edges,
written as X = (VX ,EX ) in (V,E).

Now you optain the subgraph H formally in that way:


H = G-X = (V-VX ,E-EX ,s,t,l) with s(e)=s(e), t(e)=t(e)
and l(e)=l(e) for all e E-EX . [2]
Here are three published examples of subgraphs G1, G2
and G3 of the given graph G:

the dangling condition


This condition will be satisfied if an edge e of M - g(L)
neither has its source node nor its target node in g(L) g(K). That means that, if you delete one node, you have to
delete all edges that are adjacent to this one node.
The addition of these two sub conditions forms the gluing
condition [2]
identification condition + dangling condition
= gluing condition

Figure 3. real subgraphs

2.3. graph morphisms


A graph morphism in the category of graphs assigns the
nodes and edges of a given graph G to the nodes and edges
of another graph H while the structure of the original graph
G is preserved. Of course in our case with the use of labeled
graphs, the node and edge labeling is preserved too.
More formally a graph morphism g: G H is a pair of
functions, where one of these functions is a node mapping
gV : VG VH and the other one is an edge mapping gE :
EG EH [3]
If G is an image in H, then it is called a match of G in
H. The match of G in H according to the graph morphism g
is moreover the subgraph g(G) in H, induced by the pair of
mappings (g(V), g(E)). If you have an additional third graph
F, then you will have a possible sequence of morphisms: f:
F G and g: G H then yields to the morphism g o f: F
H

2.4. gluing condition


Within the algebraic approach and the application of the
double-pushout approach which will be described later on,
you will only have a valid graph transformation if the match
of the left graph L of the rule of transformation in the given
graph G satisfies the gluing condition.
The gluing condition is divided into the following two
sub conditions:
the identification condition
This condition will be satisfied if two different elements x
and y of the left graph L either are mapped injectively (none
two different elements of the definition quantity are mapped
to the same element of the target quantity) or may only not
be mapped injectively if these two elements are not deleted
by the transformation rule. More formally
Tspeaking: mappings O(x) = O(y) only if x=y or x,y L
R

3. algebraic approach
There are several approaches of graph rewriting, one
of them is the algebraic approach which based on the just
mentioned category of theory. Actually the algebraic approach is divided into sub approaches, in this paper we will
discuss two of them, namely the single-pushout approach
(SPO) and the more frequently used double-pushout approach (DPO). Both approaches have the same intention to
perform rule-based transformation of graphs as the method
to execute local changes on graphs for the use of them in
dynamical environments. Generally speaking the algebraic
approach should specify formally and visually the semantics of rule-based systems. The rules have to express which
part of graph is to be replaced by another graph. The general
production is always described as p: L R [1]
If you want to transform a graph, you can have many
problems, such as there are some edges left after the deletion of nodes and these edges do not have any source or target node. These transformations are forbidden. To find out
which transformations on a graph are allowed, we use the
important upper mentioned gluing condition. If the match
satisfies the gluing condition, the graph transformation is
valid and be can performed without any problems later on.
The action of gluing two graphs is a construction in the context of the category of graphs and graph morphisms and is
called pushout.

3.1. double-pushout approach (DPO)


The double-pushout approach, shortly called DPO, is a
sub approach of the algebraic approach and is the frequently
used approach for graph transformations. The DPO adopts
a specific rule for the graph transformation which describes
on the one hand which parts are replaced by which other
ones and on the other hand side the DPO replies to the
important question which kinds of transformations are allowed.
From the perspective of the DPO a graph rewriting rule
is a pair of morphisms in the category of graphs with total
graph morphisms as arrows, specified by the formal rule r =

(L K R). The graphs L and R are respectively called


the left-hand side and the right-hand side of the rule. The
graph K is often called gluing graph or interface graph. A
rewriting step with the application of the DPO-production
is defined as a pair (L K R) or (L K R) of two
graph morphisms as arrows in the category of graphs with
an interface graph K, where K L is injective. Because of
that the interface graph K is a real subgraph of L as well as
of R [1,4].
A rule application r = (L K R) can be depicted by
the following diagrams. They will illustrate the formal step
of a graph rewriting and will describe why this approach
is called double-pushout approach. The
T gluing graph K is
rightly described in the diagrams as L
R.

Figure 4. finding the match


The graph morphism OL in the shown diagram models
an occurrence of L in G and is called the match. Practical
understanding of this is that L is a subgraph that is matched
from G and after a match is found, the left side of the rule
(L) is replaced by theT
right side of the rule (R) in the host
graph G where K as L R serves as some kind of interface.

Figure 6. construction of the final graph

temporary graph D (Figure 6).


More formally: The single graph morphisms OL T R :
T
L
R D and OR : R H are given by OL T R (v) =
OL (v) for all v VL T R , OL T R (e) = OL (e) for all e
EL T R , OR (v) = OL T R (v) if v VL T R , OR (v) = v
if v VR - VL T R , OR (e) = OL T R (e) if e EL T R ,
OR (e) = e if e ER - EL T R [2]

3.2. double-pushout approach:


formal application example
The following diagrams should illustrate the graph
rewriting step of the DPO on a real graph example.
Given are two elements: the hostgraph G (Figure 7) and
the transformation rule includes the left side (Figure 8) and
the right side (Figure 9).

Figure 7. hostgraph [3]

Figure 5. building the temporary graph


If a match is found (Figure 4) there are two steps to
achieve the graph rewriting. First you have to build a
temporary graph (D) as a subgraph of the host graph G
by deleting the matching elements (Figure 5. Note: the
dangling condition within the gluing condition ensures that
D is graph). Finally you have to build the final
T transformed
graph H by adding the elements of R - L
R to the built

Figure 8. left side of the rule [3]

Figure 12. final transformed graph [3]


Figure 9. right side of the rule [3]

Step 1: finding a match L in G which maintains the gluing condition (Figure 10)

for the graph rewriting step. You can use the graphical rule
representation without an interface graph by depicting only
the graphs L and R. Thus a rewriting step is only defined by
a single pushout diagram with a single graph morphism as
arrows as a the formal rule (production) r: L R [1]

Figure 10. found match [3]

Step 2: building a temporary graph Z (Figure 11)

Figure 13. SPO diagram [1]


This diagram illustrates the practical understanding of
the SPO. You perform the rewriting step with only a single derivation (morphism) as a single-pushout from the host
graph L to the target graph R.

4. comparison between DPO and SPO


Figure 11. temporary graph Z [3]

Step 3: construction of a final transformed graph N


(Figure 12)

3.3. single-pushout approach (SPO)


In contrast to the recently mentioned DPO, a graph
rewriting rule of the SPO approach is only a single morphism and therefore only a single derivation of the host
graph G with context again to the category of graphs.
The SPO is often used in cases where the interface graph
K as in the DPO is only a set of nodes but without any adjacent edges. Then you do not have to look at the edges

When you take a closer look on these two sub approaches


of the general algebraic approach, you will see that they are
quite similar to each other. Because of the fact, that the
DPO performs more secure transformations with the condition that the DPO operates structure-preserving, this approach is more frequently used than the SPO.
The main and important difference between the two
approaches is that the SPO performs the graph derivation
without an interface graph K between the host graph G and
the target graph H. Therefore the SPO operates against the
DPO with no gluing condition, which means without an
identification and following dangling condition. This is
the reason why the SPO is said to be more powerful than
the DPO because it has no restrictions within the graph
rewriting step. But big problems can raise if there are
edges after the rewriting step left which has no source or

target node. This consequence of a rewriting is strictly


forbidden because the transformed graph is not a valid one.
Therefore the SPO includes the danger that the graph could
be destroyed after the transformation with some dangling
edges. The DPO operates real structure-preserving with the
help of the gluing graph and is therefore used more often
because it guarantees the right and allowed transformation
on the graph.

5. double-pushout diagram: Pacman as an application example


We all know the computer game Pacman from former
times. If you remember the game field of Pacman contains
different players, like Pacman and a number of ghosts, and
also a finite number of positions where all players can move
to. Pacman has to eat points and has to watch the ghosts
who want to eat him also. With context to this topic you
can also represent the game field as well as the movements
of the players as a closed graph system (Figure 14) with
essential transformations on this graph if a player changes
its position on the field (Figure 15) or an action is fired,
like for instance if one ghost eats Pacman (Figure 16) and
therefore the game is over.

Figure 14. game field of Pacman

Figure 15. transformation: movePacman()

Figure 16. transformation: killPacman()

6. References
1. Grzegorz Rozenberg, editor: Handbook of Graph
Grammars and Computing by Graph Transformation.
Vol.1: Foundations. World Scientific,Singapore,1997.
2. H.-J. Kreowski, R. Klempien-Hinrichs, S. Kuske:
Some Essentials of Graph Transformation. University
of Bremen, Department of Computer Science. Bremen
3. H.-J. Kreowski: Formale Sprachen: Graphtransformation. Universitt Bremen, Sommersemester 2004
4. www.wikipedia.de

Das könnte Ihnen auch gefallen