© Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

49
© Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars

Transcript of © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

Page 1: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

2.5 Graph Grammars

Page 2: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

2

Organisatorisches

Klausurtermin: Fr, 22.02.2013 Voraussichtlich 11:00 Uhr

Hinweis: Es gibt nur einen Klausurtermin! Mögliche Konflikte bis 14.12.2012 an Uwe Pohlmann

(upohl (at) upb.de) melden.

06.12.2012Graph Grammars

Page 3: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

3Graph Grammars 06.12.2012

Graph Grammars

Example Describing program states as graphs Describing program behavior through graph transformations

Models and graphs Graph grammars Story diagrams

Page 4: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

4Graph Grammars 06.12.2012

Example: Graph Grammars in every day life Most children know graph grammars Every Lego build instruction is a

graph grammar

Page 5: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

5Graph Grammars

Example

Example: simulation of a track-based transportation system

:Shuttle

:Track :Track :Switch

:Track

:Tracknext nextnext

:Shuttle

turnNext

Concrete syntax:

Abstract syntax:

isOn

isOn

06.12.2012

Page 6: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

6Graph Grammars 06.12.2012

Object Graph

The object graph represents the state of a program The behavior of a program is a change of the state

A change of the object graph

:Shuttle

:Track :Track :Switch

:Track

:Tracknext nextnext

:Shuttle

turnNext

isOn

isOn

Page 7: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

7Graph Grammars 06.12.2012

Object Graph

The object graph represents the state of a program The behavior of a program is a change of the state

A change of the object graph

:Shuttle

:Track :Track :Switch

:Track

:Tracknext nextnext

:Shuttle

turnNextisOn

isOn

isOn

Example: Moving a shuttle

Page 8: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

8Graph Grammars 06.12.2012

Object Graph

The program behavior can be described by rules for transforming the object graph

:Shuttle

:Track :Track :Switch

:Track

:Tracknext nextnext

:Shuttle

turnNext

isOn

isOn

:Shuttle

:Track :Tracknext

isOnisOn

move

<<delete>>

<<create>>

Page 9: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

9Graph Grammars 06.12.2012

Motivation

Graph transformation rules allow us: To describe the behavior of systems in an abstract way

(e.g. RailCab)• To model and analyze them

To describe the semantics of pointer programs (OO)• To validate or verify them• To model the program behavior visually (Executable code can be

generated from them)

:Shuttle

:Track :Tracknext

isOnisOn

move

<<delete>>

<<create>>

Page 10: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

10Graph Grammars 06.12.2012

Graph Grammars

Example Describing program states as graphs Describing program behavior through graph transformations

Models and graphs Graph grammars Story diagrams

Page 11: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

11Graph Grammars 06.12.2012

Instance Model and Class Model

:Shuttle

:Track :Track :Switch

:Track

:Tracknext nextnext

:Shuttle

turnNext

isOn

isOn

TrackShuttle isOn

1..1

Switch

next

0..1turnNext

Class Diagram:

Object graph:

Page 12: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

12Graph Grammars 06.12.2012

Instance Model and Class Model

Shuttle isOn

1..1

Switch

next

0..1turnNext

Track

:Shuttle

:Track :Track :Switch

:Track

:Tracknext nextnext

:Shuttle

turnNext

isOn

isOn

Class Diagram:

Object graph: Typed Graph

Type Graph

(edges are typed, too)

Page 13: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

13Graph Grammars 06.12.2012

Graph Grammars

Example Describing program states as graphs Describing program behavior through graph transformations

Models and graphs Graph grammars Story diagrams

Page 14: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

14Graph Grammars 06.12.2012

Graph Grammars

A graph grammar consists of A set of graph grammar rules (production rules) A start graph A type graph

A graph grammar describes how to produce valid sets of graphs (sets may be infinite)

Synonyms: Graph Rewriting System or Graph Transformation System

:Track

start graph

:Shuttle

rule: move

:Track

<<create>>

isOn

:Track

isOn<<delete>>

:Track

:Track :Track

next

