Top Banner
Parallel DEVS An Introduction Using PythonPDEVS Yentl Van Tendeloo, Hans Vangheluwe
58

Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

May 01, 2018

Download

Documents

trinhtuyen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Parallel DEVSAn Introduction Using PythonPDEVS

Yentl Van Tendeloo, Hans Vangheluwe

Page 2: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Introduction

Page 3: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Bernard P. Zeigler.

Theory Of Modelling And Simulation.

1st ed. Wiley, 1976.

Bernard P. Zeigler, Herbert Praehofer,

and Tag Gon Kim.

Theory Of Modelling And Simulation.

2nd ed. Academic Press, 2000.

Bernard P. Zeigler.

Multifacetted Modelling and

Discrete Event Simulation.

1st ed. Academic Press, 1984.

Page 4: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Alex ChungHen Chow.

Parallel DEVS: a parallel, hierarchical, modular

modeling formalism and its distributed simulator.

Transactions of the Society for Computer

Simulation. 1996; 13(2): 55-68.

Alex ChungHen Chow, Bernard P. Zeigler and Doo

Hwan Kim.

Abstract simulator for the parallel DEVS formalism.

Fifth Annual Conference on AI, and Planning in High

Autonomy Systems. 1994, pp. 157-163.

Page 5: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Yentl Van Tendeloo and Hans Vangheluwe.

An Evaluation of DEVS Simulation Tools.

Simulation: Transactions of the Society

for Modeling and Simulation International.

2017, 93(2): 103-121

Yentl Van Tendeloo and Hans Vangheluwe.

An Overview of PythonPDEVS.

In Proceedings of Journées DEVS

Francophones (JDF), pages 59-66, 2016.

Page 6: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Our presentation uses initialized DEVS models, which

contain an initial state. The initial state was left

implicit in the original DEVS specification.

Page 7: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

DEVS

GPSS

Meijin++

SimScript

Sequential Discrete Event Language

= modular simulation assembly language

Page 8: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Vangheluwe, Hans. DEVS as a common denominator for multi-formalism hybrid systems modelling.In proceedings of the International Symposium on Computer-Aided Control System Design, pp. 129-134. 2000.

Page 9: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

t

t

X

Y

𝑥1

𝑥2

𝑦1𝑦2

finite number of non-𝜙 events

𝜙

𝜙

in a finite time interval

Page 10: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

t

t

t

X

S

Y

𝑥1

𝑥2

𝑦1𝑦2

𝑠1

𝑠2

𝑠3

𝑠4

𝜙

𝜙

Page 11: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.
Page 12: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Experimentation

Page 13: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Simulation

Experiment

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑 = 60𝑠𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤 = 3𝑠

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛 = 57𝑠

𝑐𝑜𝑛𝑑𝑡𝑒𝑟𝑚𝑖𝑛𝑎𝑡𝑖𝑜𝑛 = (𝑡𝑠𝑖𝑚 ≥ 𝑡𝑒𝑛𝑑)𝑡𝑒𝑛𝑑 = 24ℎ

Trace

Model

Solver

Model

Simulator

Page 14: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

from pypdevs.simulator import Simulator

from mymodel import MyModel

model = MyModel()

simulator = Simulator(model)

simulator.setVerbose()

simulator.simulate()

simple_experiment.pyConcrete Syntax

Page 15: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

__ Current Time: 0.00 ______________________________________

INITIAL CONDITIONS in model <trafficSystem.trafficLight>

Initial State: red

Next scheduled internal transition at time 58.50

INITIAL CONDITIONS in model <trafficSystem.policeman>

Initial State: idle

Next scheduled internal transition at time 200.00

__ Current Time: 58.50 ______________________________________

INTERNAL TRANSITION in model <trafficSystem.trafficLight>

New State: green

Output Port Configuration:

port <OBSERVED>:

grey

Next scheduled internal transition at time 108.50

__ Current Time: 108.50 ______________________________________

