File: bank02_OO.py

package info (click to toggle)
python-simpy 2.3.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,864 kB
  • sloc: python: 11,171; makefile: 143
file content (35 lines) | stat: -rw-r--r-- 1,091 bytes parent folder | download | duplicates (4)
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
""" bank02_OO: More Customers """
from SimPy.Simulation import Simulation, Process, hold


## Model components ------------------------
class Customer(Process):
    """ Customer arrives, looks around and leaves """

    def visit(self, timeInBank=0):
        print("%7.4f %s: Here I am" % (self.sim.now(), self.name))
        yield hold, self, timeInBank
        print("%7.4f %s: I must leave" % (self.sim.now(), self.name))


## Model -----------------------------------
class BankModel(Simulation):
    def run(self):
        """ PEM """
        c1 = Customer(name="Klaus", sim=self)
        self.activate(c1, c1.visit(timeInBank=10.0), at=5.0)
        c2 = Customer(name="Tony", sim=self)
        self.activate(c2, c2.visit(timeInBank=7.0), at=2.0)
        c3 = Customer(name="Evelyn", sim=self)
        self.activate(c3, c3.visit(timeInBank=20.0), at=12.0)
        self.simulate(until=maxTime)

## Experiment data -------------------------

maxTime = 400.0  # minutes

## Experiment ------------------------------

mymodel = BankModel()
mymodel.run()