Jul 15, 2006 - Example. Top: graph GS = (VS,ES ,sS ,tS), with. VS = {u,v,x,y}, ES = {a,b},. sS : ES â VS : a,b â¦â u,. tS : ES â VS : a,b â¦â v. Bottom: graph GT ...
Overview Tutorial on
Fundamentals of Algebraic Graph Transformation Hartmut Ehrig, Ulrike Prange : TU Berlin Karsten Ehrig : U. Leicester
July 15, 2006
1
General Introduction and Motivation
2
Category of Graphs and Gluing Construction
3
Graph Transformation Systems
4
Independence of Graph Transformations and Critical Pairs
5
Adhesive HLR Categories and Typed Attributed Graph Transformation Systems
6
Advanced Features and Conclusion
Based on
FAGT-Book, EATCS Monographs in TCS, Springer 2006
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
2 / 73
July 15, 2006
4 / 73
What is Graph Transformation? Part I General Introduction and Motivation 1
What is Graph Transformation?
2
Aims and Paradigms of Graph Transformation
3
Graph Transformation Approaches
Rule-based modification of graphs p = (L, R) A LA
R
from Chomsky grammars on strings to graph grammars; from term rewriting to graph rewriting;
4
Application Areas of Graph Transformation Systems
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
from textual description to visual modeling.
July 15, 2006
3 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
Aims and Paradigms of Graph Transformation
Graph Transformation Approaches
Computing by graph transformation is a fundamental concept for
1
Node label replacement approach
2
Hyperedge replacement approach Algebraic approach
3
visual modeling and specification,
Double Pushout (DPO) (since 1973) Single Pushout (SPO) (since 1984/90) High Level Replacement (HLR) (since 1991/2004)
model transformation, concurrency and distribution, software development.
Projects Supported by EU projects since 1990: COMPUGRAPH 1 + 2, GETGRATS, APPLIGRAPH, SEGRAVIS.
4
Logical approach
5
Theory of 2-structures
6
Programmed graph replacement approach
Literature Handbook of Graph Grammars and Computing by Graph Transformation, Vol. 1 (1997)
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
5 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
Application Areas of Graph Transformation Systems
July 15, 2006
6 / 73
Part II
Application areas are
Category of Graphs and Gluing Construction
model and program transformation; syntax and semantics of visual languages; visual modeling of behavior and programming; modeling, metamodeling, and model-driven architecture;
5
Graphs, Typed Graphs and Morphisms
6
Categories of Sets and Graphs
7
Mono-, Epi- and Isomorphisms
8
Pushouts as Gluing Construction
9
Composition and Decomposition of Pushouts
10
Pullbacks as Dual Construction of Pushouts
software architectures and evolution; refactoring of programs and software systems; security policies.
Literature Handbook of Graph Grammars and Computing by Graph Transformation, Vol. 2 (1999) Proc. ICGT ’02-06, LNCS H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
7 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
8 / 73
Graphs and Graph Morphisms
Example: Graphs and Graph Morphisms Example
Definition graph G = (V , E , s, t) consists of
E1
V1
fE
=
fV
E2
s2 t2
sets V of nodes and E of edges, and source and target functions s, t : E → V
Top: graph GS = (VS , ES , sS , tS ), with
s1 t1
VS = {u, v , x, y }, ES = {a, b}, GS
sS : ES → VS : a, b → u, tS : ES → VS : a, b → v
V2
Bottom: graph GT = (VT , ET , sT , tT ), with
graph morphism f : G1 → G2 , f = (fV , fE ) consists of two functions fV : V1 → V2 and fE : E1 → E2 with fV ◦ s1 = s2 ◦ fE and fV ◦ t1 = t2 ◦ fE
a b
u
v y
x
VT = {s, t}, ES = {e}, sT : ET → VT : e → s, tT : ET → VT : e → t
s
Inbetween: graph morphism f : GS → GT with
composition g ◦ f = (gV ◦ fV , gE ◦ fE ) : G1 → G3 of f : G1 → G2 and g : G2 → G3 is graph morphism
e
t
GT
fV : VS → VT : u, x → s; v , y → t fE : ES → ET : a, b → e
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
9 / 73
Typed Graphs and Typed Graph Morphisms
H. Ehrig, U. Prange, K. Ehrig ()
July 15, 2006
Tutorial on Graph Transformation
10 / 73
Example: Mutual Exclusion and Gluing Construction Example non−active
Definition
2
1
TG
TG :
non−active active
F2
P
F1
start crit check setTurn
July 15, 2006
11 / 73
S
P
D 2
start non−active
G2
Tutorial on Graph Transformation
R
P
F1
R
setTurn
non−active
= type2 type1
H. Ehrig, U. Prange, K. Ehrig ()
P
m
typed graph morphism f : G1T → G2T is graph morphism f : G1 → G2 with type2 ◦ f = type1 f
R
start
typed graph G T = (G , type) over TG is graph G and graph morphism type : G → TG
G1
P
setFlag
type graph is a distinguished graph TG = (VTG , ETG , sTG , tTG )
active
P
T
start
P
2
1
P
start
T
P
G1 F1
setTurn non−active
non−active
R
active
R
1
P
T
R
start
R
T
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
12 / 73
Notion of Category
Examples of Categories 1
Definition
objects: sets, morphisms: functions f : A → B, composition for f : A → B and g : B → C defined by (g ◦ f )(x) = g (f (x)), identity: identical mapping idA : A → A : x → x.
category C = (ObC , MorC , ◦, id) defined by class ObC of objects; set MorC (A, B) of morphisms ∀A, B ∈ ObC ;
2
composition ◦ : MorC (B, C ) × MorC (A, B) → MorC (A, C ) ∀A, B, C ∈ ObC ,
3
such that: Associativity. (h ◦ g ) ◦ f = h ◦ (g ◦ f )
2
Identity. f ◦ idA = f and idB ◦ f = f
g
f
category GraphsTG objects: typed graphs, morphisms: typed graph morphisms, composition and identity: as in Graphs.
h
∀A → B → C → D 4
∀f : A → B
category Alg(Σ) objects: algebras over a given signature Σ, morphisms: homomorphisms composition and identity: componentwise on the carrier sets.
for f ∈ MorC (A, B), we write f : A → B H. Ehrig, U. Prange, K. Ehrig ()
category Graphs objects: graphs, morphisms: graph morphisms, composition and identity: componentwise on nodes and edges.
identity morphism idA ∈ MorC (A, A) ∀A ∈ ObC ; 1
category Sets
July 15, 2006
Tutorial on Graph Transformation
13 / 73
Mono-, Epi- and Isomorphisms
H. Ehrig, U. Prange, K. Ehrig ()
July 15, 2006
Tutorial on Graph Transformation
14 / 73
Pushouts as Gluing Construction
Definition m : B → C ∈ MorC is monomorphism if m ◦ f = m ◦ g implies f = g A
f g
B
m
C
e : A → B ∈ MorC is epimorphism if f ◦ e = g ◦ e implies f = g
A
Definition
∀f , g : A → B ∈ MorC e
B
f g
pushout (PO) over morphisms f : A → B and g : A → C defined by
C
f
B
g
=
g
C
f
D =
a pushout object D and morphisms f : C → D and g : B → D with f ◦ g = g ◦ f
∀f , g : B → C ∈ MorC
Fact In Sets, Graphs, and GraphsTG the monomorphisms (or epimorphisms or isomorphisms) are exactly those morphisms which are injective (or surjective or bijective, respectively). Tutorial on Graph Transformation
July 15, 2006
k
=
h x
X with universal property: For all objects X , morphisms h : B → X , k : C → X with k ◦ g = h ◦ f : there is a unique morphism x : D → X with x ◦ g = h and x ◦ f = k
i : A → B ∈ MorC is isomorphism if there is i −1 : B → A ∈ MorC with i ◦ i −1 = idB and i −1 ◦ i = idA
H. Ehrig, U. Prange, K. Ehrig ()
A
15 / 73
The pushout construction is unique up to isomorphism.
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
16 / 73
Pushouts in Sets
Pushouts in Graphs and GraphsTG Fact
Fact
In Graphs and GraphsTG , pushouts can be constructed componentwise for nodes and edges in Sets.
g
f
In Sets, pushout C → D ← B over f : A → B and g : A → C is
D = B ∪ C |≡ , with ≡ generated by (f (a), g (a)) ∈ ≡ f (c) = [c] ∀c ∈ C and g (b) = [b] ∀b ∈ B.
∀a ∈ A and
Example EA
Example a
5
A b
6
C
c
sA
1
d [1]
7
B 2
8
H. Ehrig, U. Prange, K. Ehrig ()
3
4
GB
sB
VA
gE
GA
EB
fE
fV
VB
gE
(1, 5), (2, 5), (2, 6), (3, 7) ∈ ≡
D [1] = [2] = [5] = [6] = {1, 2, 5, 6}, [3] = [7] = {3, 7}, [3] [8] [4] [4] = {4}, [8] = {8} July 15, 2006
Tutorial on Graph Transformation
gV
EC
fE
sC
sD fV
VC
17 / 73
Composition and Decomposition of Pushouts
gV
ED
H. Ehrig, U. Prange, K. Ehrig ()
GC
GD
VD
July 15, 2006
Tutorial on Graph Transformation
18 / 73
Pullbacks as Dual Construction of Pushouts
Fact PO composition: (1) and (2) POs ⇒ (1) + (2) PO PO decomposition: (1) and (1) + (2) POs ⇒ (2) PO
A
f
B
e
E
Definition
g
(1)
g
(2)
e
C
f
D
e
F
pullback (PB) over morphisms f : C → D and g : B → D defined by
X
a pullback object A and f
morphisms : A → B and g : A → C with g ◦ f = f ◦ g
Example
(1)
x k
h
= = A
f
B
g
=
g
C
f
D with universal property: For all objects X , morphisms h : X → B, k : X → C with f ◦ k = g ◦ h: there is a unique morphism x : X → A with f ◦ x = h and g ◦ x = k.
(2)
The composition and decomposition of pullbacks is dual to pushouts.
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
19 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
20 / 73
Pullbacks in Sets, Graphs and GraphsTG
Part III Graph Transformation Systems
Fact g
f
In Sets, pullback C ← A → B over f : C → D and g : B → D: A = d∈D f −1 (d) × g −1 (d) = {(c, b) | f (c) = g (b)} ⊆ C × B with f : A → B : (c, b) → b and g : A → C : (c, b) → c.
11
Graph Productions and Transformations
12
Graph Transformation Systems, Grammars and Languages
13
Mutual Exclusion Graph Grammar
14
Applicability and Gluing Condition
15
Construction of Graph Transformations
16
Embedding of Transformations
∼
Special case: A = B ∩ C for inclusions f and g . In Graphs and GraphsTG , pullbacks can be constructed componentwise for nodes and edges in Sets.
H. Ehrig, U. Prange, K. Ehrig ()
July 15, 2006
Tutorial on Graph Transformation
21 / 73
Graph Productions and Transformations
H. Ehrig, U. Prange, K. Ehrig ()
July 15, 2006
Tutorial on Graph Transformation
22 / 73
Recap: Example Mutual Exclusion Example
Definition
non−active
l
P
setFlag
(typed) graph production r
p = (L ← K → R) consists of (typed) graphs L, K , and R,
L
l
K
r
m
(1)
k
(2)
R n
R
P
F1
R
m
2
1
TG :
non−active active
F2
P
F1
start crit check setTurn
23 / 73
S
P
D 2
start non−active
∗
(typed) graph transformation, G0 ⇒ Gn , is sequence G0 ⇒ G1 ⇒ . . . ⇒ Gn of direct (typed) graph transformations
July 15, 2006
R
setTurn
non−active
Tutorial on Graph Transformation
P
start
injective (typed) graph morphisms l g f G D H and r p,m direct (typed) graph transformation G =⇒ H given by POs (1) and (2), production p and match m : L → G
H. Ehrig, U. Prange, K. Ehrig ()
active
P
T
start
P
2
1
P
start
T
P
G1 F1
setTurn non−active
non−active
R
active
R
1
P
T
R
start
R
T
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
24 / 73
Example: Mutual Exclusion 2
Example: Mutual Exclusion 3
Example
Example
non−active
setFlag :
P
active
R
P
R
P
F1
R
non−active
⇓enter
non−active non−active
start
setTurn
non−active
non−active
S:
1
non−active
P
R
P T
start
P setTurn1:
P T
R
P
P
T
R
P
R
P
T
T
R
P
P
T R
P
F1
non−active
T
G1 :
R
1
R
P
R
T
P
R T
⇓setFlag
1
non−active
G2 :
1
R
P
F1
P
P
R T
setTurn
2
crit
⇓exit
R
P T
non−active
active
active
F1
start
active
F2
⇓setTurn1
F2
P
G4 :
2
setTurn
2
crit
G5 :
2
1
P
F1
R
T
P
2
start
setTurn
check
start
crit
H. Ehrig, U. Prange, K. Ehrig ()
P
R
non−active
F2
P
R
active
active
F1
start
P crit
P
⇓setFlag
T R
active
exit:
R
check
P check
T P
setTurn
enter :
1
active
F2
start
check
T
G3 :
start
P
setTurn
setTurn2:
2
July 15, 2006
Tutorial on Graph Transformation
25 / 73
Graph Transformation Systems, Grammars and Languages
H. Ehrig, U. Prange, K. Ehrig ()
July 15, 2006
Tutorial on Graph Transformation
26 / 73
Example: Language of Mutual Exclusion Grammar S: Example
Definition (typed) graph transformation system GTS = (TG , P) consists of (type graph TG and) set of (typed) graph productions P
setFlag exit
(typed) graph grammar GG = (GTS, S) consists of GTS and (typed) start graph S
process 1 active setTurn flag =1 turn
process 2 non−act. start flag =0
setTurn2
(typed) graph language L of GG is defined by
process 1 active check flag =1 turn
∗
L = {G | ∃ (typed) graph transformation S ⇒ G }.
process 2 non−act. start flag =0
setFlag
Example typed graph transformation system ME = (TG , P) typed graph grammar MutualExclusion = (TG , P, S)
process 2 non−act. start flag =0
setFlag
setFlag
Tutorial on Graph Transformation
process 1 non−act. start flag =0
process 2 non−act. start flag =0 setFlag turn process 1 non−act. setFlag start flag =0 process 1 process 2 active non−act. setTurn start flag =1 flag =0 turn
setFlag
process 1 non−act. start flag =0 turn
process 2 active setTurn flag =1
setFlag
setFlag
process 1 active setTurn flag =1 turn
process 1 active setTurn flag =1 exit
process 1 active check flag =1 turn
process 2 active setTurn flag =1
exit
July 15, 2006
27 / 73
H. Ehrig, U. Prange, K. Ehrig ()
process 2 active setTurn flag =1 turn
process 1 active setTurn flag =1
process 2 active check flag =1 turn
process 2 active setTurn flag =1 turn
exit
setTurn2
process 1 non−act. start flag =0
process 2 active check flag =1 turn enter
setFlag
setTurn2
enter
process 1 active crit flag =2 turn
setFlag
setTurn1
process 2 active setTurn flag =1
setTurn2
P = {setFlag , setTurn1, setTurn2, enter , exit}.
H. Ehrig, U. Prange, K. Ehrig ()
process 2 non−act. start flag =0
setTurn1
enter
process 1 active crit flag =2 turn
process 1 non−act. start flag =0 turn
process 1 non−act. start flag =0
process 2 active crit flag =2 turn
setFlag
enter
process 2 active setTurn flag =1
process 1 active setTurn flag =1
process 2 active crit flag =2 turn
Tutorial on Graph Transformation
July 15, 2006
28 / 73
Applicability and Gluing Condition
Example and Counterexample: Gluing Condition
Problem: When is production p applicable via match m?
Counterexample
Example
Definition
setFlag non−active
production p is applicable to G via match m if context graph D exists such that (1) is PO
L
K
l
R
r
P
active
R
P
R
start
(1)
m
k
G gluing points GP = lV (VK ) ∪ lE (EK ) = l (K )
D
f
F1
R
2
1
S
P
P
∅
m
D 2
start non−active
identification points IP =
∅
P
m
non−active
Gluing condition: IP ∪ DP ⊆ GP
P setTurn
T
P
2
R
1
P
T
start
non−active
G1
P
F1
2
R
1
P
T
e % e % e % e % e % e D% %e e % e % e % e %
S
P
start non−active
setTurn non−active
non−active
start
active
R
1
P
T
R
start
start
{v ∈ VL | ∃w ∈ VL , w = v : mV (v ) = mV (w )} ∪ {e ∈ EL | ∃f ∈ EL , f = e : mE (e) = mE (f )}
dangling points DP =
GP = l (K ): both nodes in L,
GP = l (K ) = ∅,
{v ∈ VL | ∃e ∈ EG \mE (EL ) : sG (e) = mV (v ) or tG (e) = mV (v )}
IP = ∅,
IP = ∅,
DP = node labelled R.
DP = node labeled P.
Fact
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
gluing condition is not satisfied, because DP GP
gluing condition is satisfied with IP ∪ DP ⊆ GP
Context graph D with the PO (1) exists iff the gluing condition is satisfied. If D exists, it is unique up to isomorphism. July 15, 2006
29 / 73
H. Ehrig, U. Prange, K. Ehrig ()
July 15, 2006
Tutorial on Graph Transformation
Construction of Direct Graph Transformations
Embedding of Graph Transformations
Fact
Problem: When can graph transformation t : G0 ⇒ Gn be extended to ∗ t : G0 ⇒ Gn for k0 : G0 → G0 ?
∗
L
l
K
r
R
m
(1)
k
(2)
n
p,m
If gluing condition is satisfied, G ⇒ H can be constructed in two steps:
2
Theorem ∗
G D H Delete those nodes and edges in G that are reached by the match m, but keep the image of K , i.e. D = (G \m(L)) ∪ m(l (K )), such that G = L +K D in PO (1). f
1
30 / 73
g
Given transformation t : G0 ⇒ Gn and consistent morphism k0 : G0 → G0 w.r.t. t, then there is an extension diagram (1) over t and k0 . ∗ t G0 Gn
Add those nodes and edges that are newly created in R, i.e.
H = D ∪ (R\r (K )), such that H = R +K D in PO (2). This construction is unique up to isomorphism.
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
k0
(1)
G0
t
kn
∗ Gn
Problem: What is consistency of k0 with respect to t?
July 15, 2006
31 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
32 / 73
Boundary, Context and Consistency
Example: Embedding of Graph Transformation
Definition Example
boundary B is smallest subgraph of G0 containing IP and DP of k0 : G0 → G0
bn
non−active
context C is smallest subgraph of G0 such that G0 = G0 +B C
1
P
1
t
B
consistency: boundary B is preserved by G0 ⇒ Gn leading to bn : B → Gn
S
T
non−active
R
P
2
start
non−active
active
∗
P
G5
start
1
P
F1
R
C bn
B In case of consistency we also have Gn = Gn +B C
b0
(2) C
H. Ehrig, U. Prange, K. Ehrig ()
G0
t
k0
(1)
G0
t
∗ Gn
1
non−active
P
1
T
R
G0
P
start
k5
T
R
T
R
non−active
P
start
2
setTurn
k0
Fact
T
2
active
∗
P
G5
start
1
F1
R
T
R
T
non−active
P
2
setTurn
P
start
kn
∗ Gn
Tutorial on Graph Transformation
July 15, 2006
33 / 73
H. Ehrig, U. Prange, K. Ehrig ()
July 15, 2006
Tutorial on Graph Transformation
34 / 73
Parallel and Sequential Independence
Part IV Independence of Graph Transformations and Critical Pairs
Problem: When are direct transformations commutable?
Definition p1 ,m1
p2 ,m2
17
Parallel and Sequential Independence
18
Local Church-Rosser Theorem
19
Parallelism Theorem
G =⇒ H1 and G =⇒ H2 are parallel independent if m1 (L1 ) ∩ m2 (L2 ) ⊆ m1 (l1 (K1 )) ∩ m2 (l2 (K2 )). p2 ,m2 p1 ,m1 G =⇒ H1 =⇒ H2 are sequentially independent for comatch n1 : R1 → H1 if n1 (R1 ) ∩ m2 (L2 ) ⊆ n1 (r1 (K1 )) ∩ m2 (l2 (K2 )).
20
Global Determinism and Confluence
Fact
21
Critical Pairs
p1 ,m1
p2 ,m2
R
r1
1
22
Local Confluence Theorem - Critical Pair Lemma
23
Functional Behavior of Graph Transformation Systems
K
l1
1 1 G =⇒ H1 and G =⇒ H2 are n j k parallel independent iff there exf ist morphisms i : L1 → D2 and H1 g D1 j : L2 → D1 such that f2 ◦ i = m1 and f1 ◦ j = m2 . 1
1
1
L1
L2
m1 m2
G
l2
K2
r2
n2
k2
i f2
D2
R2
g2
H2
Similar for sequential independence. H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
35 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
36 / 73
Examples: Parallel and Sequential Independence
Local Church-Rosser Theorem
Example
Theorem
Example setFlag non−active
K1 ...
P
R
P
setFlag non−active
L1
R
P
start
1
P
2
R
...
R
P
...
T P
R
crit
1
P
P
P
2
P
P
2 g1
non−active
R
P
1
T
R
1
P
T
R
P
P
P
p2 ,m
R
...
H. Ehrig, U. Prange, K. Ehrig ()
p1 ,m
p1 ,m1
p1 ,m
p2 ,m2
G
G
D2
active
F2
T
2
F2
1
P
p1 ,m1
p2 ,m2
p2 ,m2
p1 ,m1
H1
crit
f2
R
P
T
R
sequentially independent: n2 (R1 ) ∩ m3 (L2 ) = {node labelled R} = n2 (r1 (K1 )) ∩ m3 (l2 (K2 )) July 15, 2006
H2 G
start
Tutorial on Graph Transformation
p2 ,m
G =⇒ H2 =⇒1 G are sequentially independent.
2
parallel independent: m(L1 ) ∩ m (L2 ) = {node labelled R} = m(l1 (K1 )) ∩ m (l2 (K2 ))
p2 ,m2
m3
crit non−active 1
start
R
p1 ,m1
If G =⇒ H1 and G =⇒ H2 are parallel independent, there are G and H1 =⇒2 G and H2 =⇒1 G such that G =⇒ H1 =⇒2 G and
start
active
start
f2
T
2
start
start
R F2
D1
active
D2
K2
non−active
n2
non−active
S
start non−active
f1
T
P
R1
m
m
non−active
R
non−active
P
K2
start
D1 2
L2
1
setFlag L2
enter T K1
p1 ,m1
p2 ,m2
If G =⇒ H1 =⇒ G are sequentially independent, there are H2 and p2 ,m2
p1 ,m
p1 ,m1
p2 ,m2
G =⇒ H2 =⇒1 G such that G =⇒ H1 and G =⇒ H2 are parallel independent.
37 / 73
Example: Local Church-Rosser Theorem
H. Ehrig, U. Prange, K. Ehrig ()
July 15, 2006
Tutorial on Graph Transformation
Overview of Parallelism and Concurrency
38 / 73
SKIP
Example non−active
P
1
T
start
R
1
P
start
P
R
P T
Solution: 1. Parallel composition p1 + p2 (independency) 2. E-concurrent production p1 ∗E p2 (dependency)
Theorem
setFlag ,m
active
active
F1
2
start
S
setFlag ,m
non−active
Problem: How to compose productions p1 and p2 ?
non−active
G
G1
2
1
P
setTurn
setTurn
P
R T
2
p1
start
p2 p1 +p2
H1
setFlag ,m
setFlag ,m
p2 active 1
R
P
setTurn
H. Ehrig, U. Prange, K. Ehrig ()
X F1
T Tutorial on Graph Transformation
P
H H2
p1
p1
G
p2 p 1 ∗E p 2
G
G
active
F1
Concurrency
Parallelism G
non−active
F1
2
setTurn
July 15, 2006
39 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
40 / 73
Parallel Productions and Transformations
Parallelism Theorem
Definition l
r
l
r
1 1 2 2 Given productions p1 = (L1 ← K1 → R1 ) and p2 = (L2 ← K2 → R2 ), the parallel production p1 + p2 is defined by the disjoint union
l1 ∪l2
r1 ∪r2
Theorem Given a transformation system GTS, we have: 1
p1 + p2 = (L1 ∪ L2 ←− K1 ∪ K2 −→ R1 ∪ R2 ) The application of a parallel (typed) graph production is called a parallel direct (typed) graph transformation.
2
Example
3 non−active
P enter + setFlag :
start
R
P
T
P check
active
R
setTurn
T R
P
R
F1
H. Ehrig, U. Prange, K. Ehrig ()
P
R
T
P crit
Tutorial on Graph Transformation
F1
R
Synthesis. If G ⇒ H1 ⇒ G via productions (p1 , p2 ) are sequentially independent, then there is a parallel transformation G ⇒ G via the parallel production p1 + p2 . Analysis. For G ⇒ G via p1 + p2 there are sequentially independent G ⇒ H1 ⇒ G via (p1 , p2 ) and G ⇒ H2 ⇒ G via (p2 , p1 ). G Bijective correspondence. p1 p2 The synthesis and analysis p1 +p2 constructions are inverse to H1 H2 each other up to p2 p1 isomorphism. G
F2
July 15, 2006
41 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Concurrency Theorem
Example: Concurrency Theorem
Problem: How to compare productions and transformations in general?
Example non−active
Theorem Given productions p1 and p2 with E -concurrent production p1 ∗E p2 , then: 1
2
3
Synthesis. Given an E -related transformation sequence G ⇒ H ⇒ G via (p1 , p2 ), then there is a synthesis construction leading to a direct transformation G ⇒ G via p1 ∗E p2 . Analysis. Given a direct transformation G ⇒ G via p1 ∗E p2 , then there is an analysis construction leading to an E -related transformation sequence G ⇒ H ⇒ G via (p1 , p2 ). Bijective correspondence. The H synthesis and analysis p1 p2 constructions are inverse to each p 1 ∗E p 2 G G other up to isomorphism.
1
P
T
R
start
Tutorial on Graph Transformation
July 15, 2006
P
2
setTurn
G1 setTurn1,m1
non−active
G2
setFlag ∗E setTurn1,m
S
2
P T
setFlag ,m
non−active
start
1
P
active
F1 R
P T
start
2
check
setFlag ∗E setTurn1: non−active
P E :
non−active
T
active
P
P R
F1
setTurn
H. Ehrig, U. Prange, K. Ehrig ()
R
start
42 / 73
active
F1
P
1
non−active
July 15, 2006
Tutorial on Graph Transformation
43 / 73
H. Ehrig, U. Prange, K. Ehrig ()
non−active
T
non−active
P
P R
non−active
T
P R
P
start
Tutorial on Graph Transformation
T
active
P
R F1
check
July 15, 2006
44 / 73
Global Determinism and Confluence
Termination and Confluence
Problem: How to achieve global determinism of a GTS in spite of local nondeterminism?
Definition
Definition
∗
A GTS is (locally) confluent if, for all (direct) transformations G ⇒ H1 ∗ ∗ ∗ and G ⇒ H2 , there is X and transformations H1 ⇒ X and H2 ⇒ X .
A GTS is terminating if there is no infinite sequence of graph ∗ tn transformations (tn : G ⇒ Gn )n∈N with tn+1 = G ⇒ Gn ⇒ Gn+1 .
G
G ∗
∗ H2
H1
Lemma Every terminating and locally confluent GTS is also confluent.
H2
H1
∗ X ∗
Problem: How to obtain local confluence in spite of parallel dependent graph transformations?
∗ X ∗
Lemma Every confluent GTS is globally deterministic. H. Ehrig, U. Prange, K. Ehrig ()
July 15, 2006
Tutorial on Graph Transformation
45 / 73
H. Ehrig, U. Prange, K. Ehrig ()
July 15, 2006
Tutorial on Graph Transformation
Critical Pairs
Local Confluence Theorem - Critical Pair Lemma
Definition
Theorem
p1 ,o1
p2 ,o2
Pair P1 ⇐= K =⇒ P2 of direct transformations is called a critical pair if it is parallel dependent and minimal, i.e. the matches o1 : L1 → K and o2 : L2 → K are jointly surjective.
46 / 73
A (typed) graph transformation system GTS is locally confluent if all its critical pairs are strictly confluent.
Example Critical Pair 1
Critical Pair 2 non−active
non−active
active
P
F1 R
P
non−active
R
T
P
R
P
setTurn
non−active
active
P T
start
setTurn
non−active
P
R
non−active
P
F1 R
P
R
T
P
start
setTurn
start
P T
R
setTurn
P1
active
P
non−active
F1
o1
o2
K1
P
P setTurn
R
P1
active
P
F1
P setTurn
H. Ehrig, U. Prange, K. Ehrig ()
R
P
P K2 R
setFlag start
T
o2
non−active
R
setTurn1 start
T
P2
P
setFlag setTurn
non−active
P check
setTurn
T R
P
T R
setTurn
Tutorial on Graph Transformation
non−active
P
P2 R
setTurn1 start
P setTurn
start
T R
start
T
P
R
setFlag
non−active setTurn1
setTurn
F1
P
P2
P
P1
active
P
F1
K2 R
T
P
R
non−active
setFlag
setTurn1 setTurn
R
P
P2 R
check setTurn
o1
P1
active
P P
check
non−active
strict confluent critical pairs
P
non−active
P
R
K1
P
start
T R
non−active ∗
setTurn
start
R
P
T R
P
start
T R
non−active ∗
id check
P
setTurn
P start
T
P
T
P2
setTurn
R
P
check
P2 R
P
T R
id check
T R
check
check
July 15, 2006
47 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
48 / 73
Functional Behavior of Graph Transformation Systems
Part V Adhesive HLR Categories and Typed AGT Systems
Theorem If a GTS is terminating and locally confluent, it has functional behavior: 1
2
∗
For each G , there is a terminating transformation G ⇒ H in GTS, and H is unique up to isomorphism. ∗
Motivation for a Categorical Framework
25
Van Kampen Squares
26
Adhesive and Adhesive HLR Categories
27
Adhesive HLR Systems
28
Typed Attributed Graphs
29
Typed Attributed Graph Transformation Systems
∗
Each pair G ⇒ H1 and G ⇒ H2 can be extended to terminating ∗ ∗ ∗ ∗ transformations G ⇒ H1 ⇒ H and G ⇒ H2 ⇒ H with the same H.
Theorem Every layered typed graph grammar GG = (TG , P, G0 ) with injective matches terminates if it satisfies suitable layer conditions for deleting and nondeleting productions.
H. Ehrig, U. Prange, K. Ehrig ()
24
Tutorial on Graph Transformation
July 15, 2006
49 / 73
Motivation for a Categorical Framework
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
Overview of Adhesive HLR Categories
July 15, 2006
50 / 73
SKIP
Axioms: Adhesive HLR categories (C, M) satisfy: Problem: Up to now we have graph transformation theory for Graphs, GraphsTG only But the theory is required also for hypergraph transformation systems, Petri net transformation systems, transformation systems of algebraic specifications and typed attributed graph transformation systems.
2
pushouts (POs) and pullbacks (PBs) along M-morphisms
3
compatibility of POs and PBs by van Kampen squares
Theorem
Replace Graphs by suitable category. Suitable is Adhesive HLR category based on van Kampen property.
Tutorial on Graph Transformation
M ⊆ Monos closed under composition and decomposition
Examples: Sets, Graphs, GraphsTG , PTNets, AHLNets, (AGraphsATG , M)
Solution:
H. Ehrig, U. Prange, K. Ehrig ()
1
July 15, 2006
51 / 73
1
construction of adhesive HLR categories by product, slice, coslice, comma and functor categories
2
properties of adhesive HLR categories are sufficient for all constructions and results of Parts II-IV
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
52 / 73
Van Kampen Squares
Adhesive Categories
Idea: compatibility of pushouts and pullbacks
Definition
Definition
Pushout (1) is a van Kampen square if, for any commutative cube with (1) in the bottom and where the back faces are pullbacks, we have:
category C is an adhesive category if:
The top face is pushout iff the front faces are pullbacks.
Example {0, 1}
{∗}
A
m
f
(1)
C
n
B
A
f
g C
m a
n
D
D
c f
C
B
g
A
b
g
B
H. Ehrig, U. Prange, K. Ehrig ()
{0, 1, 2}
{∗, 2}
D Tutorial on Graph Transformation
C has pushouts along monomorphisms (i.e. pushouts where at least one of the given morphisms is a monomorphism)
2
C has pullbacks
3
Pushouts along monomorphisms are VK squares
Examples: Sets, Graphs, GraphsTG , Hypergraphs, ElemNets Counterexamples: PTNets, AGraphsATG
m
d
n
(2) {∗}
{∗, 2, 3} {0, 1}
{0, 1, 2, 3}
1
July 15, 2006
53 / 73
Idea for generalization: Replace monomorphisms by subclass M and pullbacks by those along monomorphisms H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
54 / 73
Construction and Properties of AHLR categories
(Weak) Adhesive HLR Categories
Theorem If (C, M1 ) and (D, M2 ) are (weak) adhesive HLR categories, then the following categories are (weak) adhesive HLR categories:
Definition category C with a morphism class M is called a (weak) adhesive HLR category if: 1
2
3
M is a class of monomorphisms closed under isomorphisms, composition (f : A → B ∈ M, g : B → C ∈ M ⇒ g ◦ f ∈ M), and decomposition (g ◦ f ∈ M, g ∈ M ⇒ f ∈ M)
1
the product category (C × D, M1 × M2 ), the slice category (C\X , M1 ∩ C\X ) and the coslice category (X \C, M1 ∩ X \C),
2
the functor category ([X, C], M − functor transformations),
3
the comma category (ComCat(F , G ; I), (M1 × M2 ) ∩ MorComCat ), where F : C → X preserves pushouts along M1 -morphisms and G : D → X preserves pullbacks (along M2 -morphisms).
C has pushouts and pullbacks along M-morphisms, and M-morphisms are closed under pushouts and pullbacks Pushouts in C along M-morphisms are (weak) VK squares
In (weak) adhesive categories, the following properties hold:
Examples: (PTNets, Mmono ), (Spec, Mstrict ), (AHLNets, Mmono ), (AGraphsATG , M) (see below)
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
55 / 73
1
Pushouts along M-morphisms are pullbacks
2
M pushout–pullback decomposition lemma
3
Cube pushout–pullback lemma
4
Uniqueness of pushout complements
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
56 / 73
Adhesive HLR Systems
Motivation for Typed AGT Systems
Definition adhesive HLR system AHS = (C, M, P) consists of (weak) adhesive HLR category (C, M) and set of productions P with morphisms in M adhesive HLR grammar AHG = (AHS, S) is an adhesive HLR system together with a distinguished start object S
Typed attributed graph transformation (AGT) is integration of typed graph transformation with data types as attributes for modeling of visual languages (VL) with alphabet of a VL given by attributed type graph, syntax given by generating grammar, operational semantics given by simulating grammar and animation.
language L of an adhesive HLR grammar is defined by ∗
L = {G | ∃ transformation S ⇒ G }.
model transformations between VLs by typed AGT systems.
The categorical framework allows to prove the results from Parts III and IVj for all the instantiations (like Graphs, HyperGraphs, PTNets etc.).
H. Ehrig, U. Prange, K. Ehrig ()
July 15, 2006
Tutorial on Graph Transformation
57 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Typed Attributed Graphs
Example: Typed Attributed Graphs
Definition
Example EG
E-graph G is defined by G = (VG , VD , EG , sourceEA ENA , EEA , (sourcej , targetj )j∈{G ,NA,EA} ). EEA
sourceG targetG
ENA targetNA
∪
param
Method
mname
par2
2
p2 Parameter par3
c
Nat
order
nat
Notations for typed attributed graphs: pname
type
m:Method
:param
par1 :Parameter
mname=add noOfPars=3
order =1
pname=p1 kind=in
:param
par2 :Parameter
order =3
:type
pname=p2 kind=in
:param
Ds = VD .
order =2
string
AGraphsATG = category of typed attributed graphs (G , D) and typed attributed graph morphisms (fG , fD ) consistent w.r.t. SD over an attributed type graph ATG H. Ehrig, U. Prange, K. Ehrig ()
3
kind
noOfPars
Let DSIG = (SD , OPD ) be a data signature with SD ⊆ SD . Attributed graph AG = (G , D) is E-graph G and DSIG -algebra D with s∈SD
in
parameterDirectionKind
return
VD
p1
1
sourceNA
targetEA
58 / 73
par1
m
add
Type graph ATG :
VG
July 15, 2006
Tutorial on Graph Transformation
Tutorial on Graph Transformation
July 15, 2006
cname
Class
DSIG = CHAR + STRING + NAT + sorts : parameterDirectionKind opns : in, out, inout, return :→ parameterDirectionKind SD = {string , nat, parameterDirectionKind}
59 / 73
H. Ehrig, U. Prange, K. Ehrig ()
:type
par3 :Parameter kind=return
Tutorial on Graph Transformation
c:Class
:type
cname=Nat
July 15, 2006
60 / 73
Typed Attributed Graph Transformation
Theory for Typed AGT Systems Idea: Instantiation of theory for adhesive HLR systems
Definition
Theorem l
r
typed attributed graph production p = (L ← K → R) consists of typed attributed graphs L, K , R with common DSIG -termalgebra TDSIG (X ) with variables X , and l , r ∈ M, with M = {f = (fG , fD ) | fg injective, fD isomorphism of DSIG -algebras} direct typed attributed graph transforp,m mation G =⇒ H from G to H via the match m is given by the following double pushout diagram in AGraphsATG
L
l
K
r
R
m
(1)
k
(2)
n
G
f
D
g
H
(AGraphsATG , M) is an adhesive HLR category.
Corollary In AGraphsATG , the following results hold: Construction of typed attributed graph transformations, Embedding Theorem, Local Church-Rosser Theorem, Parallelism Theorem, Concurrency Theorem, Local Confluence Theorem.
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
61 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
Overview of Constraints and Application Conditions
Part VI
62 / 73
SKIP
Advanced Features and Conclusion Idea of graph constraints: Restriction of graphs / graph languages by existence or nonexistence of suitable graph patterns, called constraints c
30
Graph Constraints
31
Application Conditions
32
Typed AGT Systems with Inheritance
33
Modeling of Visual Languages
Idea of application conditions: p,m Restriction of direct graphs transformations G ⇒ H by suitable conditions for the match m (e.g. gluing condition)
34
Model Transformations
Theorem
35
Implementation of Typed AGT Systems in AGG
Construction of application condition acc for match m from graph constraint c such that H |= c if m |= acc.
36
Conclusion
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
63 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
64 / 73
Graph Constraints
Application Conditions
Problem: How to define graph constraints?
Problem: How to define application conditions?
Definition
Definition
atomic (typed) graph constraint is of form PC (a), where a : P → C is (typed) graph morphism
P
C
a
p = q (typed) graph constraint is Boolean formula over atomic (typed) graph constraints G G |= PC (a), if, for every injective morphism p : P → G , there exists injective morphism q : C → G such that q ◦ a = p. This can be extended to boolean formulas.
Example R
a
P
T
G satisfies this constraint if, for each resource node R, there is a turn variable that connects it to a process.
R C
P
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
65 / 73
atomic application condition over L is given by P(x, ∨i ∈I xi )
L
m |= P(x, ∨i ∈I xi ), if, for all injective m = p : X → G with p ◦ x = m, there exist i ∈ I and injective qi : Ci → G with G qi ◦ xi = p. This can be extended to boolean formulas. negative application condition NAC (x) is a L morphism x : L → X . A morphism m : L → G satisfies NAC (x) if there does not exist an injective p : X → G with p ◦ x = m.
H. Ehrig, U. Prange, K. Ehrig ()
Construction of Application Conditions
Definition
Theorem
application condition A(p) = (AL , AR ) for production p consists of left application condition AL over L and right application condition AR over R p,m
G ⇒ H with comatch n : R → H satisfies A(p) if m |= AL and n |= AR .
=
p
qi
x m
Ci
xi
X
= p| G
July 15, 2006
Tutorial on Graph Transformation
Productions with Application Conditions
X
x
66 / 73
For each graph constraint c for H, there is an equivalent right application condition racc for the comatch n. For each right application condition racc for comatch n, there is an equivalent left application condition lacc for match m. r l L K R
Example m
(1)
k
(2)
n
G
f
D
g
H
addResource with NAC (x): P x
active
H. Ehrig, U. Prange, K. Ehrig ()
P
P
Tutorial on Graph Transformation
P
T
July 15, 2006
R
67 / 73
H |= c, if m |= lacc.
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
68 / 73
Typed AGT Systems with Inheritance
Modeling of Visual Languages
{abstract} has
Screen
visible
Figure
Example
Bool
addTransition() [X={}] LHS
height width
RHS 1:StateMachine
id
NAC=RHS
Problem: How to handle inheritance?
x y
Circle
Generation of Statecharts by typed attributed graph grammar
radius width height
Nat
has id: Nat
Rectangle Screen
endx
width: Nat height: Nat
endy
x: Nat y: Nat visible: Bool
String
has id: Nat
:sm2conf :sm2step :from :to 2:Conf 3:Conf 4:Step
:conf2state
Conf
5:State Step
trigger
Line
Transition
trans2act
end cond2state
endx: Nat endy: Nat x: Nat y: Nat visible: Bool
Boolean
RHS 1:StateMachine
Cond
SC type graph
1:StateMachine
:sm2conf
:sm2conf :sm2step :to :from 2:Conf 3:Conf 4:Step :conf2state 5:State
:sm2conf
69 / 73
Model Transformation from Statecharts to Petri Nets ATGS
incS
ATG
incT
ATGT
typeS
typeGS
typeGi
typeGT
typeT
GS
...
pi
Gi
pj
SC type graph
StateMachine smname: String
:conf2state State
PreArc presrc
from Conf
trigger
Step to
conf2state
Event ename: String
step2trans begin
trans2act
:step2trans
:conf2state 5:State
Transition :end
July 15, 2006
70 / 73
Implementation of Typed AGT Systems in AGG Screenshot of SC 2PN Model Transformation
GT
pl
pretgt
Trans
Place plname: String token: Boolean
postsrc
act2event
stname: String end isInit: Boolean Transition
Tutorial on Graph Transformation
:to 3:Conf
4:Step
PN type graph
sm2step
sm2conf
State
...
pk
H. Ehrig, U. Prange, K. Ehrig ()
:sm2conf :sm2step
2:Conf :from
:begin
July 15, 2006
Tutorial on Graph Transformation
Transition :end
[X={}]
LHS
Action
NAC=RHS trans2cond
State
act2event
addTransitionLeftState()
begin
isInit
:conf2state
:step2trans
5:State
Event
:to 3:Conf
4:Step
:begin step2trans
conf2state
:sm2conf :sm2step
2:Conf :from
to String
State
H. Ehrig, U. Prange, K. Ehrig ()
Transition :end
:sm2conf
:conf2state
ename
from
width: Nat height: Nat x: Nat y: Nat visible: Bool
State
1:StateMachine
:sm2conf
sm2conf
stname
radius: Nat x: Nat y: Nat visible: Bool
:conf2state
:step2trans
RHS 1:StateMachine
sm2step
Rectangle
:to 3:Conf
4:Step
:begin
LHS
StateMachine
Circle
:sm2conf :sm2step
2:Conf :from
State
NAC=RHS
smname
has id: Nat
:sm2conf
addTransitionRightState() [X={}]
only in abstract closure
Line has id: Nat
:sm2conf :sm2step :from :to 2:Conf 3:Conf 4:Step
:conf2state
{abstract}
Figure
1:StateMachine
:sm2conf
posttgt
PostArc
Action
cond2state trans2cond Cond r1
r2
r3
r4
r5
r6
RefEvent
RefState
SC 2PN type graph ATG H. Ehrig, U. Prange, K. Ehrig ()
RefStep
Tutorial on Graph Transformation
July 15, 2006
71 / 73
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
72 / 73
Conclusion
Fundamental aspects of algebraic graph transformation: 1 Algebraic concept of graph transformation based on gluing construction and double pushouts. 2
Basic results concerning independence, parallelism, critical pairs.
3
Categorical framework of AHLR systems for unified constructions and proofs.
4
Typed attributed graph transformation for modeling of software systems, model transformations of visual languages.
H. Ehrig, U. Prange, K. Ehrig ()
Tutorial on Graph Transformation
July 15, 2006
73 / 73