INTERNAL TRANSITION in model <trafficSystem.trafficLight>

New State: yellow

Output Port Configuration:

port <OBSERVED>:

yellow

Next scheduled internal transition at time 118.50

Page 16: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Atomic Models

Page 17: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

t

t

X

Y

𝑥1

𝑥2

𝑦1𝑦2

?𝜙

𝜙

Page 18: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Modelling Discrete Event Behaviour

Finite State Automaton Timed Event Scheduling Graph

toRed

toGreen

toYellow

red

green

yellow schedule

in 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

schedule

in 𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

schedule

in 𝑑𝑒𝑙𝑎𝑦_𝑔𝑟𝑒𝑒𝑛

𝑒 = 0𝑠

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

toRed

toYellow

toGreen

𝑒 = 0𝑠

Page 19: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

X

Y

t

t

S

t5760

120 177

red

yellow

green

Page 20: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

𝑆 : set of sequential states

𝑆 = {red, yellow, green}

𝛿𝑖𝑛𝑡 : 𝑆 → 𝑆𝛿𝑖𝑛𝑡 = {red → green,

green → yellow,

yellow → red}

𝑡𝑎 : S → ℝ0,+∞

𝑡𝑎 = {red → 𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑,

green → 𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛,

yellow → 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤}

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑀 = , , ,𝑆 𝛿𝑖𝑛𝑡 𝑡𝑎

Autonomous (no input)

Page 21: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Time Advance: corner cases

𝑡𝑎 : S → ℝ0,+∞

𝑡𝑎 𝑠𝑖 = +∞

passive states

𝑡𝑎 𝑠𝑖 = 0

transient states

!

Page 22: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Elapsed time

e

t

𝑡𝑎(𝑔𝑟𝑒𝑒𝑛)

𝑡𝑎(𝑦𝑒𝑙𝑙𝑜𝑤)

𝑡𝑎(𝑟𝑒𝑑)

… …

Page 23: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Elapsed time

S

t

red

yellow

green

… …

ta(𝑠𝑖)

𝜎𝑖𝑒𝑖

Page 24: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Initialization of Initial State

S

t

red

yellow

green

𝑡𝑎(𝑠0)

𝑒0 𝜎0

𝑠0, 0 𝑞𝑖𝑛𝑖𝑡 = 𝑠0, 𝑒0 𝑠0, 𝑡𝑎 𝑠0

Page 25: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Elapsed time

e

t

𝑡𝑎(𝑔𝑟𝑒𝑒𝑛)

𝑡𝑎(𝑦𝑒𝑙𝑙𝑜𝑤)

𝑡𝑎(𝑟𝑒𝑑)

0

𝑒0

𝑡𝑎 𝑠0

Page 26: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

𝑆 : set of sequential states

𝑆 = {red, yellow, green}

𝛿𝑖𝑛𝑡 : 𝑆 → 𝑆𝛿𝑖𝑛𝑡 = {red → green,

green → yellow,

yellow → red}

𝑡𝑎 : S → ℝ0,+∞

𝑡𝑎 = {red → 𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑,

green → 𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛,

yellow → 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤}

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑀 = , , ,𝑆 𝛿𝑖𝑛𝑡 𝑡𝑎𝑞𝑖𝑛𝑖𝑡

𝑞𝑖𝑛𝑖𝑡 : 𝑄 – set of total states

𝑄 = 𝑠, 𝑒 𝑠 ∈ 𝑆, 0 ≤ 𝑒 ≤ 𝑡𝑎(𝑠)𝑞𝑖𝑛𝑖𝑡 = (green, 0)

Autonomous (no output)

𝑒 = 0𝑠

Page 27: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

𝑆 = {red, yellow, green}

𝛿𝑖𝑛𝑡 = { red → green,

green → yellow,

yellow → red}

𝑡𝑎 = {red → 𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑,

green → 𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛,

yellow → 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤}

𝑞𝑖𝑛𝑖𝑡 = (green, 0)

time = 0

current_state = initial_state

