Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "© Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 2.5 Graph Grammars."— Presentation transcript:

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

2 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 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

3 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 3 Graph Grammars06.12.2012 Graph Grammars Example Describing program states as graphs Describing program behavior through graph transformations Models and graphs Graph grammars Story diagrams

4 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 4 Graph Grammars06.12.2012 Example: Graph Grammars in every day life Most children know graph grammars Every Lego build instruction is a graph grammar

5 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 5 Graph Grammars Example Example: simulation of a track-based transportation system :Shuttle:Track :Switch:Track next :Shuttle turnNext Concrete syntax: Abstract syntax: isOn 06.12.2012

6 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 6 Graph Grammars06.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 :Switch:Track next :Shuttle turnNext isOn

7 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 7 Graph Grammars06.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 :Switch:Track next :Shuttle turnNext isOn Example: Moving a shuttle

8 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 8 Graph Grammars06.12.2012 Object Graph The program behavior can be described by rules for transforming the object graph :Shuttle:Track :Switch:Track next :Shuttle turnNext isOn :Shuttle:Track next isOn move >

9 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 9 Graph Grammars06.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 next isOn move >

10 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 10 Graph Grammars06.12.2012 Graph Grammars Example Describing program states as graphs Describing program behavior through graph transformations Models and graphs Graph grammars Story diagrams

11 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 11 Graph Grammars06.12.2012 Instance Model and Class Model :Shuttle :Track :Switch :Track next :Shuttle turnNext isOn TrackShuttle isOn 1..1 Switch next 0..1 turnNext Class Diagram: Object graph:

12 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 12 Graph Grammars06.12.2012 Instance Model and Class Model Shuttle isOn 1..1 Switch next 0..1 turnNext Track :Shuttle :Track :Switch :Track next :Shuttle turnNext isOn Class Diagram: Object graph:Typed Graph Type Graph (edges are typed, too)

13 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 13 Graph Grammars06.12.2012 Graph Grammars Example Describing program states as graphs Describing program behavior through graph transformations Models and graphs Graph grammars Story diagrams

14 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 14 Graph Grammars06.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 > isOn :Track isOn > :Track next :Shuttle isOn next

15 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 15 Graph Grammars06.12.2012 Graph Grammar Rule A graph grammar rule consists of A left-hand side and right-hand side typed graph move :Shuttle :Track :Shuttle :Track Short hand form: lhs: rhs: ::= v1 v2 v3 next isOn v1 v2 v3 :Shuttle move :Track > isOn :Track isOn > identifier next

16 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 16 Graph Grammars06.12.2012 Graph Grammar Rule A graph grammar rule consists of A left-hand side and right-hand side typed graph move :Shuttle :Track :Shuttle :Track lhs: rhs: ::= v1 v2 v3 next isOn v1 v2 v3 TrackShuttle isOn 1 Switch next 1 turnNext (edges are typed, too) 1

17 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 17 Graph Grammars06.12.2012 Graph Grammar Rule Application move :Shuttle :Track :Shuttle :Track lhs: rhs: ::= :Shuttle:Track :Switch:Track next :Shuttle turnNext isOn next isOn v1 v2 v3v1 v2 v3

18 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 18 Graph Grammars06.12.2012 Graph Grammar Rule Application move :Shuttle :Track :Shuttle :Track lhs: rhs: ::= :Shuttle:Track :Switch:Track next :Shuttle turnNext isOn next isOn 1. Match lhs in host graph v1 v2 v3v1 v2 v3

19 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 19 Graph Grammars06.12.2012 Graph Grammar Rule Application move :Shuttle :Track :Shuttle :Track lhs: rhs: ::= :Shuttle:Track :Switch:Track next :Shuttle turnNext isOn next isOn v1 v2 v3v1 v2 v3 2. Remove nodes and edges which are in lhs, but not in rhs

20 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 20 Graph Grammars06.12.2012 Graph Grammar Rule Application move :Shuttle :Track :Shuttle :Track lhs: rhs: ::= :Shuttle:Track :Switch:Track next :Shuttle turnNext isOn next isOn 3. Create nodes and edges which are in rhs, but not in lhs v1 v2 v3v1 v2 v3

21 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 21 Graph Grammars06.12.2012 Non-Determinism Example 1: When to move which shuttle? Not determined! move :Shuttle :Track :Shuttle :Track lhs: rhs: ::= isOn next isOn v1 v2 v3v1 v2 v3 :Shuttle:Track next isOn :Shuttle:Track next isOn

22 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 22 Graph Grammars06.12.2012 Non-Determinism Example 2: Go straight or turn? Not determined! :Switch:Track next :Shuttle turnNext isOn :Shuttle move :Track > isOn :Track isOn > :Shuttle turn :Track > isOn :Switch isOn > nextturnNext TrackShuttle isOn 1 Switch next 1 turnNext (remember: a switch is also a track) 1

