File: bank06.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 (40 lines) | stat: -rw-r--r-- 1,205 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
38
39
40
""" bank06: Many Random Customers """
from SimPy.Simulation import *
from random import expovariate, seed

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


class Source(Process):
    """ Source generates customers at random """

    def generate(self, number, meanTBA):
        for i in range(number):
            c = Customer(name="Customer%02d" % (i))
            activate(c, c.visit(timeInBank=12.0))
            t = expovariate(1.0 / meanTBA)                # (1)
            yield hold, self, t                         # (2)


class Customer(Process):
    """ Customer arrives, looks around and leaves """

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

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

maxNumber = 5
maxTime = 400.0  # minutes
ARRint = 10.0    # mean arrival interval, minutes

## Model/Experiment ------------------------------

seed(99999)                                             # (3)
initialize()
s = Source(name='Source')
activate(s, s.generate(number=maxNumber,
                      meanTBA=ARRint), at=0.0)
simulate(until=maxTime)