budapest university of technology and economics adaptive graph pattern matching for model...

40
Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró [email protected] Dániel Varró [email protected] Katalin Friedl [email protected]

Upload: elaine-bryan

Post on 11-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

Budapest University of Technology and Economics

Adaptive Graph Pattern Matching for Model Transformations using

Model-sensitive Search Plans

Gergely Varró [email protected]ániel Varró [email protected]

Katalin Friedl [email protected]

Page 2: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

2Budapest University of Technology and Economics

Talk overview

Introduction & GT

PM techniques

Approach overview

Model-sensitive search plans

Adaptive PM

Page 3: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

3Budapest University of Technology and Economics

Introduction

• Common problem to be solved by model transformation tools:– Efficient query and manipulation of complex

graph-based patterns

• One possible solution:– Graph transformation

Page 4: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

4Budapest University of Technology and Economics

Metamodeling

Attribute

CF

Ref

EO

UF**

1ModelElement

NamespaceFeature

Column

Table Schema

Class Package

UniqueKey

PKey

1ClassAssociation

At most one

Inheritance

Instance model

CWM Metamodel

Slot

r1:Ref

eo1:EO

s2:Schema

c1:Class

p1:Package

p2:Package

c2:Classeo2:EO

c3:Classeo3:EO

Arbitrary

ObjectMultiplicity constraint

Link

Page 5: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

5Budapest University of Technology and Economics

Graph transformation rule

s:Schema

r1:Ref rn:Ref

tn:Table

p:Package

Left-HandSide

Right-HandSide

c:Classeo1:EO

s:Schema

r1:Ref r2:Ref

t:Table

p:Package c:Classeo1:EO

tpk:PKey tid:Column

eo2:EO

eo3:EO cf:CF

uf:UFClassRule

Negative applicationc

ondition

LHS RHS

Page 6: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

6Budapest University of Technology and Economics

Pattern matching phase

LHS RHS

s:Schema

r1:Ref rn:Ref

tn:Table

p:Package c:Classeo1:EO

s:Schema

r1:Ref r2:Ref

t:Table

p:Package c:Classeo1:EO

tpk:PKey tid:Column

eo2:EO

eo3:EO cf:CF

uf:UFClassRule

r1:Ref

eo1:EO

s2:Schema

c1:Class

p1:Package

p2:Package

c2:Classeo2:EO

c3:Classeo3:EO

Page 7: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

7Budapest University of Technology and Economics

Updating phase

id2:Column

t2:Table

uf:UF

LHS RHS

s:Schema

r1:Ref rn:Ref

tn:Table

p:Package c:Classeo1:EO

s:Schema

r1:Ref r2:Ref

t:Table

p:Package c:Classeo1:EO

tpk:PKey tid:Column

eo2:EO

eo3:EO cf:CF

uf:UFClassRule

r1:Ref

eo1:EO

s2:Schema

c1:Class

p1:Package

p2:Package

c2:Classeo2:EO

c3:Classeo3:EO

pk2:PKey

eo6:EO

eo5:EOeo4:EO

r2:Ref

Page 8: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

8Budapest University of Technology and Economics

Talk overview

Introduction & GT

PM techniques

Approach overview

Model-sensitive search plans

Adaptive PM

Page 9: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

9Budapest University of Technology and Economics

Practical consideration

• Most critical step: pattern matching

• Simplification: without NAC

s:Schema

r1:Ref rn:Ref

tn:Table

p:Package c:Classeo1:EO

ClassRuleLHS

s:Schema

r1:Ref r2:Ref

t:Table

p:Package c:Classeo1:EO

tpk:PKey tid:Column

eo2:EO

eo3:EOcf:CF

uf:UF

RHS

Page 10: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

10Budapest University of Technology and Economics

Pattern matching techniques

• Style– Interpreted: AGG, VIATRA

• underlying PM engine– Compiled: Fujaba, GReAT, PROGRES

• directly executed as a C or Java code (no PM engine)

