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