| 1 |
|
| 2 |
from SimPy.SimulationGUIDebug import * |
| 3 |
|
| 4 |
|
| 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) |
| 16 |
|
| 17 |
|
| 18 |
class Man(Process): |
| 19 |
ID = 0 |
| 20 |
def __init__(self,earth): |
| 21 |
Process.__init__(self,name="Man%d"%Man.ID) |
| 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 |
|
| 40 |
initialize() |
| 41 |
register(SuperBeing,name="SuperBeing") |
| 42 |
|
| 43 |
Earth = Resource(2,name="Earth") |
| 44 |
register(Earth) |
| 45 |
|
| 46 |
SB = SuperBeing(Earth) |
| 47 |
activate(SB,SB.Create()) |
| 48 |
|
| 49 |
|
| 50 |
simulate(until=1000) |