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