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