next

next

next:Shuttle isOn

next

Page 15: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

15Graph Grammars 06.12.2012

Graph Grammar Rule

A graph grammar rule consists of A left-hand side and right-hand side typed graph

move

:Shuttle

:Track:Track

:Shuttle

:Track:Track

Short hand form:

lhs: rhs:

::=

v1

v2

v3 nextnext

isOn isOn

v1

v2

v3

:Shuttle

move

:Track

<<create>>

isOn

:Track

isOn<<delete>>

identifier

next

Page 16: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

16Graph Grammars 06.12.2012

Graph Grammar Rule

A graph grammar rule consists of A left-hand side and right-hand side typed graph

move

:Shuttle

:Track:Track

:Shuttle

:Track:Track

lhs: rhs:

::=

v1

v2

v3 nextnext

isOn isOn

v1

v2

v3

TrackShuttle isOn

1

Switch

next

1turnNext

(edges are typed, too)

1

Page 17: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

17Graph Grammars 06.12.2012

Graph Grammar Rule Application

move

:Shuttle

:Track:Track

:Shuttle

:Track:Track

lhs: rhs:

::=

:Shuttle

:Track :Track :Switch

:Track

:Tracknext nextnext

:Shuttle

turnNext

isOn

isOn

isOn

next next

isOn

v1

v2

v3 v1

v2

v3

Page 18: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

18Graph Grammars 06.12.2012

Graph Grammar Rule Application

move

:Shuttle

:Track:Track

:Shuttle

:Track:Track

lhs: rhs:

::=

:Shuttle

:Track :Track :Switch

:Track

:Tracknext nextnext

:Shuttle

turnNext

isOn

isOn

isOn

next next

isOn

1. Match lhs in host graph

v1

v2

v3 v1

v2

v3

Page 19: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

19Graph Grammars 06.12.2012

Graph Grammar Rule Application

move

:Shuttle

:Track:Track

:Shuttle

:Track:Track

lhs: rhs:

::=

:Shuttle

:Track :Track :Switch

:Track

:Tracknext nextnext

:Shuttle

turnNext

isOn

isOn

isOn

next next

isOn

v1

v2

v3 v1

v2

v3

2. Remove nodes and edges which are in lhs, but not in rhs

Page 20: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

20Graph Grammars 06.12.2012

Graph Grammar Rule Application

move

:Shuttle

:Track:Track

:Shuttle

:Track:Track

lhs: rhs:

::=

:Shuttle

:Track :Track :Switch

:Track

:Tracknext nextnext

:Shuttle

turnNext

isOn

isOn

isOn

next next

isOn

3. Create nodes and edges which are in rhs, but not in lhs

v1

v2

v3 v1

v2

v3

Page 21: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

21Graph Grammars 06.12.2012

Non-Determinism

Example 1: When to move which shuttle? Not determined!

move

:Shuttle

:Track:Track

:Shuttle

:Track:Track

lhs: rhs:

::=isOn

next next

isOn

v1

v2

v3 v1

v2

v3

:Shuttle

:Track :Tracknext next

isOn

:Shuttle

:Track :Tracknext

isOn

Page 22: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

22Graph Grammars 06.12.2012

Non-Determinism

Example 2: Go straight or turn? Not determined!

:Switch

:Track

:Track

next

:Shuttle

turnNext

isOn

:Shuttle

move

:Track

<<create>>

isOn

:Track

isOn<<delete>>

:Shuttle

turn

:Track

<<create>>

isOn

:Switch

isOn<<delete>>

next turnNext

TrackShuttle isOn

1

Switch

next

1turnNext(remember:

a switch is also a track)

1

Page 23: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

23Graph Grammars 06.12.2012

Negative Application Conditions Example: Do not crash with other shuttle

:Shuttle

move

:Track

<<create>>

isOn

:Track

isOn<<delete>>

next

:Shuttle

:Shuttle

:Track :Tracknext next

isOn

:Shuttle

:Track :Tracknext

isOn

isOn

Page 24: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

