Debian Codegraph @

docs/source/Tutorials/bankprograms_OO/bank17_OO.py

raw symbols SCIP
1 """bank17_OO: Plotting a Histogram of Monitor results"""
2 from SimPy.Simulation import Simulation, Process, Resource, Monitor, hold, request, release
3 from SimPy.SimPlot import *
4 from random import expovariate, seed
5
6 ## Model components ------------------------
7
8 class Source(Process):
9 """ Source generates customers randomly"""
10 def generate(self, number, rate):
11 for i in range(number):
12 c = Customer(name="Customer%02d" % (i), sim=self.sim)
13 self.sim.activate(c, c.visit(timeInBank=12.0))
14 yield hold, self, expovariate(rate)
15
16
17 class Customer(Process):
18 """ Customer arrives, is served and leaves """
19 def visit(self, timeInBank):
20 arrive = self.sim.now()
21 #print("%8.4f %s: Arrived "%(now(), self.name))
22
23 yield request, self, self.sim.counter
24 #print("%8.4f %s: Got counter "%(now(), self.name))
25 tib = expovariate(1.0 / timeInBank)
26 yield hold, self, tib
27 yield release, self, self.sim.counter
28
29 #print("%8.4f %s: Finished " % (now(), self.name))
30 t = self.sim.now() - arrive
31 self.sim.Mon.observe(t)
32
33 ## Model ----------------------------------
34
35 class BankModel(Simulation):
36 def run(self, aseed):
37 """ PEM """
38 seed(aseed)
39 self.counter = Resource(1, name="Clerk", sim=self)
40 self.Mon = Monitor('Time in the Bank', sim=self)
41 source = Source(sim=self)
42 self.activate(source,
43 source.generate(number=20, rate=0.1), at=0.0)
44 self.simulate(until=maxTime)
45
46 ## Experiment data -------------------------
47
48 maxTime = 400.0 # minutes
49
50 N = 0
51 seedVal = 393939
52
53 ## Experiment -----------------------------
54
55 modl = BankModel()
56 modl.run(aseed=seedVal)
57
58 ## Output ----------------------------------
59 Histo = modl.Mon.histogram(low=0.0, high=200.0, nbins=20)
60
61 plt = SimPlot()
62 plt.plotHistogram(Histo, xlab='Time (min)',
63 title="Time in the Bank",
64 color="red", width=2)
65 plt.mainloop()