last_time = -initial_elapsed

while not termination_condition():

time = last_time + ta(current_state)

current_state = 𝛿𝑖𝑛𝑡(current_state)

last_time = time

Operational Semantics

from pypdevs.DEVS import *

class TrafficLightAutonomous(AtomicDEVS):

def __init__(self, delay_green,

delay_yellow, delay_red):

AtomicDEVS.__init__(self, “Light”)

self.state = “green”

self.elapsed = 0

self.delay_green = delay_green

self.delay_yellow = delay_yellow

self.delay_red = delay_red

def intTransition(self):

state = self.state

return {“red”: “green”,

“yellow”: “red”,

“green”: “yellow”}[state]

def timeAdvance(self):

state = self.state

return {“red”: self.delay_red,

“yellow”: self.delay_yellow,

“green”: self.delay_green}[state]

atomic_int.pyConcrete SyntaxAbstract Syntax

Page 28: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

!show_red

!show_yellow

!show_green

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

X

S

Y

t

t

t

5760

120 177

red

yellow

green

show_red

show_yellow

show_green𝑒 = 0𝑠

Page 29: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

!show_red

!show_yellow

!show_green

𝑆 = {red, yellow, green}

𝛿𝑖𝑛𝑡 = { red → green,

green → yellow,

yellow → red}

𝑞𝑖𝑛𝑖𝑡 = (green, 0)

𝑡𝑎 = {red → 𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑,

green → 𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛,

yellow → 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤}

𝑌 : set of output events

𝑌 = {“show_red”, “show_green”, “show_yellow”}

𝜆 : 𝑆 → 𝑌𝑏

𝜆 = { green → [“show_yellow”],

yellow → [“show_red”],

red → [“show_green”]}

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑀 = , 𝑆, 𝑞𝑖𝑛𝑖𝑡, 𝛿𝑖𝑛𝑡, , 𝑡𝑎𝑌 𝜆

Autonomous (with output)

𝑒 = 0𝑠

Page 30: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

𝑆 = {red, yellow, green}

𝑞𝑖𝑛𝑖𝑡 = (green, 0)

𝛿𝑖𝑛𝑡 = { red→ green,

green → yellow,

yellow → red}

𝑡𝑎 = {red→ 𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑,

green → 𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛,

yellow → 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤}

𝑌 = {“show_red”,

“show_green”,

“show_yellow”}

𝜆 = {green → [“show_yellow”],

yellow → [“show_red”],

red → [“show_green”]}

time = 0

current_state = initial_state

last_time = -initial_elapsed

while not termination_condition():

time = last_time + ta(current_state)

output(𝜆(current_state))

current_state = 𝛿𝑖𝑛𝑡(current_state)

last_time = time

Operational Semantics

from pypdevs.DEVS import *

class TrafficLightWithOutput(AtomicDEVS):

def __init__(self):

AtomicDEVS.__init__(self, “light”)

self.observe = self.addOutPort(“observer”)

def outputFnc(self):

state = self.state

if state == “red”:

return {self.observe: [“show_green”]}

elif state == “yellow”:

return {self.observe: [“show_red”]}

elif state == “green”:

return {self.observe: [“show_yellow”]}

atomic_out.pyConcrete Syntax

Abstract Syntax

Page 31: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

!show_red

!show_yellow

!show_green

?manual

?manual

?manual

?auto

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛

∞ 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

X

S

Y

t

t

t

red

manual

green

show_green

manual

auto

𝑒 = 0𝑠

yellow

Page 32: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

!show_red

!show_yellow

!show_green

?manual

?manual

?manual

?auto

𝑌 = {“show_red”, “show_green”, “show_yellow”}

𝑆 = {red, yellow, green, manual}

𝑞𝑖𝑛𝑖𝑡 = (green, 0)

𝛿𝑖𝑛𝑡 = {red → green,

green → yellow,

yellow → red}

𝜆 = {green → [“show_yellow”],

yellow → [“show_red”],

red → [“show_green”]}

