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