an introduction to graph rewriting thomas huining feng tfeng/ chess, uc berkeley tfeng/ may

16
An Introduction to Graph An Introduction to Graph Rewriting 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

Upload: beatrice-banks

Post on 04-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

An Introduction to Graph RewritingAn 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

: Field

: Field : Field : Field

: Field : Field

: Field

: Field: Field

Field

11..4

Type

: Ghost

Ghost 10..1

: PacMan

PacMan1 0..1

: Marble

Marble

10..1

2

Our 1st Rule: pmove

b : Fielda : Field

: PacMan

b : Fielda : Field

: PacMan

3

pmoveLHS

(Left Hand Side)RHS

(Right Hand Side)

: Field

: Field : Field : Field

: Field : Field

: Field

: Field: Field

: Ghost

: PacMan

: Marble

Host Graph

Redex

Redex finding is a sub-graph isomorphismproblem).Multiple redexes?

Our 2nd Rule: gmove

b : Fielda : Field

: Ghost

b : Fielda : Field

: Ghostgmove

: Field

: Field : Field : Field

: Field : Field

: Field

: Field: Field

: Ghost

: PacMan

: Marble

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 : Fielda : Field

: PacMan

b : Fielda : Field

: PacManpmove

b : Fielda : Field

: Ghost

b : Fielda : Field

: Ghostgmove

catch Rule

6

b : Fielda : Field

: Ghost

b : Fielda : Field

: Ghostcatch

: PacMan

: Field

: Field : Field : Field

: Field : Field

: Field

: Field: Field

: Ghost

: PacMan

: Marble

• 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 : Fielda : Field

: Ghost

b : Fielda : Field

: Ghostgmove

b : Fielda : Field

: Ghost

b : Fielda : Field

: Ghostcatch

: PacMan

Attribute Binding: collect Rule

8

: Field

: Field : Field : Field

: Field : Field

: Field

: Field: Field

: Ghost

: PacMan3 : marble

: Marble

: PacMan4 : marble

• 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 : Fielda : Field

: PacManm : marble

b : Fielda : Field

: PacManm+1 : marblecollect

: Marble

: Field

: Field : Field : Field

: Field : Field

: Field

: Field: Field

: Ghost

: PacMan3 : marble

: Marble

Field

11..4Type

Ghost 10..1 1 0..1

Marble

10..1

PacManint marble

Completing the PacMan Game

10

b : Fielda : Field

: PacMan

b : Fielda : Field

: PacManpmove

b : Fielda : Field

: Ghost

b : Fielda : Field

: Ghostgmove

b : Fielda : Field

: Ghost

b : Fielda : Field

: Ghostcatch

b : Fielda : Field

: PacManm : marble

b : Fielda : Field

: PacManm+1 : marblecollect

: Marble

: PacMan

sub-case

interfering

sub-case

1

2

3

3

n P

Priority:

• 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 : Fielda : Field

: PacManm : marble

b : Fielda : Field

: PacManm+1 : marble

: Marble

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 application1. 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)

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?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)

14

Field

11..4

Entrance 10..1 Kid1 0..1

Exit

10..1

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

Start End3

8

5 2

6

1

Man

0 0

1*

Start10..1 Man

int time1 0..1

End

10..1

Fieldint delay

b : Fieldd : delay

a : Field

: Mant : time

b : Fieldd : delay

a : Field

: Mant+d : time

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