24Graph Grammars 06.12.2012

Attribute Condition

Example 1: A broken shuttle cannot move

move

:Shuttle

:Track

<<create>>

isOn

:Track

isOn<<delete>>

next

failure=false

Shuttle isOn

1

Switch

next

1turnNext

Track

failure: boolean

1

Page 25: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

25Graph Grammars 06.12.2012

Attribute Condition

Example 2: May follow faster shuttles on Track

move

s1:Shuttle

:Track

<<create>>

isOn

:Track

isOn<<delete>>

next

isOn

speed ≤ s2.speed

Shuttle isOn

1

Switch

next

1turnNext

Track

broken: booleanspeed: integer

s2:Shuttle

1

Page 26: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

26Graph Grammars 06.12.2012

Graph Grammars: Overview

Non-deterministic rule application Negative application conditions Conditions on attribute values Inheritance in the type graph There may be other extensions depending on the problem

domain…• Ordered lists• Qualified associations• „maybe“-conditions

Now a bit more formally…

Page 27: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

27Graph Grammars 06.12.2012

Definition: Directed Graph

G = (V, E, s, t) V – finite set of nodes (vertices) E – finite set of edges s: E→V – source function t: E→V – target function

v2v1

v3

e3

e2

e1

Example:V = {v1, v2, v3}E = {e1, e2, e3}s(e1) = v1t(e1) = v2

Page 28: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

28Graph Grammars 06.12.2012

Definition: Labeled Graph

GL = (G,LV, LE)

G – Directed Graph LV: V →∑ – labeling function for vertices

LE: E →∑ – labeling function for edges

∑ – set of labels

v2

v1

e1

Example:V = {v1, v2}E = {e1}s(e1) = v1t(e1) = v2 track

shuttle

isOn

LV(v1) = “shuttle”LV(v2) = “track”LE(e1) = “isOn”

Page 29: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

29Graph Grammars 06.12.2012

Definition: Morphism

Given two graphs Gi=(Vi,Ei,si,ti), i ∈ {1, 2}

A graph morphism f: G1→G2, f = (fV , fE)

consists of two functions fV: V1 → V2

fE : E1 → E2

preserving the source and target functions: fV ◦ s1 = s2 ◦ fE and fV ◦ t1 = t2 ◦ fE

:Shuttle :Track

isOn

Shuttle TrackisOnG2:

G1:v11 v21

v12 v22

= =

e12

e11

Given two functions f

and g then f ◦ g is afunction that mapsa value x to f(g(x))

Page 30: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

30Graph Grammars 06.12.2012

Definition: Morphism

Given two graphs Gi=(Vi,Ei,si,ti), i ∈ {1, 2}

A graph morphism f: G1→G2, f = (fV , fE)

consists of two functions fV: V1 → V2

fE : E1 → E2

preserving the source and target functions: fV ◦ s1 = s2 ◦ fE and fV ◦ t1 = t2 ◦ fE

:Shuttle :Track

isOn

Shuttle TrackisOnG2:

G1:v11 v21

v12 v22

= =

e12

e11

Example:fV(s1(e11)) = s2(fE(e11))fV(t1(e11)) = t2(fE(e11))

Page 31: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

31Graph Grammars 06.12.2012

Definition: Typed Graph

A Typed Graph GTyped = (G, type) consists of a graph G and a graph morphism to a type graph type: G → GType

Shuttle isOn

1

Switch

next

1turnNext

Track

:Shuttle

:Track :Track :Switch

:Track

:Tracknext next next

:Shuttle

turnNextisOn

isOn

Typed Graph

Type Graph

Note:A morphism is a total function (fV, fE are total), i.e. every element in the domain (typed graph) has to be related to exactly one element of theco-domain (type graph)

1

Page 32: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

32Graph Grammars 06.12.2012

Matching a Left-hand Side

Matching a graph inside another “host” graph Find a typed isomorphism to a subgraph of the host graph

:Shuttle

:Track:Track

lhs:

::= …

:Shuttle

:Track :Tracknext next

isOn

