File: ExampleGUIDebug.py

package info (click to toggle)
python-simpy 2.3.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,864 kB
  • sloc: python: 11,171; makefile: 143
file content (50 lines) | stat: -rw-r--r-- 1,315 bytes parent folder | download | duplicates (4)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Example.py - Example for SimulationGUIDebug
from SimPy.SimulationGUIDebug import * # import SimulationGUIDebug

# Creates man
class SuperBeing(Process):
	def __init__(self,earth):
		Process.__init__(self)
		self.earth = earth

	def Create(self):
		while True:
			yield hold,self,1.20
			man = Man(self.earth)
			activate(man,man.Walk())
			register(man,man.Status) # register the man instance with hook
			
# Man waits for earth resource, then becomes, baby, adult, and leaves earth
class Man(Process):
	ID = 0
	def __init__(self,earth):
		Process.__init__(self,name="Man%d"%Man.ID) # set name to ensure window title is set
		self.earth = earth
		self.status = "in heaven"
		Man.ID += 1
	
	def Walk(self):
		self.status = "waiting for earth "
		yield  request,self,self.earth
		self.status = "baby"
		yield  hold,self,1
		self.status = "adult"
		yield  hold,self,2
		self.status = "good bye earth"
		yield  release,self,self.earth
		
	def Status(self):
		return self.status

# set up 
initialize()
register(SuperBeing,name="SuperBeing") # register SuperBeing class with name

Earth = Resource(2,name="Earth") # set name to ensure window title is set
register(Earth) # register Earth Resource

SB = SuperBeing(Earth)
activate(SB,SB.Create()) # when activated SB will be registered

# simulate
simulate(until=1000)