• Base algorithm– Constraint satisfaction: AGG, VIATRA

• variables + constraints– Local search: Fujaba, GReAT, PROGRES

• step-by-step extension of the matching

Page 11: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

11Budapest University of Technology and Economics

Traditional approach I.

• Pattern matching strategy– defined in design/compile time– single search plan– based on multiplicity and type restrictions

• e.g. at-most-one multiplicity precedes arbirtrary multiplicity

• Fixed implementation– nested-loops– in Java, C, ...

s:Schema

r1:Ref

p:Package c:Classeo1:EO

RuleLHS

Design/Compile time

c

p

s

1

2

3

Search plan

Search sequencefrequently used & efficient solution

order of traversal in the search plan

multiplicity & type restrictions

Page 12: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

12Budapest University of Technology and Economics

Traditional approach II.

s:Schema

r1:Ref

p:Package c:Classeo1:EO

RuleLHS

Design/Compile time

Execution time

Search space tree

c

p

s

1

2

3

r1:Ref

eo1:EO

s2:Schema

c1:Class

p1:Package

p2:Package

c2:Classeo2:EO

c3:Classeo3:EO

c

p

s

Model

Search plan

Search sequence

• Search space tree (SST)– Search space traversed according to a specific

search plan

– Contains all decisions made during pattern matching

Page 13: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

13Budapest University of Technology and Economics

Talk overview

Introduction & GT

PM techniques

Approach overview

Model-sensitive search plans

Adaptive PM

Page 14: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

14Budapest University of Technology and Economics

Model-sensitive search plans

Rule

Design/Compile time

Search plan 1

Search plan 2

Search plan 3Typical model 1

Typical model 2

Typical model 3

Page 15: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

15Budapest University of Technology and Economics

Adaptive PM approach

Rule

Design/Compile time

Execution time

Current model

Search plan 1

Search plan 2

Search plan 3Typical model 1

Typical model 2

Typical model 3

Strategyselection

Search space tree

Page 16: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

16Budapest University of Technology and Economics

Talk overview

Introduction & GT

PM techniques

Approach overview

Model-sensitive search plans

Adaptive PM

Page 17: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

17Budapest University of Technology and Economics

Instance model with statistics

• Statistical data– based on rules

– collected from instance models

• Example:

s:Schema

r1:Ref

p:Package c:Classeo1:EO

RuleLHS

r1:Ref

eo1:EO

s2:Schema

c1:Class

p1:Package

p2:Package

c2:Classeo2:EO

c3:Classeo3:EO

Typical model 1

#

Schema

Package

Class

EO(Package,Class)

Ref(Package,Schema)

1

3

3

3

1

Schema

InheritancePackage

Page 18: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

18Budapest University of Technology and Economics

Search graph

s:Schema

r1:Ref

p:Package c:Classeo1:EO

RuleLHS

cps

Search graph

• Edge from the starting node to another node– Iteration over all objects in the model of the corresponding

type

• Edge between non-starting nodes– When source pattern node is already matched– Navigation along the corresponding pattern edge towards

the unmatched (target) pattern node

Starting node

Page 19: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

19Budapest University of Technology and Economics

Weighted search graph

cps

Search graph 1

cps 1

0.33 1

1

33

1

r1:Ref

eo1:EO

s2:Schema

c1:Class

p1:Package

p2:Package

c2:Classeo2:EO

c3:Classeo3:EO

Typical model 1

Schema 1Package 3Class 3EO(Package,Class) 3Ref(Package,Schema) 1

#Ref(Package,Schema)/#Package = 1/3 = 0.33#Ref(Package,Schema)/#Schema = 1/1 = 1

• Edge weight– average branching factor of a possible SST at the

level, when the given edge is selected for navigation

Page 20: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

20Budapest University of Technology and Economics

Search planWeighted search graph 1

cps 1

0.33 1

1

33

1

cps 1

0.33 1

1

33

1

