mcgill university school of computer science ‘07 eugene syriani and hans vangheluwe mcgill...
TRANSCRIPT
McGill UniversitySchool of Computer Science
1
‘07
Programmed Graph Rewriting with DEVS
Eugene Syrianiand
Hans Vangheluwe
McGill UniversitySchool of Computer Science
Programmed Graph Rewriting with DEVS
2
‘07
OVERVIEW
In the context
Overview of the Discrete EVent system
Specification (DEVS) formalism
Building example with AToM3
Graph Rewriting Control Flow (GRCF):
Mimic AToM3 and beyond
Summary
Programmed Graph Rewriting with DEVS
3
‘07
IN THE CONTEXT• Model transformation: Programmed Graph
Rewriting
• At least as expressive as: GreAT, VMTS, Fujaba, ProGreS, MOFLONSequencing, Branching, Looping, Hierarchy, Parallelism
• Cleanly tear apart– Transformation entities– Control flow, structure, hierarchy
• DEVS gives us time and modularity too
Programmed Graph Rewriting with DEVS
4
‘07
OVERVIEW
In the context
Overview of the Discrete EVent system
Specification (DEVS) formalism
Building example with AToM3
Graph Rewriting Control Flow (GRCF):
Mimic AToM3 and beyond
Summary
Programmed Graph Rewriting with DEVS
5
‘07
OVERVIEW OF THE DEVS FORMALISM• Bernard Zeigler, late ‘70s
• Basis for compositional modelling and simulation of discrete event systems
• Design, performance analysis and implementation
Programmed Graph Rewriting with DEVS
6
‘07
OVERVIEW OF THE DEVS FORMALISM
• Block: Atomic / Coupled
• Port: Inport / Outport
• Event
• Global time
Programmed Graph Rewriting with DEVS
7
‘07
OVERVIEW OF THE DEVS FORMALISM
Atomic DEVS:– Time Advance– Output Function– Internal Transition– External Transition
ATOMIC
Programmed Graph Rewriting with DEVS
8
‘07
OVERVIEW OF THE DEVS FORMALISMCoupled DEVS
CA1
A2
A3
Programmed Graph Rewriting with DEVS
9
‘07
C
OVERVIEW OF THE DEVS FORMALISM
Coupled DEVS:– Select Function
A1
A2
Programmed Graph Rewriting with DEVS
10
‘07
OVERVIEW OF THE DEVS FORMALISM
class AExample(AtomicDEVS):
def __init__(self):
self.state = ExampleState() self.in = self.addInPort()
self.out = self.addOutPort()
def extTransition(self):
X = self.peak(self.in)
...
return self.state
def intTransition(self):
...
return self.state
def outputFnc(self):
...
self.poke(self.out, Y)
def timeAdvance(self):
return 1
Our implementation: pythonDEVSclass CExample(CoupledDEVS):
def __init__(self):
self.M1 = self.addSubModel(Example())
self.M2 = self.addSubModel(Example())
self.connectPorts(self.M1.out, self.M2.in)
def select(self, immList):
return immList[0]
Programmed Graph Rewriting with DEVS
11
‘07
OVERVIEW
In the context
Overview of the Discrete EVent system
Specification (DEVS) formalism
Building example with AToM3
Graph Rewriting Control Flow (GRCF):
Mimic AToM3 and beyond
Summary
Programmed Graph Rewriting with DEVS
12
‘07
BUILDING EXAMPLE WITH ATOM3 [1]
Simplified PacMan formalism [2]
[1] de Lara J., Vangheluwe H., AToM3: A tool for multi-formalism and meta-modelling, LNCS (2002), 174-188[ 2] Heckel R., Graph Transformation in a nutshell, ENTCS (2006), 187-198
Programmed Graph Rewriting with DEVS
13
‘07
BUILDING EXAMPLE WITH ATOM3
Build the Meta-Model of the PacMan formalism
Programmed Graph Rewriting with DEVS
14
‘07
BUILDING EXAMPLE WITH ATOM3
Build the Graph Grammar
Programmed Graph Rewriting with DEVS
15
‘07
BUILDING EXAMPLE WITH ATOM3
Build the Graph Grammar
14
2
1
2
5 pacLink
3
ghostLink
3
ghostLink
1: return self.LHS.nodeWithLabel(1).score + 1
1
2
3
1
2
35
4
pacLink
foodLink
6
4
pacLink
P 1
P 2
Programmed Graph Rewriting with DEVS
16
‘07
BUILDING EXAMPLE WITH ATOM3
Build the Graph Grammar
4
1 2
36
gridLeft
ghostLink
1 2
3
4
7
gridLeft
ghostLink
4
1 2
5
gridRight
pacLink
1 2
4
6
gridRight
pacLink
33
P 3
P 3
Programmed Graph Rewriting with DEVS
17
‘07
BUILDING EXAMPLE WITH ATOM3
Programmed Graph Rewriting with DEVS
18
‘07
BUILDING EXAMPLE WITH ATOM3
• Capture a trace of execution– Keep log of used rules
Programmed Graph Rewriting with DEVS
19
‘07
OVERVIEW
In the context
Overview of the Discrete EVent system
Specification (DEVS) formalism
Building example with AToM3
Graph Rewriting Control Flow (GRCF):
Mimic AToM3 and beyond
Summary
Programmed Graph Rewriting with DEVS
20
‘07
GRAPH REWRITING CONTROL FLOW• DEVS blocks– Atomic block: encapsulate the graph rewriting rule
– Coupled block: encapsulate the graph grammar
• Events– Inport: recieve the host graph
– Outport(s): send the transformed graph
Programmed Graph Rewriting with DEVS
21
‘07
GRAPH REWRITING CONTROL FLOW
Programmed Graph Rewriting with DEVS
22
‘07
Trace
GRAPH REWRITING CONTROL FLOW
Model AToM3’s graph transformation engineUserInput
Control
Graph Transformation
Rules
Input graph Step
Send graph to transform
Transformed graph
Rules used
Programmed Graph Rewriting with DEVS
23
‘07
GRAPH REWRITING CONTROL FLOW
Graph transformation engineUserInput
g_out out_stepdone_rcv
Controllerg_init done_send in_step
g_out
g_modified
g_unmodified
Trace
g_in g_succeed
match_fail
match_succeed
g_in
match_fail
trace
trace
g_in
g_fail
trace
GGRule
GGRule
match_succeed
GGRules
Programmed Graph Rewriting with DEVS
24
‘07
GRAPH REWRITING CONTROL FLOWManaging priorities
g_in
GGRules
Synchronizer
match_fail
g_in
g_in
abort
match_succeed
Priority ng_in
abort
abort
out_fail
match_failGGRule GGRule
match_succeed
in_success in_fail
out_success g_succeed
g_fail
GGRule
Priority n+1
Non-determinism:Randomize select function
Programmed Graph Rewriting with DEVS
25
‘07
GRAPH REWRITING CONTROL FLOWUse compiled version of AToM3’s rule
class pacDie:
...
Programmed Graph Rewriting with DEVS
26
‘07
import compiled rules…
GRAPH REWRITING CONTROL FLOW
class AExample(AtomicDEVS):
def __init__(self):
self.state = ExampleState() self.in = self.addInPort()
self.out = self.addOutPort()
def extTransition(self):
X = self.peak(self.in)
...
return self.state
def intTransition(self):
...
return self.state
def outputFnc(self):
...
self.poke(self.out, Y)
def timeAdvance(self):
return 1
Programmed Graph Rewriting with DEVS
27
‘07
GRAPH REWRITING CONTROL FLOWExtension of AToM3’s graph transformation engine
g_out out_step
g_init done_send in_step
done_rcv
g_out
g_succeed
g_failg_in
AutonomousRules
Usercontrolled
Rules
g_fail
g_modifiedg_unmodified
g_in
out_control
control_out
control_in
Controller
User
in_control
Programmed Graph Rewriting with DEVS
28
‘07
GRAPH REWRITING CONTROL FLOWExtension of AToM3’s graph transformation engine
Up Down Left Right
g_incontrol_in
key g_in
g_up
g_down
g_in
match_succeedmatch_fail
g_in
match_succeedmatch_fail
g_in
match_succeedmatch_fail
g_in
match_fail
Dispatchg_left
out_fail
in_successin_fail
out_success
g_succeedg_fail
User controlled Rules
match_succeed
g_right
Programmed Graph Rewriting with DEVS
29
‘07
Autonomous Rules
match_fail
g_in
match_fail
g_in
GRAPH REWRITING CONTROL FLOWExtension of AToM3’s graph transformation engine
g_in g_succeed
match_succeed
g_in
g_fail
Kill
Eat
Ghost Move
match_succeed
match_fail
match_succeed
Programmed Graph Rewriting with DEVS
30
‘07
OVERVIEW
In the context
Overview of the Discrete EVent system
Specification (DEVS) formalism
Building example with AToM3
Graph Rewriting Control Flow (GRCF):
Mimic AToM3 and beyond
Summary
Programmed Graph Rewriting with DEVS
31
‘07
SUMMARY
SequenceBranchingLoopingHierarchy + ModularityParallelism
Control flow structure properties satisfied
Programmed Graph Rewriting with DEVS
32
‘07
Are we at the right level of abstraction?Is it the way industry should go in
model transformation?
Programmed Graph Rewriting with DEVS
33
‘07
“[...] the rule execution semantics is similar to the execution semantics of asynchronous
dataflow graphs and DEVS, but with a difference in the hierarchical rule execution.
[...] the class diagrams Figs. 14 and 15 introduce the same concepts as found in DEVS.”
A. Agrawal et al. The design of a language for model transformations. SoSym, 2006
Programmed Graph Rewriting with DEVS
34
‘07
CONCLUSION AND FUTURE WORK
• DEVS is a sequential, deterministic formalism
• Parallel-DEVS
• Kiltera (CSP-like languages)
Parallelism
Programmed Graph Rewriting with DEVS
35
‘07
CONCLUSION AND FUTURE WORK
• Metric, Statistics
• Timed graph transformation
• Real-Time DEVS
Time
Programmed Graph Rewriting with DEVS
36
‘07
CONCLUSION AND FUTURE WORK
• Event-driven Graph Rewriting
• Modelling of the user
User - Events
Programmed Graph Rewriting with DEVS
37
‘07
CONCLUSION AND FUTURE WORK
• Optimization hints
• Information on the flow
• Replace python code by... Statechart?
• Multi-formalism
• Add an AI block in the autonomous rules
Some Extensions
Programmed Graph Rewriting with DEVS
38
‘07
GRAPH REWRITING CONTROL FLOW
class AExample(AtomicDEVS):
def __init__(self):
self.state = ExampleState()
self.in = self.addInPort()
self.out =
self.addOutPort()
def extTransition(self):
X = self.peak(self.in)
...
return self.state
return 1
e(AtomicDEVS):
def ___(self):
self.state = ExampleState()
self.in = self.addInPort()
self.out = hsdhfjhb
Sdvjvkv
Ds
v
return 1
classself.state =
ExampleState()sdvv
self.in = self.addInPort()
self.out =
self.addOutPort()
def extTransition(self):
X = self.peak(self.in)
...
return sdsdfsdfsdfsfsdfsdf
In AToM3 Outside AToM3