| 1 |
""" bank03_OO: Many non-random Customers """ |
| 2 |
from SimPy.Simulation import Simulation, Process, hold |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
class Source(Process): |
| 7 |
""" Source generates customers regularly """ |
| 8 |
|
| 9 |
def generate(self, number, TBA): |
| 10 |
for i in range(number): |
| 11 |
c = Customer(name="Customer%02d" % (i), sim=self.sim) |
| 12 |
self.sim.activate(c, c.visit(timeInBank=12.0)) |
| 13 |
yield hold, self, TBA |
| 14 |
|
| 15 |
|
| 16 |
class Customer(Process): |
| 17 |
""" Customer arrives, looks around and leaves """ |
| 18 |
|
| 19 |
def visit(self, timeInBank): |
| 20 |
print("%7.4f %s: Here I am" % (self.sim.now(), self.name)) |
| 21 |
yield hold, self, timeInBank |
| 22 |
print("%7.4f %s: I must leave" % (self.sim.now(), self.name)) |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
class BankModel(Simulation): |
| 27 |
def run(self): |
| 28 |
""" PEM """ |
| 29 |
s = Source(sim=self) |
| 30 |
self.activate(s, s.generate(number=maxNumber, |
| 31 |
TBA=ARRint), at=0.0) |
| 32 |
self.simulate(until=maxTime) |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
maxNumber = 5 |
| 37 |
maxTime = 400.0 |
| 38 |
ARRint = 10.0 |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
mymodel = BankModel() |
| 43 |
mymodel.run() |