1 / 33

Introduction to Graph Transformation

Introduction to Graph Transformation. Estonian Summer School on Computer and Systems Science Lecture 1 Arend Rensink, University of Twente. Lectures & assignments. Introduction to Graph Transformation Some puzzles and games Graph-Based Operational Semantics Semantics of a small language

kanoa
Download Presentation

Introduction to Graph Transformation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Graph Transformation Estonian Summer School on Computer and Systems ScienceLecture 1Arend 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 Introduction to Graph Transformation

  3. 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 Introduction to Graph Transformation

  4. 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) 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 Introduction to Graph Transformation

  6. next val first last Example type graph • Node for each type • Labelled edge for each “property” • Edge label = property name • Possible: multiplicities • These graphs are deterministic Cell Object 1 0..1 1 1 Buffer Introduction to Graph Transformation

  7. Cell Object val next next first last Cell Buffer Cell Object val next next Cell Example instance graph • 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! Introduction to Graph Transformation

  8. val Cell Object next Cell 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 1 2 3 Introduction to Graph Transformation

  9. 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 Introduction to Graph Transformation

  10. 2 next 6 Cell Object val val next next first 3 last 5 1 7 Cell Buffer Cell Object first last val 4 next next Cell 1 2 Cell Object 3 Buffer Typing: total morphism to type graph Source graph Type graph fV = { (1,3), (2,1), (3,1), (4,1), (5,1), (6,2), (7,2)} 1 0..1 1 1 Multiplicities not regarded 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 nextCell is filled and it is not the first, then this Cell is also filled • No Objects are shared between Cells (?) 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) lastCell • In this model, we create a freshObject • Only if this nextCell did not have a val yet! • What does a “get” operation do? • Delete the val of the firstCell • Move the first pointer to the nextCell • Only if the firstCell had a val! • What does an “extend” operation do? • Insert a new Cell after the current last 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 Introduction to Graph Transformation

  14. Single-graph representation of <put> Example production rule 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 Introduction to Graph Transformation

  15. Cell next Object last val Cell Buffer Object val last Partial graph morphisms Equivalent rule syntax Single-graph: Multi-graph: 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 Cell Buffer Cell Buffer Buffer Cell Introduction to Graph Transformation

  16. 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 Rdisjointly to result • Partial morphisms h: G  H, m’: R  H Introduction to Graph Transformation

  17. Cell last next Buffer Object last val Cell val Object Object val matching Cell Object val Object next Cell first next next Buffer val last first | last next transition Cell Cell next Buffer Cell Cell next Example rule application Introduction to Graph Transformation

  18. 2 6 Cell Object 2 val 6 Cell Object next next val first 3 next next 5 1 7 Cell Buffer Cell Object first last 3 last val 5 1 Cell Buffer Cell 4 next 4 next <put> Cell next next Cell <get> Transitions: Partial morphisms 1 cell filled fV = { (1,1), (2,2), (3,3), (4,4), (5,5), (6,6)} fE partial on edge (1,last,2) 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 Introduction to Graph Transformation

  19. NAC Cell Object n next Cell Object val next last Buffer Cell val last Buffer Cell g val Cell Object next next first last Cell Buffer Cell Object val val next next Object Cell Object val Negative application conditions • Here the rule should not be applicable! LHS RHS Cell next last Cell Buffer m How to rule out this matching? G There exists a total morphism g: NAC  Gsuch that m = g  n (gfactorsm through n) Introduction to Graph Transformation

  20. Kinds of NACs • Merge embargoes: force injectivity • Non-injective morphism n: LHS  NAC • n(v1) = n(v2) rules out m(v1) = m(v2); hencev1and v2must 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))  NACimply(m(v1),lab,m(v2))  G • General NACs: forbid larger subgraphs • Multiple NACs per rule Introduction to Graph Transformation

  21. Production rule rule morphism LHS RHS NAC NAC (partial) NACs forbidden matching source graph morph(t) target graph src(t) tgt(t) Graph transition pushout Graph Productions (SPO = Single Pushout Approach) Introduction to Graph Transformation

  22. Single-graph representation of <put> Example production rule (again) 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 Introduction to Graph Transformation

  23. 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? Introduction to Graph Transformation

  24. val Cell Object next next first, last <put> Cell Buffer Cell <get> Cell <put> <get> next next Cell next next first last Cell Buffer Cell val Cell Object next next next next first Cell val last Cell Object Cell Buffer Cell Object val next next first val next next Cell Buffer Cell Object Object Cell Object val val last next <get> <put> next Cell Object val <get> <put> Cell Object val next next first last Cell Buffer Cell Object val next next Cell Graph transition system Introduction to Graph Transformation

  25. GROOVE Demo Introduction to Graph Transformation

  26. 2 Cell 5 7 Cell Object next last m’ 1 3 next Cell Buffer val last 4 6 Buffer Cell H h 2 2 Cell Object Cell Object val val 6 6 next next next next first last first 3 3 1 1 Cell Buffer Cell Cell Buffer Cell Object last val 5 5 7 4 4 next next next next Cell Cell Example rule application • General requirement: h  m = m’  p L R p (1,4), (2,5), (3,6) m (1,1), (2,2), (3,3) (4,1), (5,2), (6,3), (7,7) G (1,1), (2,2), (3,3), (4,4), (5,5) (6,6)  Introduction to Graph Transformation

  27. 2 Cell 5 7 Cell Object next last m’ 1 3 next Cell Buffer val last 4 6 Buffer Cell H’ h 2 5 Cell Object Cell Object val val 6 4 next next next next first last first 3 1 1 2 Cell Buffer Cell Cell Buffer Cell Object last val 5 3 9 4 8 next next next next Cell Cell Rule application: variation 1 • Also correct: H  H’ L R p (1,4), (2,5), (3,6) m (1,1), (2,2), (3,3) (4,2), (5,5), (6,1), (7,9) G (1,2), (2,5), (3,1), (4,8), (5,3) (6,4)  Introduction to Graph Transformation

  28. 2 Cell 5 7 Cell Object next last m’ 1 3 next Cell Buffer val last 4 6 Buffer Cell h 2 Cell Object val 6 next next first last 3 1 Cell Buffer Cell 5 4 next next Cell Rule application: variation 2 • What’s wrong? h  m = m’  p fulfilled! L R p (1,4), (2,5), (3,6) m (1,1), (2,2), (3,3) (4,1), (5,2), (6,3) G 2 H Cell next next first 3 1 Cell Buffer Cell last 5 4 next next Cell Object 6 val (1,1), (2,2), (3,3), (4,4), (5,5)  Introduction to Graph Transformation

  29. diagramcommutes (hm =m’p) rule (p) that’s the one! wrong alternative matching (m) 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      Introduction to Graph Transformation

  30. 2 1 A c c c c b b a a a 1 1 1 1 A A A A C C C C 3 2 3 2 1 1 1 1 1 A A A A A A B B A 2 2 2 2 2 a 4 A B 5 5 4 AB b c b b c 4 A C 7 4 4 A A B B 5 5 4 A C 5 b a a a b b b b B 6 B B 6 6 B 6 1 A 1 A x y x,y 2 3 2 3 b b b 4 4 A A B B 5 5 4 C B 5 6 C B 5 a a c 4 4 A A x,y x,y 5 5 Example pushouts (1,4),(2,5) (1,4),(2,5) (1,4),(2,5) (1,4),(2,4) (1,4),(2,4) (1,4),(2,5),(3,5) Lessons: - Pushouts always exist - Leave no dangling edges - Deletion always wins x-edge not mapped! 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 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 Introduction to Graph Transformation

  33. 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 Introduction to Graph Transformation

More Related