isOn

nextv1

v2

v3

:Track:Track next

subgraph

isomorphism

Page 33: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

33Graph Grammars 06.12.2012

Definition: Subgraph

A subgraph GSub = (VSub, ESub, sSub, tSub) of G= (V, E, s, t) is a graph with VSub V

ESub E

sSub = s

tSub = t

If GSub is a subgraph of G, we may also write GSub G.

Means that the domain of the source and target function for the subgraph is reduced to the edges which are in it.

ESub

ESub

Page 34: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

34Graph Grammars 06.12.2012

Definition: Isomorphism

A graph morphism f: G1→G2, f = (fV , fE) with

fV, fE bijective is called a graph isomorphism.

:Shuttle

:Track:Track

lhs:

::= …

:Shuttle

:Track :Tracknext next

isOn

isOn

nextv1

v2

v3

:Track:Track next

subgraph

isomorphism

Page 35: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

35Graph Grammars 06.12.2012

Definition: Typed Isomorphism Both the graph and host graph are typed over the same

type Graph GType:

Let type = (typeV, typeE) be a graph morphism and

f = (fV, fE) is an isomorphism, then f is a typed isomorphism when

• typeV(v) = typeV(fV(v))

• typeE(e) = typeE(fE(e))

:Track:Track

:Track :Tracknext

next

Track

next

1

Page 36: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

36Graph Grammars 06.12.2012

Definition: Graph Grammar Rule A graph grammar rule r is defined as a partial morphism r :

L→R with L GType the lhs graph of r, R GType the rhs graph of r, GType the set of all graphs typed over GType such that there is a maximum common subgraph TL of L and R, with: TL GType : TL L and TL R and

TL not empty

Page 37: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

37Graph Grammars 06.12.2012

Definition: Graph Grammar Rule

:Shuttle

:Track:Track

:Shuttle

:Track:Track

L(lhs graph) isOn

next next

isOn

v1

v2

v3 v1

v2

v3

R(rhs graph)

:Shuttle

:Track:Tracknextv1

v2

v3

TL(common subgraph)

partial morphismr : L→R

Page 38: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

38Graph Grammars 06.12.2012

Rule Application - Formally

The application of a rule r: L→R is defined by a relation appr = { (G, G‘‘)(GType x GType) | G‘‘ is defined by the three steps1. Search (on host graph G)

2. Delete (result is G‘)

3. Create (result is G‘‘)

or G = G‘‘ }

appr represents all possible applications of r

GType

An element is a possible (host) graph typed over GType

Page 39: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

39Graph Grammars 06.12.2012

Rule Application – Step 1

Search: Given a host graph G, find a subgraph isomorphism match: L→GSub, GSub G

:Shuttle

:Track:Track

::= …

:Shuttle

:Track :Tracknext next

isOn

isOn

nextv1

v2

v3

:Track:Track next

Subgraph GSub

isomorphismL(lhs)

Page 40: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

40Graph Grammars 06.12.2012

Rule Application – Step 2 (1/3)

2. Delete: Form a new graph G‘ from G by deleting all nodes and edges in GSub which are in match(L) = GSub

but not in G‘Sub = match(TL) ( GSub)

:Shuttle

:Track :Tracknext next

isOn

:Track:Track next

GSub

:Shuttle

:Track:Track

isOn

nextv1

v2

v3

L(lhs)

:Shuttle

:Track:Tracknextv1

v2

v3

TL(common subgraph)

(Only the edge labeled “isOn” is removed)

Page 41: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

41Graph Grammars 06.12.2012

Rule Application – Step 2 (2/3)

Delete:Remove all edges leading to deleted nodes

createAssignment:Customer

:Broker

:Shuttle :Shuttle:Shuttle

:Requestcreated

queuedRequest

respForrespFor

respFor

:Broker :Shuttle

:Request

queuedRequest

respFor

:Assignment

assigned

:Broker :Shuttle

:Request

queuedRequest

respFor

L(lhs)

:Broker :ShuttlerespFor

TL(common subgraph)

