43
Hans Vangheluwe Eugene Syriani Modelling, Simulation and Design Lab McGill University

Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

Hans VangheluweEugene Syriani

Modelling, Simulation and Design LabMcGill University

Page 2: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

OVERVIEW Introduction

Context

Existing Programmed Graph Rewriting Systems

Graph transformation in AToM3’s by example

The Modular Timed Graph Transformation

(MoTif) system

Overview of the DEVS formalism

Meta-model, Code generation, Rule compilation & Usage

Mimic AToM3 & beyond

Conclusion and Future Work2

Page 3: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

CONTEXT• Meta-Model + Model Transformation + …

• Model Transformation ⇒ Graph Transformation

• Types of rule-based Graph Transformations [1]

– Unordered Graph Rewriting: non-deterministic, run till no more rules apply

– Ordered Graph Rewriting: explicit (partial) ordering of rules

– Event-driven Graph Rewriting: external ordering of rules

• Ordered Graph Rewriting can be generalized to ProgrammedProgrammed Graph Rewriting

3

[1] Blostein D., Fahmy H., Grbavec A., Practical Use of Graph Rewriting, Technical Report No. 95-373, 1995.

Page 4: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.), International Conference on Applications of Graph Transformations with Industrial Relevance (AGTIVE 2007). Lecture Notes in Computer Science. Springer-Verlag, Kassel (2007).

• Cleanly separate

1.Transformation entities2.Control flow, structure, hierarchy

• Graph transformation control flow primitives [1]

– Flow: Sequencing, Branching, Looping

– Structure: Parallelism, Hierarchy

– Essence: Time, Backtracking

ProgrammedProgrammed Graph Rewriting wish list

IN THE CONTEXT

4

Page 5: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

EXISTING PROGRAMMED GRAPH REWRITING SYSTEMSFrom UML to JAVA And Back Again (FUJABA) [4,5]

5

[4] Nickel U., Niere J., Zündorf A. Tool demonstration: The FUJABA environment, Proceedings of ICSE, ACM Press, pp. 742-745, 2000.[5] Fischer T. et al. Story Diagrams: an new graph grammar language based on UML and JAVA, Proceedings of ESEC, LNCS 1764, pp. 1-21, 2000.

Page 6: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

EXISTING PROGRAMMED GRAPH REWRITING SYSTEMS

MOFLON [6]

6[6] Amelunxen C. et al. Moflon: A standard compliant metamodeling framework with graph transformations, Proceedings of MDA – Foundations and Applications, LNCS 4066, pp. 361-375, 2006.

Page 7: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

EXISTING PROGRAMMED GRAPH REWRITING SYSTEMS

Graph Rewriting and Transformation (GReAT) [7,8,9]

7

[7] Vizhanyo A. et al., Towards generation of high-performance transformations, Proceedings of GPCE, LNCS 3286 pp. 298-396, 2004.[8] Agrawal A., Metamodel based model transformation language, Proceedings of OOPSLA, ACM Press pp. 386-397, 2003.[9] Agrawal A., The design of a language for model transformations, SoSym 5, pp. 261-288, 2005.

Page 8: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

Simplified PacMan formalism [13]

RUNNING EXAMPLE WITH AToM3 [12]

8

[12] de Lara J., Vangheluwe H., AToM3: A tool for multi-formalism and meta-modelling, LNCS (2002), 174-188[ 13] Heckel R., Graph Transformation in a nutshell, ENTCS (2006), 187-198

Page 9: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

Build the Meta-Model of the PacMan formalism

RUNNING EXAMPLE WITH AToM3

9

Page 10: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

Model the Graph Transformation

RUNNING EXAMPLE WITH AToM3

10

Page 11: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

Graph Transformation Rules

RUNNING EXAMPLE WITH ATOM3

11

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

Page 12: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

Graph Transformation Rules

RUNNING EXAMPLE WITH ATOM3

12

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

1

78

ghostLink

Page 13: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

RUNNING EXAMPLE WITH AToM3

13

Page 14: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

RUNNING EXAMPLE WITH ATOM3

• Capture execution trace:– Keep log of used rules

14

Page 15: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

OVERVIEW OF THE DEVS FORMALISM

• Bernard Zeigler, late ‘70s

• The Discrete Event System Specification [1] (DEVS) formalism

• DEVS is compositional

• Foundation for compositional modelling and simulation of discrete event systems

• DEVS:

– Blocks

– Ports

– Events

• Semantics: Parallel composition of blocks/models15

Page 16: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

OVERVIEW OF THE DEVS FORMALISM

• Block:

– Atomic

– Coupled

• Port:

– Inport

– Outport

• Event

• Global time

16

Page 17: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

OVERVIEW OF THE DEVS FORMALISM

17

Atomic DEVS:– Time Advance– Output Function– Internal Transition–External Transition

ATOMIC

Page 18: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

Coupled DEVS

OVERVIEW OF THE DEVS FORMALISM

18

CA1

A2

A3

Page 19: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

C

OVERVIEW OF THE DEVS FORMALISM

19

Coupled DEVS:– Select Function

A1

A2

Page 20: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

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: pythonDEVS

OVERVIEW OF THE DEVS FORMALISM

20

class 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]

Page 21: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MoTif

• DEVS blocks– Atomic block: encapsulate the graph