23 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 23 Graph Grammars06.12.2012 Negative Application Conditions Example: Do not crash with other shuttle :Shuttle move :Track > isOn :Track isOn > next :Shuttle :Track next isOn :Shuttle:Track next isOn

24 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 24 Graph Grammars06.12.2012 Attribute Condition Example 1: A broken shuttle cannot move move :Shuttle :Track > isOn :Track isOn > next failure=false Shuttle isOn 1 Switch next 1 turnNext Track failure: boolean 1

25 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 25 Graph Grammars06.12.2012 Attribute Condition Example 2: May follow faster shuttles on Track move s1:Shuttle :Track > isOn :Track isOn > next isOn speed s2.speed Shuttle isOn 1 Switch next 1 turnNext Track broken: boolean speed: integer s2:Shuttle 1

26 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 26 Graph Grammars06.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…

27 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 27 Graph Grammars06.12.2012 Definition: Directed Graph G = (V, E, s, t) V – finite set of nodes (vertices) E – finite set of edges s: EV – source function t: EV – target function v2v1 v3 e3 e2 e1 Example: V = {v1, v2, v3} E = {e1, e2, e3} s(e1) = v1 t(e1) = v2

28 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 28 Graph Grammars06.12.2012 Definition: Labeled Graph G L = (G,L V, L E ) G – Directed Graph L V : V – labeling function for vertices L E : E – labeling function for edges – set of labels v2 v1 e1 Example: V = {v1, v2} E = {e1} s(e1) = v1 t(e1) = v2 track shuttle isOn L V (v1) = shuttle L V (v2) = track L E (e1) = isOn

29 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 29 Graph Grammars06.12.2012 Definition: Morphism Given two graphs G i =(V i,E i,s i,t i ), i {1, 2} A graph morphism f: G 1 G 2, f = (f V, f E ) consists of two functions f V : V 1 V 2 f E : E 1 E 2 preserving the source and target functions: f V s 1 = s 2 f E and f V t 1 = t 2 f E :Shuttle:Track isOn ShuttleTrack isOn G2:G2: G1:G1: v1 1 v2 1 v1 2 v2 2 == e1 2 e1 1 Given two functions f and g then f g is a function that maps a value x to f(g(x))

30 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 30 Graph Grammars06.12.2012 Definition: Morphism Given two graphs G i =(V i,E i,s i,t i ), i {1, 2} A graph morphism f: G 1 G 2, f = (f V, f E ) consists of two functions f V : V 1 V 2 f E : E 1 E 2 preserving the source and target functions: f V s 1 = s 2 f E and f V t 1 = t 2 f E :Shuttle:Track isOn ShuttleTrack isOn G2:G2: G1:G1: v1 1 v2 1 v1 2 v2 2 == e1 2 e1 1 Example: f V (s 1 (e1 1 )) = s 2 (f E (e1 1 )) f V (t 1 (e1 1 )) = t 2 (f E (e1 1 ))

31 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 31 Graph Grammars06.12.2012 Definition: Typed Graph A Typed Graph G Typed = (G, type) consists of a graph G and a graph morphism to a type graph type: G G Type Shuttle isOn 1 Switch next 1 turnNext Track :Shuttle:Track :Switch :Track next :Shuttle turnNext isOn Typed Graph Type Graph Note: A morphism is a total function (f V, f E are total), i.e. every element in the domain (typed graph) has to be related to exactly one element of the co-domain (type graph) 1

32 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 32 Graph Grammars06.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 lhs: ::= … :Shuttle:Track next isOn next v1 v2 v3 :Track next subgraph isomorphism

33 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 33 Graph Grammars06.12.2012 Definition: Subgraph A subgraph G Sub = (V Sub, E Sub, s Sub, t Sub ) of G= (V, E, s, t) is a graph with V Sub V E Sub E s Sub = s t Sub = t If G Sub is a subgraph of G, we may also write G Sub G. Means that the domain of the source and target function for the subgraph is reduced to the edges which are in it. E Sub

34 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 34 Graph Grammars06.12.2012 Definition: Isomorphism A graph morphism f: G1G2, f = (f V, f E ) with f V, f E bijective is called a graph isomorphism. :Shuttle :Track lhs: ::= … :Shuttle:Track next isOn next v1 v2 v3 :Track next subgraph isomorphism

35 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 35 Graph Grammars06.12.2012 Definition: Typed Isomorphism Both the graph and host graph are typed over the same type Graph G Type : Let type = (type V, type E ) be a graph morphism and f = (f V, f E ) is an isomorphism, then f is a typed isomorphism when type V (v) = type V (f V (v)) type E (e) = type E (f E (e)) :Track next Track next 1

