Add tutorial models
This commit is contained in:
parent
a3050e5f1d
commit
070993ac35
17 changed files with 533 additions and 0 deletions
32
examples/tutorial_classic/trafficlight_system.py
Normal file
32
examples/tutorial_classic/trafficlight_system.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
### Model
|
||||
from pypdevs.DEVS import *
|
||||
|
||||
from trafficlight import TrafficLight
|
||||
from policeman import Policeman
|
||||
|
||||
def convert_police2light(evt):
|
||||
if evt == "take_break":
|
||||
return "toAuto"
|
||||
elif evt == "go_to_work":
|
||||
return "toManual"
|
||||
|
||||
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, convert_police2light)
|
||||
|
||||
def select(self, imm):
|
||||
if self.police in imm:
|
||||
return self.police
|
||||
else:
|
||||
return self.light
|
||||
|
||||
### Experiment
|
||||
from pypdevs.simulator import Simulator
|
||||
sim = Simulator(TrafficLightSystem())
|
||||
sim.setVerbose()
|
||||
sim.setTerminationTime(1000)
|
||||
sim.setClassicDEVS()
|
||||
sim.simulate()
|
||||
Loading…
Add table
Add a link
Reference in a new issue