rewriting rule

– Coupled block: encapsulate a structured collection of rules (graph transformation)

• Events– Inport: receive the host graph

– Outport(s): send the transformed graph

21

Page 22: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MOTIF META-MODEL

22

Page 23: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MOTIF MODELLING ENVIRONMENT

23

CRule PortsAtomic Rule

SynchronizerCoupled Rule

Atomic DEVS

Coupled DEVS

pyDEVS Generator

Page 24: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MODEL AToM3’S GRAPH TRANSFORMATION ENGINE

24

Input Input graphgraph StepStep

Send graph to Send graph to transformtransform

Transformed Transformed graphgraph

Rules usedRules used

Page 25: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

GRAPH TRANSFORMATION ENGINE

25

g_outg_out out_stepout_stepdone_rcvdone_rcv

g_initg_init done_senddone_send in_stepin_step

g_outg_out

g_modifieg_modifiedd

g_unmodifieg_unmodifiedd

g_ing_in g_succeeg_succeeddmatch_fmatch_f

ailail

match_succmatch_succeedeed

g_ing_in

match_fmatch_failail

tracetrace

tracetrace

g_ing_in

g_failg_fail

tracetrace

match_succmatch_succeedeed

Page 26: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MANAGING PRIORITIES

26

g_ing_in

match_fmatch_failail

g_ing_in

g_ing_in

aborabortt

match_succematch_succeeded

Priority Priority nng_ing_in

aborabortt

abortabort

out_failout_fail

match_fmatch_failail

match_succematch_succeeded

in_succein_successss

in_failin_fail

out_succeout_successss

g_succeeg_succeedd

g_failg_fail

Priority Priority n+1n+1

Non-determinism:Randomize select function

Page 27: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MoTif & AToM3

class Pacmandie:

...

Page 28: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MoTif EXECUTION

COMPILE

GENERATE

IMPORT

SIMULATEclass Kill(ARule): def __init__(self): ARule.__init__(self, name=‘Kill') self.state = ARuleState(Pacdie()) def weightFunction(self): return 1.0

class Pacmanmoveri: def match(): … def execute(): …

class Pacmandie:

def match(): … …

28

Page 29: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

EXTENSION OF ATOM3’S GRAPH TRANSFORMATION ENGINE

29

g_outg_out out_stepout_step

g_initg_init done_sendone_sendd

in_stepin_step

done_rcdone_rcvv

g_outg_out

g_succeg_succeeded

g_failg_failg_ing_in g_failg_fail

g_modifieg_modifiedd

g_unmodifig_unmodifieded

g_ing_in

out_controut_controlol

control_oucontrol_outt

control_icontrol_inn

in_contrin_controlol

Page 30: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MODELLING OF THE TRANSFORMATION: SYSTEM

• User – Controller – Autonomous loop

• Feed-back to User

• On User interrupt: User Controlled

• Feed-back to User

Autonomous UserControlled

30

Page 31: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MODELLING OF THE TRANSFORMATION: AUTONOMOUS CRule

Priorities

31

Page 32: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MODELLING OF THE TRANSFORMATION: GHOSTMOVE CRule

Decider finds the next move for the ghost

Decider consumes time

32

Page 33: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MODELLING OF TRANSFORMATION: SYSTEM

Autonomous UserControlled

33

Page 34: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MODELLING OF THE TRANSFORMATION: USERCONTROLLED CRule

Conditional rule execution34

Page 35: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MODELLING OF THE TRANSFORMATION: SYSTEM

Autonomous UserControlled

35

Page 36: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

MODELLING OF ENVIRONMENT: USER CoupledBlock

UserBehavior

UserInteraction

•Customization

•Modularity

36

Page 37: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

BACKTRACKING• What?What?

Algorithmically, used for exploring a search space

• Why?Why?In graph transformation, needed when a non-deterministic choice is made– Matching level

– Rule level

• How?How?– Make copies of the graph

– Use checkpoints and transactions

– Have undo/inverse transformations37

Page 38: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

BACKTRACKING

• Next Mode event:– Cumulative

– Roll-back38

Page 39: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

SequenceBranchingLoopingHierarchy + Modularity(pseudo-)ParallelismBacktrackingTime

Control flow structure properties satisfied

SUMMARY

39

Page 40: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

• Event-driven Graph Rewriting

• Modelling of the user

Web-based pacman game– AJAX

– SVG

– Real-time

User - Events

ONE STEP FURTHER

40

Page 41: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

ONE STEP FURTHER

• Metric, Statistics

• Timed graph transformation

• Real-Time DEVS

Time

41

Page 42: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

• Optimization (rule compilation)

• Replace transformation blocks by Statecharts, code, ...

• Integrate MoTif in AToM3: 2-way communication

• Scaling for larger models:– Database

– Distributed

Some Extensions

FUTURE WORK

42

Page 43: Hans Vangheluwe Eugene Syriani Modelling, Simulation and ......1. Eugene Syriani and Hans Vangheluwe: Programmed Graph Rewriting with DEVS. In: Manfred Nagl and Andy Schürr (eds.),

• DEVS is a sequential formalism– Parallel-DEVS

– Kiltera (CSP-like languages)

• Distributed rule application

Parallelism

FUTURE WORK

43

Variable Structure Formalisms