36 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 36 Graph Grammars06.12.2012 Definition: Graph Grammar Rule A graph grammar rule r is defined as a partial morphism r : LR with L G Type the lhs graph of r, R G Type the rhs graph of r, G Type the set of all graphs typed over G Type such that there is a maximum common subgraph TL of L and R, with: TL G Type : TL L and TL R and TL not empty

37 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 37 Graph Grammars06.12.2012 Definition: Graph Grammar Rule :Shuttle :Track :Shuttle :Track L (lhs graph) isOn next isOn v1 v2 v3 v1 v2 v3 R (rhs graph) :Shuttle :Track next v1 v2 v3 TL (common subgraph) partial morphism r : LR

38 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 38 Graph Grammars06.12.2012 Rule Application - Formally The application of a rule r: LR is defined by a relation app r = { (G, G) ( G Type x G Type ) | G is defined by the three steps 1.Search (on host graph G) 2.Delete (result is G) 3.Create (result is G) or G = G } app r represents all possible applications of r G Type An element is a possible (host) graph typed over G Type

39 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 39 Graph Grammars06.12.2012 Rule Application – Step 1 Search: Given a host graph G, find a subgraph isomorphism match: LG Sub, G Sub G :Shuttle :Track ::= … :Shuttle :Track next isOn next v1 v2 v3 :Track next Subgraph G Sub isomorphism L (lhs)

40 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 40 Graph Grammars06.12.2012 Rule Application – Step 2 (1/3) 2.Delete: Form a new graph G from G by deleting all nodes and edges in G Sub which are in match(L) = G Sub but not in G Sub = match(TL) ( G Sub ) :Shuttle :Track next isOn :Track next G Sub :Shuttle :Track isOn next v1 v2 v3 L (lhs) :Shuttle :Track next v1 v2 v3 TL (common subgraph) (Only the edge labeled isOn is removed)

41 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 41 Graph Grammars06.12.2012 Rule Application – Step 2 (2/3) Delete: Remove all edges leading to deleted nodes createAssignment :Customer :Broker :Shuttle :Request created queuedRequest respFor :Broker :Shuttle :Request queuedRequest respFor :Assignment assigned :Broker :Shuttle :Request queuedRequest respFor L (lhs) :Broker :Shuttle respFor TL (common subgraph) > assignment >

42 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 42 Graph Grammars06.12.2012 Rule Application – Step 2 (2/3) Delete: Remove all edges leading to deleted nodes createAssignment :Customer :Broker :Shuttle created respFor :Broker :Shuttle :Request queuedRequest respFor :Assignment assigned :Broker :Shuttle :Request queuedRequest respFor L (lhs) :Broker :Shuttle respFor TL (common subgraph) > assignment >

43 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 43 Graph Grammars06.12.2012 Rule Application – Step 2 (3/3) Delete: Remove all edges leading to deleted nodes createAssignment :Customer :Broker :Shuttle respFor :Broker :Shuttle :Request queuedRequest respFor :Assignment assigned :Broker :Shuttle :Request queuedRequest respFor L (lhs) :Broker :Shuttle respFor TL (common subgraph) > assignment >

44 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 44 Graph Grammars06.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 match R : R G Sub from R to a new subgraph G Sub G such that (G Sub =) match(TL) match R (R) (= G Sub )

45 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 45 Graph Grammars06.12.2012 Rule Application – Step 3 (2/3) Create: G Sub = match(TL) match R (R) = G Sub :Shuttle :Track next :Track next G Sub :Shuttle :Track next v1 v2 v3 TL (common subgraph) :Shuttle :Track next v1 v2 v3 isOn R (lhs)

46 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 46 Graph Grammars06.12.2012 Rule Application – Step 3 (3/3) Create: G Sub = match(TL) match R (R) = G Sub :Customer :Broker :Shuttle respFor :Broker :Shuttle respFor TL (common subgraph) :Broker :Shuttle respFor :Assignment assigned :Assignment R (lhs) G Sub assignment assigned assignment

47 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 47 Graph Grammars06.12.2012 Rule Application - Formally The application of a rule r: LR is defined by a relation app r = { (G, G) ( G Type x G Type ) | G is defined by the three steps 1.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) app r where G is the host graph before applying the rule and G is the host graph after rule application. G Type

48 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 48 Graph Grammars06.12.2012 What about Inheritance? G Type = (G L, I) G L – 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) = v1 t(e1) = v2 I = {(v2, v3)} But now the formalization of the matching becomes more complicated…

49 © Fachgebiet Softwaretechnik, Heinz Nixdorf Institut, Universität Paderborn 49 Graph Grammars06.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 next isOn move >


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

Similar presentations


Ads by Google