𝑡𝑎 = {red → 𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑,

green → 𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛,

yellow → 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤,

manual → ∞}

𝛿𝑒𝑥𝑡 : Q × 𝑋𝑏 → 𝑆𝑄 = 𝑠, 𝑒 𝑠 ∈ 𝑆, 0 ≤ 𝑒 ≤ 𝑡𝑎(𝑠)𝛿𝑒𝑥𝑡 = {( (*, *), [“toManual”])→ “manual”,

( (“manual”, *), [“toAuto”]) → “red”}

𝑋 : set of input events

𝑋 = {“toAuto”, “toManual”}

𝑋 𝛿𝑒𝑥𝑡

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛

∞ 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑀 = , 𝑌, 𝑆, 𝑞𝑖𝑛𝑖𝑡, 𝛿𝑖𝑛𝑡, , 𝜆, 𝑡𝑎

Reactive

𝑒 = 0𝑠

Page 33: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

𝑌 = {“show_red”, “show_green”, “show_yellow”}

𝑆 = {red, yellow, green, manual}

𝑞𝑖𝑛𝑖𝑡 = (green, 0)

𝛿𝑖𝑛𝑡 = {red → green,

green → yellow,

yellow → red}

𝜆 = {green → [“show_yellow”],

yellow → [“show_red”],

red → [“show_green”]}

𝑡𝑎 = {red → 𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑,

green → 𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛,

yellow → 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤,

manual→ ∞}

𝑋 = {“toAuto”, “toManual”}

𝛿𝑒𝑥𝑡 = {( (*, *), [“toManual”])→ “manual”,

( (“manual”, *), [“toAuto”]) → “red”}

time = 0

cur_state = initial_state

last_time = -initial_elapsed

while not termination_condition():

next_time = last_time + ta(cur_state)

if time_next_ev <= next_time:

e = time_next_ev – last_time

time = time_next_ev

cur_state = 𝛿𝑒𝑥𝑡((cur_state, e), next_ev)

else:

time = next_time

output(𝜆(current_state))

current_state = 𝛿_𝑖𝑛𝑡(current_state)

last_time = time

Operational Semantics

Abstract Syntax

Page 34: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

from pypdevs.DEVS import *

class TrafficLight(AtomicDEVS):

def __init__(self):

AtomicDEVS.__init__(self, “light”)

self.interrupt = self.addInPort(“interrupt”)

def extTransition(self, inputs):

inp = inputs[self.interrupt][0]

if inp == “toManual”:

return “manual”

elif inp == “toAuto”:

if self.state == “manual”:

return “red”

atomic_ext.pyConcrete Syntax

𝑌 = {“show_red”, “show_green”, “show_yellow”}

𝑆 = {red, yellow, green, manual}

𝑞𝑖𝑛𝑖𝑡 = (green, 0)

𝛿𝑖𝑛𝑡 = {red → green,

green → yellow,

yellow → red}

𝜆 = {green → [“show_yellow”],

yellow → [“show_red”],

red → [“show_green”]}

𝑡𝑎 = {red → 𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑,

green → 𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛,

yellow → 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤,

manual→ ∞}

𝑋 = {“toAuto”, “toManual”}

𝛿𝑒𝑥𝑡 = {( (*, *), [“toManual”])→ “manual”,

( (“manual”, *), [“toAuto”]) → “red”}

Abstract Syntax

Page 35: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

!show_red

!show_yellow

!show_green

?toManual/

!turn_off

?toManual/

!turn_off

?toManual/

!turn_off

?toAuto/

!show_red

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛

∞ 𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑒 = 0𝑠

X

S

Y

t

t

t

red

manual

green

show_green

toManual

toAuto

yellow

show_red

turn_off

Page 36: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

!show_red

!show_yellow

!show_green

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛0

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑒 = 0𝑠

0

!show_red

!turn_off

?toAuto?toManual

?toManual

?toManual

X

S

Y

t

t

t

red

manual

