Budapest	University	of	Technology	 and	Economics
Department	 of	Measurement	and	Information	 Systems
Rete network slicing
for model queries
Zoltán	Ujhelyi,	Gábor	Bergmann,	
Dániel	Varró
VIATRA:	A	Reactive &	Incremental
Transformation Platform
http://eclipse.org/viatra
Road	to	a	reactive	and	incremental	model	transformation	platform:	
three	generations	of	the	VIATRA	framework
Varró,	D	et	al.	Softw	Syst	Model	(2016).	
doi:10.1007/s10270-016-0530-4
VIATRA:	
Reactive
Transformation
Framework
Reactive Event Driven Transformations
Observed
events
Controlled
events
Notifications
Messages
Model
VIATRA:	
Reactive
Transformation
Framework
Reactive Event Driven Transformations
Observed
events
Controlled
events
Notifications
Messages
Model
Event
What has	happened?	
(external +	internal)
Condition
When to react?	
(internal)
Action
What to do?	
(external+internal)
VIATRA:	
Reactive
Transformation
Framework
Reactive Event Driven Transformations
Observed
events
Controlled
events
Notifications
Messages
Model
• Model modified
• Match	of	queryappeared
• Event sequence identified
• „Run”	button pushed
• Consistentstate
reached after edit
• Transaction committed
• Modifymodel
• Add	error marker
• Update	view
• Send e-mail
• Regular model
queries
• Traceabilityinfo
VIATRA:	Overview of	Features
•Display	exec.	state of	MT	
(in debug mode)
•Model +	rule activations
•Breakpoints (incl.	conditional)
•User selects next activation
Debugger
•Explore design	model
candidates
•Satisfying multiple criteria
•Rule based exploration
•Optimization
Design	
Space
Exploration
•Detect complex event
sequences
•Rule based reaction
•Xtext based language
Complex
Event
Processing
§ Reactive MT	Platform
o Query +	MT	Language
• Language +	API	for queries and	
transformations
– Query:	DSL	(VQL)
– MT:	Internal DSL	over	Xtend
o Engine:
• Event-driven VM
(compiles to Java)
• Local-search +	incremental queries
• Batch	+	Incremental MTs
o Advanced	GUI
§ Unified projects (April 2016)
o EMF-IncQuery è VIATRA	Query
o Graduatedat	Eclipse	Foundation
Tool integration with:	
Papyrus UML,	Sirius,	
RMF,	Capella,	ARTOP,	
mbeddr
Industrial users:	
Itemis,	Ericsson,	CERN
Embraer,	Thales,	CEA
ThyssenKrupp
Simple	Graph	Pattern	in	VIATRA
pattern stateOfMachine(sm : StateMachine, st : State) {
StateMachine.region(sm, r);
Region.member(r, st);
}
7
7
sm:	State	
Machine
st:	State
member
region
r:	Region
And	a	More	Complex	Example
/**
* A transition between different state machines
*/
pattern differentStateMachine(tr : Transition) {
State.outgoing(src, tr);
Transition.target(tr, trg);
find stateOfMachine(sm, src);
neg find stateOfMachine(sm, trg);
}
pattern stateOfMachine(sm : StateMachine, st : State) {
StateMachine.region(sm, r);
Region.member(r, st);
}
8
And	a	More	Complex	Example
/**
* A transition between different state machines
*/
pattern differentStateMachine(tr : Transition) {
State.outgoing(src, tr);
Transition.target(tr, trg);
find stateOfMachine(sm, src);
neg find stateOfMachine(sm, trg);
}
pattern stateOfMachine(sm : StateMachine, st : State) {
StateMachine.region(sm, r);
Region.member(r, st);
}
9
Pattern
composition
(for reuse)
Negative
composition
(negation,	
quantification)
Query	Development	in	VIATRA
10
Pattern	Editor
Model	Editor
Query	Result	Viewer
Results recalculated
on	model	changes
Results reevaluated
on patterns change
Current VIATRA	Debugger
11
• Display	exec.	state of	MT		
(in debug mode)
• Model +	rule activations
• Breakpoints (incl.	Conditional)
• User selects next activation
Motivations
Towards advanced debugging by slicing
Incorrect	Query
13
Incorrect	Query
14
Negation replaced
with (positive)	
pattern composition
Incorrect query
results found
Incorrect	Query
15
Negation replaced
with (positive)	
pattern composition
Incorrect query
results found
Why is	a	tuple
(transition	TI)
incorrectly	included	
in	the	results?	
Debugging graph patterns:	
• Manually	removing	constraints
• Evaluating	the	result	manually
Debugging	the	Faulty	Pattern
16
Debugging	the	Faulty	Pattern
17
Missing TC1	and	
TC2;	extra	TI
Debugging	the	Faulty	Pattern
18
Debugging	the	Faulty	Pattern
19
All transition/target
pairs correct
Debugging	the	Faulty	Pattern
20
Debugging	the	Faulty	Pattern
21
All transition/target
pairs correct
Debugging	the	Faulty	Pattern
22
All transition/target
pairs correct
Conclusion:	the two
compositionsneeds
to be	verified
Rete Networks for Incremental
Graph Query Evaluation
Graph	Pattern	Matching	with	Rete	networks
§ Rete	network:	complex	cache	structure
o Model	index
o Pattern	matches
o Partial	matches
§ Graph	pattern	matching	with	Rete
o Incremental	approach:
• Partial	re-evaluation	on	model	changes
• Notifications	on	pattern	match	changes
24
Intermediate	nodes
pattern stateOfMachine(sm : StateMachine, st : State) {
StateMachine.region(sm, r);
Region.member(r, st);
}
∏
stateOfMachine
StateMachine #	
region
Region	#
member
JOIN
Rete	Network	– Simple	Pattern
Input
nodes
Production	nodes
Intermediate	nodes
pattern stateOfMachine(sm : StateMachine, st : State) {
StateMachine.region(sm, r);
Region.member(r, st);
}
∏
stateOfMachine
StateMachine #	
region
Region	#
member
JOIN
Rete	Network	– Simple	Pattern
Input
nodes
Indexes	model
objects and	links
Production	nodes
Intermediate	nodes
pattern stateOfMachine(sm : StateMachine, st : State) {
StateMachine.region(sm, r);
Region.member(r, st);
}
∏
stateOfMachine
StateMachine #	
region
Region	#
member
JOIN
Rete	Network	– Simple	Pattern
Input
nodes
Indexes	model
objects and	links
Production	nodes
Intermediate	nodes
pattern stateOfMachine(sm : StateMachine, st : State) {
StateMachine.region(sm, r);
Region.member(r, st);
}
∏
stateOfMachine
StateMachine #	
region
Region	#
member
JOIN
Rete	Network	– Simple	Pattern
Input
nodes
Production	nodes
Caches partial
matches
Intermediate	nodes
pattern stateOfMachine(sm : StateMachine, st : State) {
StateMachine.region(sm, r);
Region.member(r, st);
}
∏
stateOfMachine
StateMachine #	
region
Region	#
member
JOIN
Rete	Network	– Simple	Pattern
Input
nodes
Production	nodes
Caches pattern
matches
∏
DSM
Rete	Network	– Complex	Pattern
30
JOIN
NAC
∏
stateOfMachine
State	#	
outgoingTransition
Transition	#	
targetState
JOIN
∏
DSM
Rete	Network	– Complex	Pattern
31
JOIN
NAC
∏
stateOfMachine
State	#	
outgoingTransition
Transition	#	
targetState
JOIN
Productionnode of	
the stateOfMachine
pattern
∏
DSM
Rete	Network	– Complex	Pattern
32
JOIN
NAC
∏
stateOfMachine
State	#	
outgoingTransition
Transition	#	
targetState
JOIN
Pattern
composition
∏
DSM
Rete	Network	– Complex	Pattern
33
JOIN
NAC
∏
stateOfMachine
State	#	
outgoingTransition
Transition	#	
targetState
JOIN
Anti-join operation
calculates negative
composition
Rete	Network	– Cached	Information
34
st =	fr
JOIN
st =	to
NAC
State	#	
outgoingTransition
Transition	#	
targetState
tr =	tr
JOIN
sm st
SM1 S11
SM1 S12
SM2 S21
SM2 FS
st tr
S11 TC1
S11 TI
S12 TC2
tr to
TC1 S21
TI S12
TC2 FS
fr tr to
S11 TC1 S21
S11 TI S12
S12 TC2 FS
sm fr tr to
SM1 S11 TC1 S21
SM1 S12 TC2 FS
∏
stateOfMachine
∏
DSM
sm fr tr to
SM1 S11 TC1 S21
SM1 S11 TI S12
SM1 S12 TC2 FS
Rete	Network	– Change	Propagation
35
st =	fr
JOIN
st =	to
NAC
State	#	
outgoingTransition
Transition	#	
targetState
tr =	tr
JOIN
sm st
SM1 S11
SM1 S12
SM2 S21
SM2 FS
st tr
S11 TC1
S11 TI
S12 TC2
tr to
TC1 S21
TI S12
TC2 FS
fr tr to
S11 TC1 S21
S11 TI S12
S12 TC2 FS
sm fr tr to
SM1 S11 TC1 S21
SM1 S12 TC2 FS
∏
stateOfMachine
∏
DSM
sm fr tr to
SM1 S11 TC1 S21
SM1 S11 TI S12
SM1 S12 TC2 FS
Slicing of	Rete Networks
Slicing	Model	Transformations
§ Similar	to	program	slicing
o Systematic	collection	of	dependencies
o BUT:	slicing of	(input)	models	is	also required
Z.	Ujhelyi	et	al:	Dynamic Forward Slicing of	Model Transformation Programs.	ICST	2012.
37
Model	
transformation
slicing
Transformation
Models
Transformation	
Slice
Model	Slice
Criterion
Slicing	Rete	Networks
§ Goals of	this paper:
o Identify	model	changes	resulting	in	a	specific	change	
in	the	production	node
o Explain the	chain	of	operations connecting	the	model	
and	the	production	node	changes
38
Rete	
network
Transformation
Models
Rete	Operations
Model	Changes
Criterion:
production	node	change	
Rete	
network
slicing
Slicing	Algorithm
§ Inputs:
o Match	set	M	of	Production	node	P
o Criteria
• An	existing match	in	M	to	disappear,	or
• A	non-existing match	in	M	to	appear
§ Output:	Formula	identifying matches in Rete nodes
§ For	each	evaluated	term	recursively
o Calculate	possible	changes	in	parent
§ Recursion	stops
o Elementary	changes	in	input	nodes
o A	match	already	existing	in	a	node	to	be	added
o A	non-existing	match	to	be	deleted	from	a	node
39
Slicing	Rete	Network
40
st =	fr
JOIN
st =	to
State	#	
outgoingTransition
Transition	#	
targetState
tr =	tr
JOIN
sm st
SM1 S11
SM1 S12
SM2 S21
SM2 FS
st tr
S11 TC1
S11 TI
S12 TC2
tr to
TC1 S21
TI S12
TC2 FS
fr tr to
S11 TC1 S21
S11 TI S12
S12 TC2 FS
sm fr tr to
SM1 S11 TI S12
∏
stateOfMachine
∏
DSM
sm fr tr to
SM1 S11 TC1 S21
SM1 S11 TI S12
SM1 S12 TC2 FS
JOIN
Slicing	Rete	Network
41
st =	fr
JOIN
st =	to
State	#	
outgoingTransition
Transition	#	
targetState
tr =	tr
JOIN
sm st
SM1 S11
SM1 S12
SM2 S21
SM2 FS
st tr
S11 TC1
S11 TI
S12 TC2
tr to
TC1 S21
TI S12
TC2 FS
fr tr to
S11 TC1 S21
S11 TI S12
S12 TC2 FS
sm fr tr to
SM1 S11 TI S12
∏
stateOfMachine
∏
DSM
sm fr tr to
SM1 S11 TC1 S21
SM1 S11 TI S12
SM1 S12 TC2 FS
JOIN
Why is	state S12	present in	
the match set?
Criteria:	
remove tuple (0)	
from match set
0
Slicing	Rete	Network
42
st =	fr
JOIN
st =	to
State	#	
outgoingTransition
Transition	#	
targetState
tr =	tr
JOIN
sm st
SM1 S11
SM1 S12
SM2 S21
SM2 FS
st tr
S11 TC1
S11 TI
S12 TC2
tr to
TC1 S21
TI S12
TC2 FS
fr tr to
S11 TC1 S21
S11 TI S12
S12 TC2 FS
sm fr tr to
SM1 S11 TI S12
∏
stateOfMachine
∏
DSM
sm fr tr to
SM1 S11 TC1 S21
SM1 S11 TI S12
SM1 S12 TC2 FS
JOIN
0
1
Removing the other
tuples cannot remove (0)
Removing tuple (1)	results
in	the removal of	(0).
Slicing	Rete	Network
43
st =	fr
JOIN
st =	to
State	#	
outgoingTransition
Transition	#	
targetState
tr =	tr
JOIN
sm st
SM1 S11
SM1 S12
SM2 S21
SM2 FS
st tr
S11 TC1
S11 TI
S12 TC2
tr to
TC1 S21
TI S12
TC2 FS
fr tr to
S11 TC1 S21
S11 TI S12
S12 TC2 FS
sm fr tr to
SM1 S11 TI S12
∏
stateOfMachine
∏
DSM
sm fr tr to
SM1 S11 TC1 S21
SM1 S11 TI S12
SM1 S12 TC2 FS
JOIN
0
1
2
Removing tuple (2)	results
in	the removal of	(1).
Slicing	Rete	Network
44
st =	fr
JOIN
st =	to
State	#	
outgoingTransition
Transition	#	
targetState
tr =	tr
JOIN
sm st
SM1 S11
SM1 S12
SM2 S21
SM2 FS
st tr
S11 TC1
S11 TI
S12 TC2
tr to
TC1 S21
TI S12
TC2 FS
fr tr to
S11 TC1 S21
S11 TI S12
S12 TC2 FS
sm fr tr to
SM1 S11 TI S12
∏
stateOfMachine
∏
DSM
sm fr tr to
SM1 S11 TC1 S21
SM1 S11 TI S12
SM1 S12 TC2 FS
JOIN
0
1
2
3
Removing tuple (3)	results
in	the removal of	(2).
Slicing	Rete	Network
45
st =	fr
JOIN
st =	to
State	#	
outgoingTransition
Transition	#	
targetState
tr =	tr
JOIN
sm st
SM1 S11
SM1 S12
SM2 S21
SM2 FS
st tr
S11 TC1
S11 TI
S12 TC2
tr to
TC1 S21
TI S12
TC2 FS
fr tr to
S11 TC1 S21
S11 TI S12
S12 TC2 FS
sm fr tr to
SM1 S11 TI S12
∏
stateOfMachine
∏
DSM
sm fr tr to
SM1 S11 TC1 S21
SM1 S11 TI S12
SM1 S12 TC2 FS
JOIN
0
1
2
3
4
Removing tuple (4)	results
in	the removal of	(3).
Slicing	Rete	Network
46
st =	fr
JOIN
st =	to
State	#	
outgoingTransition
Transition	#	
targetState
tr =	tr
JOIN
sm st
SM1 S11
SM1 S12
SM2 S21
SM2 FS
st tr
S11 TC1
S11 TI
S12 TC2
tr to
TC1 S21
TI S12
TC2 FS
fr tr to
S11 TC1 S21
S11 TI S12
S12 TC2 FS
sm fr tr to
SM1 S11 TI S12
∏
stateOfMachine
∏
DSM
sm fr tr to
SM1 S11 TC1 S21
SM1 S11 TI S12
SM1 S12 TC2 FS
JOIN
0
1
2
3
4
5
Removing tuple (5)	results
in	the removal of	(1).
Slicing	Rete	Network
47
st =	fr
JOIN
st =	to
State	#	
outgoingTransition
Transition	#	
targetState
tr =	tr
JOIN
sm st
SM1 S11
SM1 S12
SM2 S21
SM2 FS
st tr
S11 TC1
S11 TI
S12 TC2
tr to
TC1 S21
TI S12
TC2 FS
fr tr to
S11 TC1 S21
S11 TI S12
S12 TC2 FS
sm fr tr to
SM1 S11 TI S12
∏
stateOfMachine
∏
DSM
sm fr tr to
SM1 S11 TC1 S21
SM1 S11 TI S12
SM1 S12 TC2 FS
JOIN
0
1
2
3
4
5
6
Removing tuple (6)	results
in	the removal of	(0).
Slicing	Rete	Network
48
st =	fr
JOIN
st =	to
State	#	
outgoingTransition
Transition	#	
targetState
tr =	tr
JOIN
sm st
SM1 S11
SM1 S12
SM2 S21
SM2 FS
st tr
S11 TC1
S11 TI
S12 TC2
tr to
TC1 S21
TI S12
TC2 FS
fr tr to
S11 TC1 S21
S11 TI S12
S12 TC2 FS
sm fr tr to
SM1 S11 TI S12
∏
stateOfMachine
∏
DSM
sm fr tr to
SM1 S11 TC1 S21
SM1 S11 TI S12
SM1 S12 TC2 FS
JOIN
0
1
2
3
4
5
6
Formalization	Overview
§ Slice	Formalization
o Basis:	a	chain	of	semantic	mappings
o Main	contribution:	the	slice	formula
49
Graph
Patterns
Rete
Networks
Terms
Rel Alg
Rete
Changes
Terms
Query Alg
Terms
Change Alg
Rete
Slices
Formula
Graphs
Terms
Graph Alg
matchedOn derivedFrom
uses
Formalization	Overview
§ Slice	Formalization
o Basis:	a	chain	of	semantic	mappings
o Main	contribution:	the	slice	formula
50
Graph
Patterns
Rete
Networks
Terms
Rel Alg
Rete
Changes
Terms
Query Alg
Terms
Change Alg
Rete
Slices
Formula
Graphs
Terms
Graph Alg
matchedOn derivedFrom
uses
Instance models
&	metamodels
Formalization	Overview
§ Slice	Formalization
o Basis:	a	chain	of	semantic	mappings
o Main	contribution:	the	slice	formula
51
Graph
Patterns
Rete
Networks
Terms
Rel Alg
Rete
Changes
Terms
Query Alg
Terms
Change Alg
Rete
Slices
Formula
Graphs
Terms
Graph Alg
matchedOn derivedFrom
uses
Graph patterns
&	constraints
Formalization	Overview
§ Slice	Formalization
o Basis:	a	chain	of	semantic	mappings
o Main	contribution:	the	slice	formula
52
Graph
Patterns
Rete
Networks
Terms
Rel Alg
Rete
Changes
Terms
Query Alg
Terms
Change Alg
Rete
Slices
Formula
Graphs
Terms
Graph Alg
matchedOn derivedFrom
uses
(Rete)	Cache	for
relational algebra
Formalization	Overview
§ Slice	Formalization
o Basis:	a	chain	of	semantic	mappings
o Main	contribution:	the	slice	formula
53
Graph
Patterns
Rete
Networks
Terms
Rel Alg
Rete
Changes
Terms
Query Alg
Terms
Change Alg
Rete
Slices
Formula
Graphs
Terms
Graph Alg
matchedOn derivedFrom
uses
Incremental
update	formula	
for Rete nodes
Formalization	Overview
§ Slice	Formalization
o Basis:	a	chain	of	semantic	mappings
o Main	contribution:	the	slice	formula
54
Graph
Patterns
Rete
Networks
Terms
Rel Alg
Rete
Changes
Terms
Query Alg
Terms
Change Alg
Rete
Slices
Formula
Graphs
Terms
Graph Alg
matchedOn derivedFrom
uses
Formula	derived
for slicing criteria
The	Slice	Formula
§ Derived	in	Disjunctive Normal Form
o Cases	of	disjunction	represent	possible	changes
o The	conjunction	describe	the	chain	of	operations
§ The	resulting	formula	is	easy	to	understand
55
The	Slice	Formula
§ Derived	in	Disjunctive Normal Form
o Cases	of	disjunction	represent	possible	changes
o The	conjunction	describe	the	chain	of	operations
§ The	resulting	formula	is	easy	to	understand
56
The	Slice	Formula
§ Derived	in	Disjunctive Normal Form
o Cases	of	disjunction	represent	possible	changes
o The	conjunction	describe	the	chain	of	operations
§ The	resulting	formula	is	easy	to	understand
57
We	want to remove a	tuple
from node n6	where the
4th	parameter is	S12.
The	Slice	Formula
§ Derived	in	Disjunctive Normal Form
o Cases	of	disjunction	represent	possible	changes
o The	conjunction	describe	the	chain	of	operations
§ The	resulting	formula	is	easy	to	understand
58
The	slicer has	found four
possible changes.
The	Slice	Formula
§ Derived	in	Disjunctive Normal Form
o Cases	of	disjunction	represent	possible	changes
o The	conjunction	describe	the	chain	of	operations
§ The	resulting	formula	is	easy	to	understand
59
By removing the input	
tuple <TI,	S11>...
The	Slice	Formula
§ Derived	in	Disjunctive Normal Form
o Cases	of	disjunction	represent	possible	changes
o The	conjunction	describe	the	chain	of	operations
§ The	resulting	formula	is	easy	to	understand
60
By removing the input	
tuple <TI,	S11>...
...	the followingoperations
provide the removal of	the
expected tuple from n6.
Summary
Context:	Debugging of	MT
• Extensive support in VIATRA
• Challenge:	debugging graph patterns
Background:	MT	Slicing
• Compute dependencies based on a	slicing condition
• Model +	MT	program
This paper:
• Rete networks cache	matches of	patterns
• Slicing Rete networks
• Identify input	changes resulting in a	certain output	change
• Formalization by a	chain of	mappings
61

Rete network slicing for Model Queries