| 1 |
""" bank09: Several Counters but a Single Queue """ |
| 2 |
from SimPy.Simulation import * |
| 3 |
from random import expovariate, seed |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
class Source(Process): |
| 9 |
""" Source generates customers randomly """ |
| 10 |
|
| 11 |
def generate(self, number, meanTBA, resource): |
| 12 |
for i in range(number): |
| 13 |
c = Customer(name="Customer%02d" % (i)) |
| 14 |
activate(c, c.visit(b=resource)) |
| 15 |
t = expovariate(1.0 / meanTBA) |
| 16 |
yield hold, self, t |
| 17 |
|
| 18 |
|
| 19 |
class Customer(Process): |
| 20 |
""" Customer arrives, is served and leaves """ |
| 21 |
|
| 22 |
def visit(self, b): |
| 23 |
arrive = now() |
| 24 |
print("%8.4f %s: Here I am " % (now(), self.name)) |
| 25 |
yield request, self, b |
| 26 |
wait = now() - arrive |
| 27 |
print("%8.4f %s: Waited %6.3f" % (now(), self.name, wait)) |
| 28 |
tib = expovariate(1.0 / timeInBank) |
| 29 |
yield hold, self, tib |
| 30 |
yield release, self, b |
| 31 |
print("%8.4f %s: Finished " % (now(), self.name)) |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
maxNumber = 5 |
| 36 |
maxTime = 400.0 |
| 37 |
timeInBank = 12.0 |
| 38 |
ARRint = 10.0 |
| 39 |
theseed = 99999 |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
seed(theseed) |
| 44 |
k = Resource(capacity=2, name="Counter", unitName="Clerk") |
| 45 |
|
| 46 |
initialize() |
| 47 |
s = Source('Source') |
| 48 |
activate(s, s.generate(number=maxNumber, meanTBA=ARRint, |
| 49 |
resource=k), at=0.0) |
| 50 |
simulate(until=maxTime) |