Debian Codegraph @

docs/source/Tutorials/bankprograms/bank24.py

raw symbols SCIP
1 """ bank24. BCC system with several counters """
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, meanTBA, resource):
12 for i in range(number):
13 c = Customer(name="Customer%02d" % (i))
14 activate(c, c.visit(b=resource))
15 t = expovariate(1.0 / meanTBA)
16 yield hold, self, t
17
18
19 class Customer(Process):
20 """ Customer arrives, is served and leaves """
21
22 numBalking = 0
23
24 def visit(self, b):
25 arrive = now()
26 print("%8.4f %s: Here I am " % (now(), self.name))
27 if len(b.waitQ) < maxInQueue: # the test
28 yield request, self, b
29 wait = now() - arrive
30 print("%8.4f %s: Wait %6.3f" % (now(), self.name, wait))
31 tib = expovariate(1.0 / timeInBank)
32 yield hold, self, tib
33 yield release, self, b
34 print("%8.4f %s: Finished " % (now(), self.name))
35 else:
36 Customer.numBalking += 1
37 print("%8.4f %s: BALKING " % (now(), self.name))
38
39 ## Experiment data -------------------------------
40
41 timeInBank = 12.0 # mean, minutes
42 ARRint = 10.0 # mean interarrival time, minutes
43 numServers = 1 # servers
44 maxInSystem = 2 # customers
45 maxInQueue = maxInSystem - numServers
46
47 maxNumber = 8
48 maxTime = 4000.0 # minutes
49 theseed = 12345
50
51 ## Model/Experiment ------------------------------
52
53 seed(theseed)
54 k = Resource(capacity=numServers,
55 name="Counter", unitName="Clerk")
56
57 initialize()
58 s = Source('Source')
59 activate(s, s.generate(number=maxNumber, meanTBA=ARRint,
60 resource=k), at=0.0)
61 simulate(until=maxTime)
62
63 ## Results -----------------------------------------
64
65 nb = float(Customer.numBalking)
66 print("balking rate is %8.4f per minute" % (nb / now()))