Debian Codegraph @

docs/source/Tutorials/bankprograms/bank21.py

raw symbols SCIP
1 """ bank21: One counter with impatient customers """
2 from SimPy.Simulation import *
3 from random import expovariate, seed
4
5 ## Model components ------------------------
6
7
8 class Source(Process):
9 """ Source generates customers randomly """
10
11 def generate(self, number, interval):
12 for i in range(number):
13 c = Customer(name="Customer%02d" % (i))
14 activate(c, c.visit(timeInBank=15.0))
15 t = expovariate(1.0 / interval)
16 yield hold, self, t
17
18
19 class Customer(Process):
20 """ Customer arrives, is served and leaves """
21
22 def visit(self, timeInBank=0):
23 arrive = now() # arrival time
24 print("%8.3f %s: Here I am " % (now(), self.name))
25
26 yield (request, self, counter), (hold, self, maxWaitTime)
27 wait = now() - arrive # waiting time
28 if self.acquired(counter):
29 print("%8.3f %s: Waited %6.3f" % (now(), self.name, wait))
30 yield hold, self, timeInBank
31 yield release, self, counter
32 print("%8.3f %s: Completed" % (now(), self.name))
33 else:
34 print("%8.3f %s: Waited %6.3f. I am off" % (now(), self.name, wait))
35
36 ## Experiment data -------------------------
37
38 maxTime = 400.0 # minutes
39 maxWaitTime = 12.0 # minutes. maximum time to wait
40
41 ## Model ----------------------------------
42
43
44 def model():
45 global counter
46 seed(98989)
47 counter = Resource(name="Karen")
48 initialize()
49 source = Source('Source')
50 activate(source,
51 source.generate(number=5, interval=10.0), at=0.0)
52 simulate(until=maxTime)
53
54 ## Experiment ----------------------------------
55
56 model()