green

show_green

toManual

toAuto

going_auto

show_red

turn_off

going_manual

Page 37: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

𝑄 = 𝑠, 𝑒 𝑠 ∈ 𝑆, 0 ≤ 𝑒 ≤ 𝑡𝑎(𝑠)

𝑒 = 0 0 < 𝑒 < 𝑡𝑎(𝑠) 𝑒 = 𝑡𝑎 𝑠

?

𝛿𝑐𝑜𝑛𝑓 : 𝑆 × 𝑋𝑏 → 𝑆

Page 38: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

from pypdevs.DEVS import *

class TrafficLight(AtomicDEVS):

def confTransition(self, inputs):

self.elapsed = 0.0

self.state = self.intTransition()

self.state = self.extTransition(inputs)

return self.state

atomic_conf.py

Page 39: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

𝑀 = 𝑋, 𝑌, 𝑆, 𝑞𝑖𝑛𝑖𝑡, 𝛿𝑖𝑛𝑡, 𝛿𝑒𝑥𝑡, 𝛿𝑐𝑜𝑛𝑓, 𝜆, 𝑡𝑎

𝑋 : set of input events

𝑌 : set of output events

𝑆 : set of sequential states

𝑞𝑖𝑛𝑖𝑡 : 𝑄𝑄 = 𝑠, 𝑒 𝑠 ∈ 𝑆, 0 ≤ 𝑒 ≤ 𝑡𝑎(𝑠)

𝛿𝑖𝑛𝑡 : 𝑆 → 𝑆𝛿𝑒𝑥𝑡: 𝑄 × 𝑋𝑏 → 𝑆𝛿𝑐𝑜𝑛𝑓: 𝑆 × 𝑋𝑏 → 𝑆

𝜆 : 𝑆 → 𝑌𝑏

𝑡𝑎 : 𝑆 → ℝ0,+∞+

Full Atomic DEVS Specification

Page 40: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

S

t

(𝑠𝑖 , 0)

𝑡𝑎 𝑠𝑖

(𝛿𝑒𝑥𝑡 𝑠𝑖 , 𝑒 , 𝑥 , 0)

(𝛿𝑖𝑛𝑡(𝑠𝑖), 0)

𝛿𝑒𝑥𝑡

𝛿𝑖𝑛𝑡

output 𝜆(𝑠𝑖)

𝑡𝑖 𝑡𝑖 + 𝑒 𝑡𝑖 + 𝑡𝑎 𝑠𝑖

𝑒

Page 41: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Coupled Models

Page 42: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

!show_red

!show_yellow

!show_green

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛0

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑒 = 0𝑠

0

!show_red

!turn_off

?toAuto?toManual

?toManual

?toManual

Page 43: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

work

3600s

idle

300s

!go_to_work !take_break

𝑒 = 0𝑠

Page 44: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

work

3600s

idle

300s

𝑀𝑖 𝑖 ∈ 𝐷𝑀𝑖 = 𝑋, 𝑌, 𝑆, 𝛿𝑖𝑛𝑡, 𝛿𝑒𝑥𝑡, 𝜆, 𝑡𝑎 , ∀ 𝑖 ∈ 𝐷

𝐶 = 𝐷, 𝑀𝑖

!go_to_work !take_break

𝑒 = 0𝑠

!show_red

!show_yellow

!show_green

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛0

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑒 = 0𝑠

0!show_red

!turn_off

?toAuto ?toManual

?toManual

?toManual

Page 45: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

work

3600s

idle

300s

𝑀𝑖 𝑖 ∈ 𝐷𝑀𝑖 = 𝑋, 𝑌, 𝑆, 𝛿𝑖𝑛𝑡, 𝛿𝑒𝑥𝑡, 𝜆, 𝑡𝑎 , ∀ 𝑖 ∈ 𝐷

𝐶 = 𝑋𝑠𝑒𝑙𝑓 , 𝑌𝑠𝑒𝑙𝑓 , 𝐷, 𝑀𝑖

