160 likes | 315 Views
An Introduction to Graph Rewriting. Thomas Huining Feng http://www.eecs.berkeley.edu/~tfeng/ CHESS, UC Berkeley May 1, 2007 Inspired by Tutorial Introduction to Graph Transformation: A Software Engineering Perspective . Luciano Baresi, Reiko Heckel. ICGT 2002. PacMan: a Motivating Example.
E N D
An Introduction to Graph Rewriting Thomas Huining Fenghttp://www.eecs.berkeley.edu/~tfeng/CHESS, UC Berkeley May 1, 2007 Inspired by Tutorial Introduction to Graph Transformation: A Software Engineering Perspective. Luciano Baresi, Reiko Heckel. ICGT 2002
PacMan: a Motivating Example : PacMan : Field : Field : Field : Ghost : Marble : Field : Field : Field : Field : Field : Field Type 1..4 1 0..1 1 1 0..1 Ghost Field PacMan 1 0..1 Marble
Our 1st Rule: pmove LHS (Left Hand Side) RHS (Right Hand Side) : PacMan : PacMan pmove a : Field a : Field b : Field b : Field Redex finding is a sub-graph isomorphism problem). Multiple redexes? Redex : PacMan : Field : Field : Field : Ghost : Marble : Field : Field : Field : Field Host Graph : Field : Field
Our 2nd Rule: gmove : Ghost : Ghost gmove a : Field a : Field b : Field b : Field : PacMan : Field : Field : Field : Ghost : Marble : Field : Field : Field : Field : Field : Field
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. : Ghost : Ghost pmove gmove : PacMan : PacMan a : Field a : Field b : Field b : Field a : Field a : Field b : Field b : Field
catch Rule : Ghost : Ghost : PacMan catch a : Field a : Field b : Field b : Field : PacMan : Field : Field : Field : Ghost : Marble : Field : Field : Field : Field : Field : Field
Important Decision: Which Rule to Choose? • 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) : Ghost : Ghost : PacMan catch gmove : Ghost : Ghost a : Field a : Field b : Field b : Field a : Field a : Field b : Field b : Field
Attribute Binding: collect Rule : PacMan 4 : marble : PacMan 3 : marble : Field : Field : Field : Ghost : Marble : Field : Field : Field : Field : Field : Field
Attribute Binding: collect Rule • Here, m on the LHS serves as a bound variable; on the RHS, it refers to the value bound to. : PacMan m : marble : PacMan m+1 : marble : Marble : PacMan 3 : marble collect : Field : Field : Field a : Field a : Field b : Field b : Field : Ghost : Marble : Field : Field : Field : Field : Field : Field 1..4 1 Type 0..1 1 1 0..1 Ghost Field PacMan int marble 1 0..1 Marble
Completing the PacMan Game Priority: : PacMan : PacMan 3 : PacMan m : marble : Ghost : PacMan m+1 : marble : Ghost : Marble collect gmove pmove catch interfering a : Field a : Field b : Field b : Field a : Field a : Field a : Field a : Field b : Field b : Field b : Field b : Field 3 sub-case 1 : Ghost : PacMan : Ghost a : Field a : Field b : Field b : Field sub-case 2 n P
The Graph Rewriting Problem • 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 : PacMan m : marble : PacMan m+1 : marble : Marble a : Field a : Field b : Field b : Field m < BAG_SIZE
The Graph Rewriting Problem • 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 • In the host graph, find all redexes according to the rules. • Match LHS • Check application condition • Choose a redex and a rule to apply. • Apply the rule. • Generate a substitution (unique) isomorphic to RHS • Compute new attributes • Make substitution (“bridge” w.r.t embedding information)
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 C? Y N e1 e2 C1? C2?
More on Application Decision • We have seen priorities (as a total order of rules). • Applications may require other approaches. • Maze walking (goal-directed searching) 1..4 1 0..1 1 1 0..1 Entrance Field Kid 1 0..1 Exit
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) Start 3 6 End 0 5 1 2 0 Man 8 : Man t : time : Man t+d : time * 1 0..1 1 1 0..1 Field int delay Man int time Start a : Field b : Field d : delay a : Field b : Field d : delay 1 0..1 End
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.