Parallel DEVS An Introduction Using PythonPDEVS Yentl Van Tendeloo, Hans Vangheluwe
Introduction
Process Interaction Cellular Automata Discrete Event Activity Scanning State Charts Petri Nets Discrete Event Event Scheduling Finite State Automata Discrete Event DEVS
Experimentation
X t S t Y t
simple_experiment.py from pypdevs.simulator import Simulator from mymodel import MyModel model = MyModel() simulator = Simulator(model) simulator.setVerbose() simulator.simulate()
Atomic Models
X Red 60s t S Yellow 3s t 57 120 177 60 Y Green 57s t
Red 60s π = π , π πππ’ π’π , π : set of sequential states π = {red, yellow, green} π πππ’ : π β π Yellow π πππ’ = {red β green, 3s green β yellow, yellow β red} π’π : S β β 0,+β π’π = {red β 60, green β 57, yellow β 3} Green 57s
π = {red, yellow, green} atomic_int.py π πππ’ = { red β green, from pypdevs.DEVS import * green β yellow, yellow β red} class TrafficLightAutonomous(AtomicDEVS): π’π = {red β 60, def __init__(self): green β 57, AtomicDEVS.__init __(self, βLightβ) yellow β 3} self.state = βredβ def intTransition(self): state = self.state return {βredβ: βgreenβ, βyellowβ: βredβ, βgreenβ: βyellowβ}[state] def timeAdvance(self): time = 0 state = self.state current_state = green return {βredβ: 60, while True: βyellowβ: 3, time += ta(current_state) βgreenβ: 57}[state] current_state = π πππ’ (current_state)
X Red 60s t !red S Yellow !green 3s !yellow t 57 120 177 60 Y Green 57s t
Red π = , π, π πππ’ , , π’π 60s π π π = {red, yellow, green} π πππ’ = { red β green, !red green β yellow, yellow β red} π’π = {red β 60, green β 57, Yellow !green yellow β 3} 3s π : set of output events π = {βredβ, βgreenβ, βyellowβ} !yellow π : π β π π π = { green β [βyellowβ], yellow β [βredβ], Green red β [βgreenβ]} 57s
atomic_out.py π = {βredβ, βgreenβ, βyellowβ} from pypdevs.DEVS import * π = {green β βyellowβ, yellow β βredβ, class TrafficLightWithOutput(AtomicDEVS): red β βgreenβ} def __init__(self): AtomicDEVS.__init __(self, βlightβ) self.state = βredβ self.observe = self.addOutPort (βobserverβ) β¦ def outputFnc(self): state = self.state if state == βredβ: v = βgreenβ time = 0 elif state == βyellowβ: current_state = green v = βredβ while True: elif state == βgreenβ: time += ta(current_state) v = βyellowβ output( π (current_state)) return {self.observe: [v]} current_state = π πππ’ (current_state)
X Red 60s ?manual t !red ?auto S Manual Yellow !green βs 3s ?manual t 57 120 177 !yellow 60 Y Green ?manual 57s t
π = π , π, π, π πππ’ , π ππ¦π’ , π, π’π π = {βredβ, βgreenβ, βyellowβ} Red π = {red, yellow, green, manual} 60s ?manual π πππ’ = {red β green, green β yellow, yellow β red} !red π = {green β βyellowβ, ?auto yellow β βredβ, red β βgreenβ} π’π = {red β 60, Manual Yellow !green green β 57, βs 3s yellow β 3, ?manual manual β β } π : set of input events !yellow π = {βautoβ, βmanualβ} π ππ¦π’ : Q Γ π π β π Green ?manual π ππ¦π’ = {( (*, *), [βmanualβ]) β βmanualβ, 57s ( (βmanualβ, *), [βautoβ]) β βredβ}
π = {βautoβ, βmanualβ} atomic_ext.py π ππ¦π’ = {( (*, *), [βmanualβ]) β βmanualβ, from pypdevs.DEVS import * ( (βmanualβ, *), [βautoβ]) β βredβ} class TrafficLight(AtomicDEVS): def __init__(self): AtomicDEVS.__init __(self, βlightβ) self.state = βredβ self.observe = self.addOutPort (βobserverβ) self.interrupt = self.addInPort (βinterruptβ) time = 0 cur_state = βredβ β¦ while True: next_time = time + ta(cur_state) def extTransition(self, inputs): if time_next_ev <= next_time: inp = inputs[self.interrupt][0] cur_state = π ππ¦π’ ((cur_state, e), next_ev) if inp == βmanualβ: time = time_next_ev return βmanualβ else: elif inp == βautoβ: time = next_time if self.state == βmanualβ: output( π (current_state)) return βredβ current_state = π _ πππ’ (current_state)
π ππππ π = π, π, π, π πππ’ , π ππ¦π’ , , π, π’π π : set of input events π : set of output events π : set of sequential states π πππ’ : π β π π ππ¦π’ : Q Γ π π β π π : π β π π π’π : S β β 0,+β π ππππ : π Γ π π β π
atomic_conf.py 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
Coupled Models
Work 360s !manual !auto Idle 20s
Red Work 60s ?manual 360s !red ?auto !manual !auto Manual Yellow !green βs 3s Idle 20s ?manual !yellow Green ?manual M = π, π, πΈ, π π , π½ π , π π,π 57s
trafficlight_system.py from pypdevs.DEVS import * from trafficlight import TrafficLight from policeman import Policeman 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)
City Traffic House Road Road Commerce light Generator Queue Queue Queue ο¦ ο¦ ο¦ ο¦ Queue Processor Processor Collector ο¦ ο¦ ο¦ ο¦ Queue Queue ο¦ ο¦
Root coordinator (done, t) (done, t) (@,t) (*, t) Coupled DEVS Coordinator (x, t) (*, t) (*, t) (@,t) (y, t) (done, t) (done, t) Simulator Simulator Atomic DEVS Atomic DEVS
Applications
Conclusions
Conclusions (@,t) (Y , t) (X, t) (*, t) (done, t) ο΅ Atomic DEVS ο΅ Coupled DEVS R ο΅ Closure under coupling 60s ?manual Work ο΅ Abstract Simulator 360s !red ?auto !manual !auto M Y !green βs 3s ?manual Idle 20s !yellow G ?manual 57s
http://msdl.cs.mcgill.ca/projects/PythonPDEVS
Formalisms Standardization Performance Model libraries Applications Dynamic Algorithms Structure Tools Example Real-time Activity Languages Cell DEVS Distribution Reusable Interoperable Verification Parallel
Recommend
More recommend