!go_to_work !take_break

𝑒 = 0𝑠

!show_red

!show_yellow

!show_green

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛0

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑒 = 0𝑠

0!show_red

!turn_off

?toAuto ?toManual

?toManual

?toManual

Page 46: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

work

3600s

idle

300s

𝑀𝑖 𝑖 ∈ 𝐷𝑀𝑖 = 𝑋, 𝑌, 𝑆, 𝛿𝑖𝑛𝑡, 𝛿𝑒𝑥𝑡, 𝜆, 𝑡𝑎 , ∀ 𝑖 ∈ 𝐷

𝐶 = 𝑋𝑠𝑒𝑙𝑓 , 𝑌𝑠𝑒𝑙𝑓 , 𝐷, 𝑀𝑖 , 𝐼𝑖

𝐼𝑖 𝑖 ∈ 𝐷 ∪ 𝑠𝑒𝑙𝑓∀ 𝑖 ∈ 𝐷 ∪ 𝑠𝑒𝑙𝑓 ∶ 𝐼𝑖 ⊆ 𝐷 ∪ 𝑠𝑒𝑙𝑓

∀ 𝑖 ∈ 𝐷 ∪ 𝑠𝑒𝑙𝑓 ∶ 𝑖 ∉ 𝐼𝑖

!go_to_work !take_break

𝑒 = 0𝑠

!show_red

!show_yellow

!show_green

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛0

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑒 = 0𝑠

0!show_red

!turn_off

?toAuto ?toManual

?toManual

?toManual

Page 47: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

!go_to_work !take_break

work

3600s

idle

300s

𝑀𝑖 𝑖 ∈ 𝐷𝑀𝑖 = 𝑋, 𝑌, 𝑆, 𝛿𝑖𝑛𝑡, 𝛿𝑒𝑥𝑡, 𝜆, 𝑡𝑎 , ∀ 𝑖 ∈ 𝐷

𝐶 = 𝑋𝑠𝑒𝑙𝑓 , 𝑌𝑠𝑒𝑙𝑓 , 𝐷, 𝑀𝑖 , 𝐼𝑖 , 𝑍𝑖,𝑗

𝐼𝑖 𝑖 ∈ 𝐷 ∪ 𝑠𝑒𝑙𝑓∀ 𝑖 ∈ 𝐷 ∪ 𝑠𝑒𝑙𝑓 ∶ 𝐼𝑖 ⊆ 𝐷 ∪ 𝑠𝑒𝑙𝑓

∀ 𝑖 ∈ 𝐷 ∪ 𝑠𝑒𝑙𝑓 ∶ 𝑖 ∉ 𝐼𝑖

𝑍𝑖,𝑗 𝑖 ∈ 𝐷 ∪ 𝑠𝑒𝑙𝑓 , 𝑗 ∈ 𝐼𝑖𝑍𝑠𝑒𝑙𝑓,𝑗 ∶ 𝑋𝑠𝑒𝑙𝑓 → 𝑋𝑗 , ∀ 𝑗 ∈ 𝐷

𝑍𝑖,𝑠𝑒𝑙𝑓 ∶ 𝑌𝑖 → 𝑌𝑠𝑒𝑙𝑓 , ∀ 𝑖 ∈ 𝐷

𝑍𝑖,𝑗 ∶ 𝑌𝑖 → 𝑋𝑗 , ∀ 𝑖, 𝑗 ∈ 𝐷take_break toAuto

go_to_work toManual

𝑒 = 0𝑠

!show_red

!show_yellow

!show_green

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛0

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑒 = 0𝑠

0!show_red

!turn_off

?toAuto ?toManual

?toManual

?toManual

Page 48: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

from pypdevs.DEVS import *

from trafficlight import TrafficLight

from policeman import Policeman

def translate(in_evt):

mapping = {“take_break”: “toAuto”,

“go_to_work”: “toManual”}

return mapping[in_evt]

