File: bank05_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 (37 lines) | stat: -rw-r--r-- 1,101 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
36
37
""" bank05_OO: The single Random Customer """
from SimPy.Simulation import Simulation, Process, hold
from random import expovariate, seed

## Model components ------------------------

class Customer(Process):
    """ Customer arrives at a random time,
        looks around  and then leaves """

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

## Model -----------------------------------

class BankModel(Simulation):
    def run(self, aseed):
        """ PEM """
        seed(aseed)
        c = Customer(name="Klaus", sim=self)
        t = expovariate(1.0 / tMeanArrival)
        self.activate(c, c.visit(timeInBank), at=t)
        self.simulate(until=maxTime)

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

maxTime = 100.0     # minutes
timeInBank = 10.0   # minutes
tMeanArrival = 5.0  # minutes
seedVal = 99999

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

mymodel = BankModel()
mymodel.run(aseed=seedVal)