Debian Codegraph @

docs/source/Tutorials/bankprograms/bank14.py

raw symbols SCIP
1 """bank14: *waituntil* the Bank door opens"""
2 from SimPy.Simulation import *
3 from random import expovariate, seed
4
5 ## Model components ------------------------
6
7 door = 'Shut'
8
9
10 def dooropen():
11 return door == 'Open'
12
13
14 class Doorman(Process):
15 """ Doorman opens the door"""
16 def openthedoor(self):
17 """ He will open the door when he arrives"""
18 global door
19 yield hold, self, expovariate(1.0 / 10.0)
20 door = 'Open'
21 print("%7.4f Doorman: Ladies and "\
22 "Gentlemen! You may all enter." % (now()))
23
24
25 class Source(Process):
26 """ Source generates customers randomly"""
27 def generate(self, number, rate):
28 for i in range(number):
29 c = Customer(name="Customer%02d" % (i))
30 activate(c, c.visit(timeInBank=12.0))
31 yield hold, self, expovariate(rate)
32
33
34 class Customer(Process):
35 """ Customer arrives, is served and leaves """
36 def visit(self, timeInBank=10):
37 arrive = now()
38
39 if dooropen():
40 msg = ' and the door is open.'
41 else:
42 msg = ' but the door is shut.'
43 print("%7.4f %s: Here I am%s" % (now(), self.name, msg))
44
45 yield waituntil, self, dooropen
46
47 print("%7.4f %s: I can go in!" % (now(), self.name))
48 wait = now() - arrive
49 print("%7.4f %s: Waited %6.3f" % (now(), self.name, wait))
50
51 yield request, self, counter
52 tib = expovariate(1.0 / timeInBank)
53 yield hold, self, tib
54 yield release, self, counter
55
56 print("%7.4f %s: Finished " % (now(), self.name))
57
58 ## Experiment data -------------------------
59
60 maxTime = 2000.0 # minutes
61 counter = Resource(1, name="Clerk")
62
63 ## Model ----------------------------------
64
65
66 def model(SEED=393939):
67 seed(SEED)
68
69 initialize()
70 door = 'Shut'
71 doorman = Doorman()
72 activate(doorman, doorman.openthedoor())
73 source = Source()
74 activate(source,
75 source.generate(number=5, rate=0.1), at=0.0)
76 simulate(until=400.0)
77
78 ## Experiment ----------------------------------
79
80 model()