class TrafficLightSystem(CoupledDEVS):

def __init__(self):

CoupledDEVS.__init__(self, “system”)

self.light = self.addSubModel(TrafficLight())

self.police = self.addSubModel(Policeman())

self.connectPorts(self.police.out, self.light.interrupt, translate)

trafficlight_system.pyConcrete Syntax

Page 49: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Closure under Coupling

Page 50: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

!go_to_work !take_break

work

3600s

idle

300s

?

𝑒 = 0𝑠

!show_red

!show_yellow

!show_green

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛0

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑒 = 0𝑠

0!show_red

!turn_off

?toAuto ?toManual

?toManual

?toManual

Page 51: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

!go_to_work !take_break

work

3600s

idle

300s ?𝐶𝑀 = 𝑋𝑠𝑒𝑙𝑓 , 𝑌𝑠𝑒𝑙𝑓 , 𝐷, 𝑀𝑖 , 𝐼𝑖 , 𝑍𝑖,𝑗

𝑀𝑖 = 𝑋𝑖 , 𝑌𝑖 , 𝑆𝑖 , 𝛿𝑖𝑛𝑡,𝑖 , 𝛿𝑒𝑥𝑡,𝑖 , 𝜆𝑖 , 𝑡𝑎𝑖 , ∀ 𝑖 ∈ 𝐷𝐶𝑀 = 𝑋, 𝑌, 𝑆, 𝑞𝑖𝑛𝑖𝑡, 𝛿𝑖𝑛𝑡, 𝛿𝑒𝑥𝑡, 𝛿𝑐𝑜𝑛𝑓, 𝜆, 𝑡𝑎

𝑒 = 0𝑠

!show_red

!show_yellow

!show_green

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛0

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑒 = 0𝑠

0!show_red

!turn_off

?toAuto ?toManual

?toManual

?toManual

Page 52: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Hierarchical Simulator

Page 53: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

(done, t)

(*, t)

(done, t)

(y, t)

(x, t)

(@,t)

(@,t)

(*, t)

(done, t) (done, t)

(*, t)

Root coordinator

Coordinator

SimulatorSimulator

Coupled DEVS

Atomic DEVS Atomic DEVS

Page 54: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

DEVS Semantics

Atomic DEVS

Coupled DEVS

Operational

Semantics

Denotational

Semantics

Abstract

Simulator[1]

Hierarchical

Simulator

Closure under

Coupling

[1] Ashvin Radiya and Robert G. Sargent. A logic-based foundation of discrete event modeling

and simulation. ACM Transactions on Modeling and Computer Simulation, 1(1):3-51, 1994.

Page 55: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Conclusions

Atomic DEVS

Coupled DEVS

Closure under coupling

Abstract Simulator

(@,t) (X, t)(Y, t) (*, t) (done, t)

!go_to_work !take_break

work

3600s

idle

300s

!show_red

!show_yellow

!show_green

𝑑𝑒𝑙𝑎𝑦𝑟𝑒𝑑

𝑑𝑒𝑙𝑎𝑦𝑔𝑟𝑒𝑒𝑛0

𝑑𝑒𝑙𝑎𝑦𝑦𝑒𝑙𝑙𝑜𝑤

𝑒 = 0𝑠

0!show_red

!turn_off

?toAuto ?toManual

?toManual

?toManual

Page 56: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

http://msdl.cs.mcgill.ca/projects/PythonPDEVS

Page 57: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

Formalisms

Dynamic Structure

Real-time

Cell DEVS

Verification

Standardization

Tools

Languages

Interoperable

Performance

Algorithms

Activity

Distribution

Parallel

Model libraries

Example

Reusable

Applications

Page 58: Parallel DEVS - The Modelling, Simulation and Design Lab ...msdl.cs.mcgill.ca/people/yentl/files/17.SpringSim.DEVSTutorial.pdf · Abstract simulator for the parallel DEVS formalism.

http://msdl.cs.mcgill.ca/projects/PythonPDEVS