Debian Codegraph @

docs/examples/ExampleGUIDebug.py

raw symbols SCIP
1 # Example.py - Example for SimulationGUIDebug
2 from SimPy.SimulationGUIDebug import * # import SimulationGUIDebug
3
4 # Creates man
5 class SuperBeing(Process):
6 def __init__(self,earth):
7 Process.__init__(self)
8 self.earth = earth
9
10 def Create(self):
11 while True:
12 yield hold,self,1.20
13 man = Man(self.earth)
14 activate(man,man.Walk())
15 register(man,man.Status) # register the man instance with hook
16
17 # Man waits for earth resource, then becomes, baby, adult, and leaves earth
18 class Man(Process):
19 ID = 0
20 def __init__(self,earth):
21 Process.__init__(self,name="Man%d"%Man.ID) # set name to ensure window title is set
22 self.earth = earth
23 self.status = "in heaven"
24 Man.ID += 1
25
26 def Walk(self):
27 self.status = "waiting for earth "
28 yield request,self,self.earth
29 self.status = "baby"
30 yield hold,self,1
31 self.status = "adult"
32 yield hold,self,2
33 self.status = "good bye earth"
34 yield release,self,self.earth
35
36 def Status(self):
37 return self.status
38
39 # set up
40 initialize()
41 register(SuperBeing,name="SuperBeing") # register SuperBeing class with name
42
43 Earth = Resource(2,name="Earth") # set name to ensure window title is set
44 register(Earth) # register Earth Resource
45
46 SB = SuperBeing(Earth)
47 activate(SB,SB.Create()) # when activated SB will be registered
48
49 # simulate
50 simulate(until=1000)