Search tree 1

cps 1

0.33 1

1

33

1

2 3

1

Search plan 1

Algorithm 1

Algorithm 2

Page 21: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

21Budapest University of Technology and Economics

Search plan

cps 1

0.33 1

1

33

1

2 3

1

Search plan 1

Estimated search space tree

s

p

c

1

1

1

r1:Ref

eo1:EO

s2:Schema

c1:Class

p1:Package

p2:Package

c2:Classeo2:EO

c3:Classeo3:EO

Typical model 1

w(P) =w(P) = 1w(P) = 1 + 1*1w(P) = 1 + 1*1 + 1*1*1 = 3

• Estimated number of traversed nodes in SST

• Properties of the minimal search plan – SST optimal in size– first-fail principle

Page 22: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

22Budapest University of Technology and Economics

Algorithm 1

• Given:– Search graph

• Goal:– Low cost search tree

• Chu-Liu / Edmonds algorithm– Relatively simple greedy algorithm

– Spanning tree in a weighted directed graph

– Optimality guaranteed, if cost function is the sum

of edge weights !+ Fast

Page 23: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

23Budapest University of Technology and Economics

Chu-Liu / Edmonds algorithm I.

• Discard edges entering the starting node

Weighted search graph 1

cps 1

0.33 1

1

33

1

Page 24: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

24Budapest University of Technology and Economics

Chu-Liu / Edmonds algorithm II.

• For each other node, select the incoming edge with the smallest weight. Let the selected n-1 edges be the set S.

Weighted search graph 1

cps 1

0.33 1

1

33

1

Page 25: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

25Budapest University of Technology and Economics

Chu-Liu / Edmonds algorithm III.

• For each cycle formed, contract the nodes of the cycle into a pseudo-node k, and

• Modify the weight of each edge entering node j of the cycle from some node i outside the cycle.

Weighted search graph 1

cps 1

0.33 1

1

33

1

M = min(1,0.33) = 0.33

c(i,k) = c(i,j) – [c(x(j),j)-M]0.67

2.671

Page 26: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

26Budapest University of Technology and Economics

Chu-Liu / Edmonds algorithm IV.

• For each pseudo-node, select the entering edge, which has the smallest weight.

• Go to the previous step with the contracted graph.

Weighted search graph 1

cps 1

0.33 0.67

1

32.67

11

Page 27: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

27Budapest University of Technology and Economics

Chu-Liu / Edmonds algorithm V.

• For each cycle formed, contract the nodes of the cycle into a pseudo-node k, and

• Modify the weight of each edge entering node j of the cycle from some node i outside the cycle.

Weighted search graph 1

c

0.67

1

32.672.671

2.671

M = min(1,0.67) = 0.67

c(i,k) = c(i,j) – [c(x(j),j)-M]

Page 28: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

28Budapest University of Technology and Economics

Chu-Liu / Edmonds algorithm VI.

• For each pseudo-node, select the entering edge, which has the smallest weight.

• Go to the previous step with the contracted graph.

Weighted search graph 1

c

0.67

1

2.672.671

Page 29: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

29Budapest University of Technology and Economics

Chu-Liu / Edmonds algorithm VII.

• No cycles

• Restore the consistency of edges in contracted nodes.

Weighted search graph 1

c

0.67

1

32.671

2.67

Page 30: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

30Budapest University of Technology and Economics

Chu-Liu / Edmonds algorithm VIII.

• Restore the consistency of edges in contracted nodes.

Weighted search graph 1

cps 1

0.33 1

1

33

1

Search tree 1

Page 31: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

31Budapest University of Technology and Economics

Algorithm 2

• Set the label of the smallest tree edge leaving S to the value of the counter.

• Increment the counter, and add the target node of the selected edge to S.

• Repeat these steps until S contains all nodes of the graph.

cps 1

0.33 1

1

33

1

Search tree 1

counter = 1, S = {0}counter = 2, S = {0,s}counter = 3, S = {0,s,p}counter = 4, S = {0,s,p,c}32

