Download presentation
Presentation is loading. Please wait.
1
Introduction to Graph Transformation
Kaminski, Seidl et al. Muscholl Estonian Summer School on Computer and Systems Science Lecture 1 Arend Rensink, University of Twente
2
Lectures & assignments
Introduction to Graph Transformation Some puzzles and games Graph-Based Operational Semantics Semantics of a small language Graph-Based Model Checking ESSCASS, 25 August 2008 Introduction to Graph Transformation
3
Introduction to Graph Transformation
What The verification question: Given a requirement (in some logic) Given a system model M (in some language that admits a semantic of the logic) Does M satisfy ? (notation: M ² ) In this course: Versions of temporal logic Safety: invariants, no exceptions thrown Liveness: termination, fairness Graph grammars as modelling language Model checking as basic technique ESSCASS, 25 August 2008 Introduction to Graph Transformation
4
Introduction to Graph Transformation
Why Why verification? Design/implementation-time sanity check (precedes testing in software development) But: integration in design process not easy (due to absence of models) Hence: software verification Why graph transformation? Graphs are natural for the domain Easier to grasp for non-specialist Captures dynamic states (heap, stack) ESSCASS, 25 August 2008 Introduction to Graph Transformation
5
Example: Circular buffer
Data structure module as subsystem Model the essence Structure captured by type graph (classes) Buffer cells linked in cycle Each cell may contain a value (an object) Pointers to first and last elements Further data invariants Instances captured by graphs Dynamics defined by operations E.g., insertion and deletion Captured by changes in graphs ESSCASS, 25 August 2008 Introduction to Graph Transformation
6
Introduction to Graph Transformation
Example type graph next val Cell Object 1 0..1 first last 1 1 Buffer Node for each type Labelled edge for each “property” Edge label = property name Possible: multiplicities These graphs are deterministic ESSCASS, 25 August 2008 Introduction to Graph Transformation
7
Example instance graph
Buffer Cell next last first Object val Snapshot of concrete data (on the heap) Four-cell buffer, of which 2 cells filled Type information & multiplicities satisfied There are many more invariant properties! ESSCASS, 25 August 2008 Introduction to Graph Transformation
8
Introduction to Graph Transformation
Graphs, formally Tuple <L,V,E> L: set of labels V: set of nodes (vertices) E µ V £ L £ V: set of binary, labelled edges No node labels (but self-edges mimic them) Example L = {Call, Object, next, val} V = {1, 2, 3} E = { (1,Cell,1), (2,Object,2), (3,Cell,3), (1,val,2), (1,next,3) } Choice of identities is irrelevant Cell next Object val 1 2 3 ESSCASS, 25 August 2008 Introduction to Graph Transformation
9
Introduction to Graph Transformation
Graph morphisms Consider G = <LG,VG,EG> and H = <LH,VH,EH> Morphisms f: G ! H functions fV: VG ! VH and fE: EG ! EH preserve structure: fE(v,a,w) = (fV(v), a, fV(w)) Isomorphism fV and fE are bijective Abstraction from node identities Partial morphism f does not have an image for all elements of G ESSCASS, 25 August 2008 Introduction to Graph Transformation
10
Typing: total morphism to type graph
1 2 3 6 5 7 4 Buffer Cell next last first Object val Source graph Type graph Buffer Cell next first Object val last 1 3 2 fV = { (1,3), (2,1), (3,1), (4,1), (5,1), (6,2), (7,2)} 1 0..1 1 1 Multiplicities not regarded ESSCASS, 25 August 2008 Introduction to Graph Transformation
11
Example invariant properties
The Cells of a Buffer form a cycle All Cells are connected to a Buffer Either first is pointing to a filled Cell, or the Buffer is empty (no Cells are filled) Either the next of a filled Cell is filled, or the Cell is the last If the next Cell is filled and it is not the first, then this Cell is also filled No Objects are shared between Cells (?) ESSCASS, 25 August 2008 Introduction to Graph Transformation
12
Data structure operations
What does a “put” operation do? Move the last pointer to the next Cell Attach an Object to the (now) last Cell In this model, we create a fresh Object Only if this next Cell did not have a val yet! What does a “get” operation do? Delete the val of the first Cell Move the first pointer to the next Cell Only if the first Cell had a val! What does an “extend” operation do? Insert a new Cell after the current last ESSCASS, 25 August 2008 Introduction to Graph Transformation
13
Graph transformations
The operations are graph changes These can be captured as changes What has to be removed What has to be added In addition: where in the host graph E.g., for “get”: (simultaneously) Identify b and c connected by a first edge Remove the val-edge and Object at c Remove the first edge pointing to c Add a first edge from b to the next w.r.t. c This constitutes a transformation rule ESSCASS, 25 August 2008 Introduction to Graph Transformation
14
Example production rule
Single-graph representation of <put> black = reader: to be matched and preserved red = embargo: forbidden Cell blue = eraser: to be matched and deleted last next Object val Buffer Cell last val Object green = creator: to be added ESSCASS, 25 August 2008 Introduction to Graph Transformation
15
Equivalent rule syntax
Single-graph: Buffer Cell Object next val last Multi-graph: Partial graph morphisms Negative Application Condition (NAC) Left Hand Side (LHS) Right Hand Side (RHS) Cell Object Cell Cell Object next next next last val last val last Buffer Cell Buffer Cell Buffer Cell ESSCASS, 25 August 2008 Introduction to Graph Transformation
16
Introduction to Graph Transformation
Production rules Partial morphism p: L R L \ dom(p): elements to be deleted R \ cod(p): elements to be added Non-injectivity (f(x)=f(y) for x y): merging Rule application to host graph G: Find total matching m: L G Multiple matchings are possible Subtract m-image of L from G Add R disjointly to result Partial morphisms h: G H, m’: R H ESSCASS, 25 August 2008 Introduction to Graph Transformation
17
Example rule application
Buffer Cell Object next val last matching Buffer Cell first | last next Object val Buffer Cell last first next Object val transition ESSCASS, 25 August 2008 Introduction to Graph Transformation
18
Transitions: Partial morphisms
1 cell filled 1 2 3 6 5 4 Buffer Cell next last first Object val fV = { (1,1), (2,2), (3,3), (4,4), (5,5), (6,6)} fE partial on edge (1,last,2) <put> 1 2 3 6 5 7 4 Buffer Cell next last first Object val <get> fV = { (1,1), (2,5), (3,2), (4,3), (5,4), (7,6)} fV partial on node 6 fE partial on several edges 2 cells filled ESSCASS, 25 August 2008 Introduction to Graph Transformation
19
Negative application conditions
Here the rule should not be applicable! Buffer Cell next last Object val NAC LHS RHS n Buffer Cell next last Object val Cell next last Buffer Cell g m How to rule out this matching? G There exists a total morphism g: NAC G such that m = g n (g factors m through n) Buffer Cell next last first Object val ESSCASS, 25 August 2008 Introduction to Graph Transformation
20
Introduction to Graph Transformation
Kinds of NACs Merge embargoes: force injectivity Non-injective morphism n: LHS NAC n(v1) = n(v2) rules out m(v1) = m(v2); hence v1 and v2 must be matched injectively Edge embargoes: forbid edges Edge not in image of n: LHS NAC (v1,lab,v2) LHS and (n(v1),lab,n(v2)) NAC imply (m(v1),lab,m(v2)) G General NACs: forbid larger subgraphs Multiple NACs per rule ESSCASS, 25 August 2008 Introduction to Graph Transformation
21
Introduction to Graph Transformation
Graph Productions Production rule NAC NACs LHS RHS rule morphism (partial) source graph matching target graph pushout forbidden Graph transition src(t) tgt(t) morph(t) (SPO = Single Pushout Approach) ESSCASS, 25 August 2008 Introduction to Graph Transformation
22
Example production rule (again)
Single-graph representation of <put> black = reader: LHS and RHS; to be matched and preserved black = reader: to be matched and preserved red = embargo: NAC, not LHS; forbidden red = embargo: forbidden blue = eraser: LHS, not RHS; to be matched and deleted Cell blue = eraser: to be matched and deleted last next Object val Buffer Cell last val green = creator: RHS, not LHS; to be added Object green = creator: to be added ESSCASS, 25 August 2008 Introduction to Graph Transformation
23
Introduction to Graph Transformation
Graphs as states Every graph represents a snapshot State of the system Every rule application changes the graph Transition of the system Together form a state/transition system Captures the system behaviour Basis for verification Exercise: state space of a 4-cell buffer No “extend” operations Will “put-get” return to the same graph? ESSCASS, 25 August 2008 Introduction to Graph Transformation
24
Graph transition system
Buffer Cell next first, last Object val <put> <get> <put> <get> Buffer Cell next first last Buffer Cell next last first Object val The states grow The size of states is unbounded The number of states is potentially infinite Morphisms are not inverse This is SPO; a similar situation holds after DPO Buffer Cell next last first Object val <put> <get> Buffer Cell next last first Object val <put> <get> ESSCASS, 25 August 2008 Introduction to Graph Transformation
25
Introduction to Graph Transformation
GROOVE Demo ESSCASS, 25 August 2008 Introduction to Graph Transformation
26
Example rule application
Buffer Cell next last 3 2 1 Buffer Cell next last Object val 4 5 6 7 R p (1,4), (2,5), (3,6) m m’ (1,1), (2,2), (3,3) (4,1), (5,2), (6,3), (7,7) G 1 2 3 6 5 7 4 Buffer Cell next last first Object val H 1 2 3 6 5 4 Buffer Cell next last first Object val h (1,1), (2,2), (3,3), (4,4), (5,5) (6,6) General requirement: h m = m’ p ESSCASS, 25 August 2008 Introduction to Graph Transformation
27
Rule application: variation 1
Buffer Cell next last 3 2 1 Buffer Cell next last Object val 4 5 6 7 R p (1,4), (2,5), (3,6) m m’ (1,1), (2,2), (3,3) (4,2), (5,5), (6,1), (7,9) G 2 5 1 4 3 9 8 Buffer Cell next last first Object val H’ 1 2 3 6 5 4 Buffer Cell next last first Object val h (1,2), (2,5), (3,1), (4,8), (5,3) (6,4) Also correct: H H’ ESSCASS, 25 August 2008 Introduction to Graph Transformation
28
Rule application: variation 2
Buffer Cell next last 3 2 1 Buffer Cell next last Object val 4 5 6 7 R p (1,4), (2,5), (3,6) m m’ (1,1), (2,2), (3,3) (4,1), (5,2), (6,3) G 1 2 3 6 5 4 Buffer Cell next last first Object val 2 H Cell next next h first 3 Cell 1 Buffer Cell last 5 4 next next Cell Object 6 val (1,1), (2,2), (3,3), (4,4), (5,5) What’s wrong? h m = m’ p fulfilled! ESSCASS, 25 August 2008 Introduction to Graph Transformation
29
Criteria for the target graph
Should be the “minimal complete” one Complete: elements kept when possible Minimal: no spurious elements Universal property: Pushout Minimal because it’s “smaller” than the others Complete because the subdiagrams commute matching (m) rule (p) diagram commutes (hm = m’p) that’s the one! wrong alternative ESSCASS, 25 August 2008 Introduction to Graph Transformation
30
Introduction to Graph Transformation
Example pushouts B A b 1 2 1 C A c 2 B A b 1 2 1 C A c 3 A a 1 2 1 A 2 (1,4),(2,5) (1,4),(2,5) (1,4),(2,5) B A b 4 5 6 a C A c 4 5 B 6 b a B A b 4 5 6 a C A c 4 7 B 6 b A B b 4 5 B A b 4 5 a A x 1 2 3 y A 1 2 3 x,y A a 1 2 1 C A c 2 A a 1 2 1 C A c 3 (1,4),(2,4) (1,4),(2,4) B A b 4 5 a B C b 4 5 c B A b 4 5 a B C 6 5 (1,4),(2,5),(3,5) A 4 5 x,y A 4 5 x,y Lessons: - Pushouts always exist - Leave no dangling edges - Deletion always wins x-edge not mapped! ESSCASS, 25 August 2008 Introduction to Graph Transformation
31
Principles of SPO transformation
What happens upon node deletion All incident edges are deleted What happens upon node merging Incident edges are copied to merged nodes What happens for non-injective matches Node deletion wins over preservation Edge creation wins over deletion ESSCASS, 25 August 2008 Introduction to Graph Transformation
32
Assignment A: Hands-On
Download GROOVE sf.net/projects/groove Model the following games/puzzles: Wolf-Goat-Cabbage (WGC) Solitaire Pacman Ludo (see course notes) (Answers are available as downloads) Specify properties of WGC Type graphs Invariants ESSCASS, 25 August 2008 Introduction to Graph Transformation
33
Introduction to Graph Transformation
Seen today Graphs and morphisms Graphs: Tuples of nodes, labels, edges Morphisms: node and edge mappings State invariants as graph properties Graph transformation rules Single-graph and multi-graph representation Rule applications as pushouts Negative application conditions GROOVE tool State space generation Graphs as states Graph productions as transitions ESSCASS, 25 August 2008 Introduction to Graph Transformation
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.