Title: An Introduction to Graph Rewriting
1An 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
2PacMan a Motivating Example
PacMan
Field
Field
Field
Ghost
Marble
Field
Field
Field
Field
Field
Field
Type
1
1..4
1
0..1
1
0..1
Field
Ghost
PacMan
1
0..1
Marble
3Our 1st Rule pmove
PacMan
PacMan
LHS (Left Hand Side)
RHS (Right Hand Side)
b Field
a Field
a 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
4Our 2nd Rule gmove
Ghost
Ghost
b Field
a Field
a Field
b Field
PacMan
Field
Field
Field
Ghost
Marble
Field
Field
Field
Field
Field
Field
5Combining pmove and gmove
- pmove and gmove do not interfere with each
other. - I.e., applying any one does not affect
applicability of the other.
6catch Rule
PacMan
Field
Field
Field
Ghost
Marble
Field
Field
Field
Field
Field
Field
7Important 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) gt P(gmove)
8Attribute Binding collect Rule
PacMan 3 marble
PacMan 4 marble
Field
Field
Field
Ghost
Marble
Field
Field
Field
Field
Field
Field
9Attribute Binding collect Rule
- Here, m on the LHS serves as a bound variable on
the RHS, it refers to the value bound to.
PacMan 3 marble
Field
Field
Field
Ghost
Marble
Field
Field
Field
Field
Field
Field
10Completing the PacMan Game
Priority
3
interfering
3
sub-case
1
Ghost
Ghost
PacMan
b Field
a Field
a Field
b Field
sub-case
2
11The 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 m1 marble
Marble
b Field
a Field
b Field
a Field
m lt BAG_SIZE
12The 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)
13More 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
14More on Application Decision
- We have seen priorities (as a total order of
rules). - Applications may require other approaches.
- Maze walking (goal-directed searching)
1
1..4
1
0..1
1
0..1
Field
Entrance
Kid
1
0..1
Exit
15More on Application Decision
- We have seen priorities (as a total order of
rules). - Applications may require other approaches.
- Shortest path (optimizing an objective function)
16Conclusion
- 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.