1

Search plan 1

Simple greedy algorithm

Page 32: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

32Budapest University of Technology and Economics

Additional notes

• NACs– general rule: checked after a matching found

– simple checks (e.g. cardinality check) when shared node is processed during the traversal of LHS

– NAC pattern ~ LHS pattern no problem

• Completion of partially matched patterns– several starting nodes in Algorithms 1 and 2

– search tree forest rooted at starting nodes

– all other nodes are reachable on tree edges

Page 33: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

33Budapest University of Technology and Economics

Model-sensitive search plan generation

r1:Ref

eo1:EO

s2:Schema

c1:Class

p1:Package

p2:Package

c2:Classeo2:EO

c3:Classeo3:EO

Typical model 1

cps 1

0.33 1

1

33

11

32 cps 1

0.5 1

0.25

14

21

3 2

Search plan 2Search plan 1

Same as the search plan of the traditional

approach

r2:Refs2:Schema

p1:Package

p2:Package

eo1:EOTypical model 2

s1:Schemar1:Ref

c1:Class

Page 34: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

34Budapest University of Technology and Economics

Talk overview

Introduction & GT

PM techniques

Approach overview

Model-sensitive search plans

Adaptive PM

Page 35: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

35Budapest University of Technology and Economics

Adaptive PM implementation

• cost():– calculates the cost of the search plan based on the current

instance model– invoked on every strategies before each pattern matching

• match():– pattern matching implementation– invoked only on the strategy with the smallest cost

Strategy

StrategyFromModel1

StrategyFromModel2

cost()match()

Page 36: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

36Budapest University of Technology and Economics

Runtime behaviour I.cps 1

0.33 1

1

33

11

32 cps 1

0.33 1

1

33

11

3 2

Search plan 2Search plan 1

Search space tree Search space tree

w(P1) = 3 w(P2) = 7

r1:Ref

eo1:EO

s2:Schema

c1:Class

p1:Package

p2:Package

c2:Classeo2:EO

c3:Classeo3:EO

Typical model 1s

p

c

c

p

s

Page 37: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

37Budapest University of Technology and Economics

Runtime behaviour II.cps 1

0.5 1

0.25

14

21

32 cps 1

0.5 1

0.25

14

21

3 2

Search plan 2Search plan 1

r2:Refs2:Schema

p1:Package

p2:Package

eo1:EOTypical model 2

s1:Schemar1:Ref

c1:Class

Search space tree

s

p

c

Search space tree

c

p

s

w(P1) = 4.5 w(P2) = 2.5

Page 38: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

38Budapest University of Technology and Economics

Runtime behaviour III.cps 0

0 1

1

33

01

32 cps 0

0 1

1

33

01

3 2

Search plan 2Search plan 1

Search space tree Search space tree

w(P1) = 0 w(P2) = 6

eo1:EO c1:Class

p1:Package

p2:Package

c2:Classeo2:EO

c3:Classeo3:EO

Model 3s

p

c

c

p

s

Immediate PM failure detection

Page 39: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

39Budapest University of Technology and Economics

Pros and contras

• Resource related+ time: smaller execution time during pattern matching

– time: extra computation for cost calculation

– storage: small amount of additional (statistical) data

• Application area related+ when only one matching is needed+ first-fail principle early detection of PM failure+ manually created (or tool provided) search plans can be

used

– search plan generation algorithm: not necessarily optimal

– estimated and executed SST may differ+ estimated SST better for the worst case

Page 40: Budapest University of Technology and Economics Adaptive Graph Pattern Matching for Model Transformations using Model-sensitive Search Plans Gergely Varró

40Budapest University of Technology and Economics

Future work

• Topics not discussed– Java implementation of search plans

• Todo list– Quantitative measurements for assessing the

performance of the approach

– Algorithm for finding an optimal search plan

• Thanks for your kind attention.

• Questions, comments, remarks?