Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to Graph Rewriting Thomas Huining Feng CHESS, UC Berkeley May.

Similar presentations


Presentation on theme: "An Introduction to Graph Rewriting Thomas Huining Feng CHESS, UC Berkeley May."— Presentation transcript:

1 An Introduction to Graph Rewriting Thomas Huining Feng http://www.eecs.berkeley.edu/~tfeng/ CHESS, UC Berkeley http://www.eecs.berkeley.edu/~tfeng/ May 1, 2007 Inspired by Tutorial Introduction to Graph Transformation: A Software Engineering Perspective. Luciano Baresi, Reiko Heckel. ICGT 2002

2 PacMan: a Motivating Example : Field Field 11..4 Type : Ghost Ghost 10..1 : PacMan PacMan 10..1 : Marble Marble 1 0..1 2

3 Our 1 st Rule: pmove b : Field a : Field : PacMan b : Field a : Field : PacMan 3 pmove LHS (Left Hand Side) RHS (Right Hand Side) : Field : Ghost : PacMan : Marble Host Graph Redex Redex finding is a sub-graph isomorphism problem). Multiple redexes?

4 Our 2 nd Rule: gmove b : Field a : Field : Ghost b : Field a : Field : Ghost gmove : Field : Ghost : PacMan : Marble

5 Combining pmove and gmove pmove and gmove do not “interfere” with each other. I.e., applying any one does not affect applicability of the other. 5 b : Field a : Field : PacMan b : Field a : Field : PacMan pmove b : Field a : Field : Ghost b : Field a : Field : Ghost gmove

6 catch Rule 6 b : Field a : Field : Ghost b : Field a : Field : Ghost catch : PacMan : Field : Ghost : PacMan : Marble

7 catch is actually a “sub-case” of gmove, because: LHS(gmove)  LHS(catch) Assign priority (almost always the same for sub-cases): P(catch) > P(gmove) Important Decision: Which Rule to Choose? 7 b : Field a : Field : Ghost b : Field a : Field : Ghost gmove b : Field a : Field : Ghost b : Field a : Field : Ghost catch : PacMan

8 Attribute Binding: collect Rule 8 : Field : Ghost : PacMan 3 : marble : Marble : PacMan 4 : marble

9 Here, m on the LHS serves as a bound variable; on the RHS, it refers to the value bound to. Attribute Binding: collect Rule 9 b : Field a : Field : PacMan m : marble b : Field a : Field : PacMan m+1 : marble collect : Marble : Field : Ghost : PacMan 3 : marble : Marble Field 11..4 Type Ghost 10..11 Marble 1 0..1 PacMan int marble

10 Completing the PacMan Game 10 b : Field a : Field : PacMan b : Field a : Field : PacMan pmove b : Field a : Field : Ghost b : Field a : Field : Ghost gmove b : Field a : Field : Ghost b : Field a : Field : Ghost catch b : Field a : Field : PacMan m : marble b : Field a : Field : PacMan m+1 : marble collect : Marble : PacMan sub-case interfering sub-case 1 2 3 3 n P Priority:

11 Common components in the problem – Host graph – A set of rewriting rules LHS and RHS Attribute binding and transfer Application condition Embedding information Host Graph – Redex The Graph Rewriting Problem 11 m < BAG_SIZE b : Field a : Field : PacMan m : marble b : Field a : Field : PacMan m+1 : marble : Marble

12 The Graph Rewriting Problem 12 Common components in the problem: – Host graph – A set of rewriting rules LHS and RHS Attribute binding and transfer Application condition Embedding information Rule application 1.In the host graph, find all redexes according to the rules. Match LHS Check application condition 2.Choose a redex and a rule to apply. 3.Apply the rule. Generate a substitution (unique) isomorphic to RHS Compute new attributes Make substitution (“bridge” w.r.t embedding information)

13 More on Application Decision We have seen priorities (as a partial order of rules). Applications may require other approaches. – More flexible rule choosing: Combine with control structure Event-driven Combine with state machine 13 C? YN e1e2 C1?C2?

14 More on Application Decision We have seen priorities (as a total order of rules). Applications may require other approaches. – Maze walking (goal-directed searching) 14 Field 11..4 Entrance 10..1 Kid 10..1 Exit 1 0..1

15 More on Application Decision We have seen priorities (as a total order of rules). Applications may require other approaches. – Shortest path (optimizing an objective function) 15 StartEnd3 8 52 6 1 Man 00 1* Start 10..1 Man int time 10..1 End 1 0..1 Field int delay b : Field d : delay a : Field : Man t : time b : Field d : delay a : Field : Man t+d : time

16 Conclusion Key idea is simple. User-friendly. Expressive. – Transformation problems – Analysis problems – Search problems – Optimization problems Complexity due to sub-graph isomorphism on the LHS. Rules need to be carefully designed and chosen at run time. – Depending on the problem and the goal. Problem formulation and algorithm are application dependent. 16


Download ppt "An Introduction to Graph Rewriting Thomas Huining Feng CHESS, UC Berkeley May."

Similar presentations


Ads by Google