Debian Codegraph @

docs/examples/GUIdemo.py

raw symbols SCIP
1 __doc__=""" GUIdemo.py
2 This is a very basic model, demonstrating the ease
3 of interfacing to SimGUI.
4 """
5 from SimPy.Simulation import *
6 from SimPy.Monitor import *
7 from random import *
8 from SimPy.SimGUI import *
9
10 ## Model components ------------------------
11
12 class Launcher(Process):
13 nrLaunched=0
14 def launch(self):
15 while True:
16 gui.writeConsole("Launch at %.1f"%now())
17 Launcher.nrLaunched+=1
18 gui.launchmonitor.observe(Launcher.nrLaunched)
19 yield hold,self,uniform(1,gui.params.maxFlightTime)
20 gui.writeConsole("Boom!!! Aaaah!! at %.1f"%now())
21
22 def model():
23 gui.launchmonitor=Monitor(name="Rocket counter",
24 ylab="nr launched",tlab="time")
25 initialize()
26 Launcher.nrLaunched=0
27 for i in range(gui.params.nrLaunchers):
28 lau=Launcher()
29 activate(lau,lau.launch())
30 simulate(until=gui.params.duration)
31 gui.noRunYet=False
32 gui.writeStatusLine("%s rockets launched in %.1f minutes"%
33 (Launcher.nrLaunched,now()))
34
35 class MyGUI(SimGUI):
36 def __init__(self,win,**par):
37 SimGUI.__init__(self,win,**par)
38 self.run.add_command(label="Start fireworks",
39 command=model,underline=0)
40 self.params=Parameters(duration=duration,
41 maxFlightTime=maxFlightTime,
42 nrLaunchers=nrLaunchers)
43
44 ## Experiment data ---------------------------------------
45
46 duration=2000
47 maxFlightTime=11.7
48 nrLaunchers=3
49
50 ## Model/Experiment/Display ------------------------------
51
52 root=Tk()
53 gui=MyGUI(root,title="RocketGUI",doc=__doc__,consoleHeight=40)
54 gui.mainloop()