<<delete>> <<create>>assignment<<create>>

Page 42: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

42Graph Grammars 06.12.2012

Rule Application – Step 2 (2/3)

Delete:Remove all edges leading to deleted nodes

createAssignment:Customer

:Broker

:Shuttle :Shuttle:Shuttle

created

respForrespFor

respFor

:Broker :Shuttle

:Request

queuedRequest

respFor

:Assignment

assigned

:Broker :Shuttle

:Request

queuedRequest

respFor

L(lhs)

:Broker :ShuttlerespFor

TL(common subgraph)

<<delete>> <<create>>assignment<<create>>

Page 43: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

43Graph Grammars 06.12.2012

Rule Application – Step 2 (3/3)

Delete:Remove all edges leading to deleted nodes

createAssignment:Customer

:Broker

:Shuttle :Shuttle:Shuttle

respForrespFor

respFor

:Broker :Shuttle

:Request

queuedRequest

respFor

:Assignment

assigned

:Broker :Shuttle

:Request

queuedRequest

respFor

L(lhs)

:Broker :ShuttlerespFor

TL(common subgraph)

<<delete>> <<create>>assignment<<create>>

Page 44: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

44Graph Grammars 06.12.2012

Rule Application – Step 3 (1/3)

Create:Add nodes and edges to G‘, forming an extended graph G‘‘, such that there is an isomorphism matchR: R → G‘‘Sub from R to a new subgraph G‘‘Sub G‘‘ such that(G‘Sub =) match(TL) matchR(R) (= G‘‘Sub)

Page 45: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

45Graph Grammars 06.12.2012

Rule Application – Step 3 (2/3)

Create: G‘Sub = match(TL) matchR(R) = G‘‘Sub

:Shuttle

:Track :Tracknext next :Track:Track next

G‘‘Sub

:Shuttle

:Track:Tracknextv1

v2

v3

TL(common subgraph)

:Shuttle

:Track:Tracknextv1

v2

v3

isOn

isOn

R(lhs)

Page 46: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

46Graph Grammars 06.12.2012

Rule Application – Step 3 (3/3)

Create:G‘Sub = match(TL) matchR(R) = G‘‘Sub

:Customer

:Broker

:Shuttle :Shuttle:Shuttle

respForrespFor

respFor

:Broker :ShuttlerespFor

TL(common subgraph)

:Broker :ShuttlerespFor

:Assignment

assigned

:Assignment

R(lhs)

G‘‘Sub

G‘Sub

assignment

assigned

assignment

Page 47: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

47Graph Grammars 06.12.2012

Rule Application - Formally

The application of a rule r: L→R is defined by a relation appr = { (G, G‘‘)(GType x GType) | G‘‘ is defined by the three steps1. Search (on host graph G)

2. Delete (result is G‘)

3. Create (result is G‘‘)

or G = G‘‘ }

A concrete rule application is repre-sented by a tuple (G, G‘‘) appr where G is the host graph before applying the rule and G‘‘ is the host graph after rule application.

GType

Page 48: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

48Graph Grammars 06.12.2012

What about Inheritance?

GType = (GL, I)

GL – Directed labeled Graph

I V x V – inheritance relation (cycle free)

v2v1

v3

e3

e2

e1

Example:V = {v1, v2, v3}E = {e1, e2, e3}s(e1) = v1t(e1) = v2I = {(v2, v3)}

But now the formalization of the matching becomes more complicated…

Page 49: © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars.

© F

achg

ebie

t S

oftw

aret

echn

ik,

Hei

nz N

ixdo

rf I

nstit

ut,

Uni

vers

ität

Pad

erbo

rn

49Graph Grammars 06.12.2012

Summary

Graph transformation rules allow us: To describe the behavior of systems (e.g. RailCab) in an

abstract, formal way• To model and analyze them

To describe the semantics of OO-programs• To validate or verify them• To model the program behavior visually (Executable code

can be generated from them)

:Shuttle

:Track :Tracknext

isOnisOn

move

<<delete>>

<<create>>