1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
""" RealTimeFireworks.py """
from SimPy.SimulationRT import *
from random import *
import time
## Model components -----------------------------------------------------------
class Launcher(Process):
def launch(self):
while True:
print "Launch at %2.2f; wallclock: %2.2f"%(now(),time.clock()-startTime)
yield hold,self,uniform(1,maxFlightTime)
print "Boom!!! Aaaah!! at %2.2f; wallclock: %2.2f"\
%(now(),time.clock()-startTime)
def model():
initialize()
for i in range(nrLaunchers):
lau=Launcher()
activate(lau,lau.launch())
simulate(real_time=True,rel_speed=1,until=20) ##unit sim time = 1 sec clock
## Experiment data -----------------------------------------------------------
nrLaunchers=2
maxFlightTime=5.0
startTime=time.clock()
seed(1234567)
## Experiment -----------------------------------------------------------------
model()
|