| 1 |
""" bank04_OO: Simulate a single customer. random time in system """ |
| 2 |
from SimPy.Simulation import Simulation, Process, hold |
| 3 |
from random import Random |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
class Customer(Process): |
| 8 |
""" Customer arrives in the bank, looks around for |
| 9 |
a random time and then leaves """ |
| 10 |
|
| 11 |
def visit(self, timeInBank=0): |
| 12 |
print("%7.4f %s: Here I am" % (self.sim.now(), self.name)) |
| 13 |
t = self.sim.rv.expovariate(1.0 / timeInBank) |
| 14 |
yield hold, self, t |
| 15 |
print("%7.4f %s: I must leave" % (self.sim.now(), self.name)) |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
maxTime = 100.0 |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
class BankModel(Simulation): |
| 24 |
def __init__(self, seed): |
| 25 |
Simulation.__init__(self) |
| 26 |
self.rv = Random(seed) |
| 27 |
|
| 28 |
def run(self): |
| 29 |
""" PEM """ |
| 30 |
c = Customer(name="Klaus", sim=self) |
| 31 |
self.activate(c, c.visit(timeInBank=10.0), at=5.0) |
| 32 |
self.simulate(until=maxTime) |
| 33 |
|
| 34 |
mymodel = BankModel(seed=1133) |
| 35 |
mymodel.run() |
| 36 |
|