1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
""" bank20: One counter with a priority customer """
from SimPy.Simulation import *
from random import expovariate, seed
## Model components ------------------------
class Source(Process):
""" Source generates customers randomly """
def generate(self, number, interval, resource):
for i in range(number):
c = Customer(name="Customer%02d" % (i))
activate(c, c.visit(timeInBank=12.0,
res=resource, P=0))
t = expovariate(1.0 / interval)
yield hold, self, t
class Customer(Process):
""" Customer arrives, is served and leaves """
def visit(self, timeInBank=0, res=None, P=0):
arrive = now() # arrival time
Nwaiting = len(res.waitQ)
print("%8.3f %s: Queue is %d on arrival" % (now(), self.name, Nwaiting))
yield request, self, res, P
wait = now() - arrive # waiting time
print("%8.3f %s: Waited %6.3f" % (now(), self.name, wait))
yield hold, self, timeInBank
yield release, self, res
print("%8.3f %s: Completed" % (now(), self.name))
## Experiment data -------------------------
maxTime = 400.0 # minutes
k = Resource(name="Counter", unitName="Karen",
qType=PriorityQ)
## Model/Experiment ------------------------------
seed(98989)
initialize()
s = Source('Source')
activate(s, s.generate(number=5, interval=10.0,
resource=k), at=0.0)
guido = Customer(name="Guido ")
activate(guido, guido.visit(timeInBank=12.0, res=k,
P=100), at=23.0)
simulate(until=maxTime)
|