-
Notifications
You must be signed in to change notification settings - Fork 0
/
marketmodel.py
47 lines (39 loc) · 1.61 KB
/
marketmodel.py
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
41
42
43
44
45
46
47
"""
File: model.py
Author: Ken Lambert
Editor: Leigh Stauffer
Project 7
Models multiple cashiers.
"""
from cashier import Cashier
from customer import Customer
import random
class MarketModel(object):
def __init__(self, lengthOfSimulation, averageTimePerCus,
probabilityOfNewArrival, numCashiers):
self._probabilityOfNewArrival = probabilityOfNewArrival
self._lengthOfSimulation = lengthOfSimulation
self._averageTimePerCus = averageTimePerCus
self._cashiers = list()
for count in range(numCashiers):
self._cashiers.append(Cashier(count + 1))
def runSimulation(self):
"""Run the clock for n ticks."""
for currentTime in range(self._lengthOfSimulation):
# Attempt to generate a new customer
customer = Customer.generateCustomer(
self._probabilityOfNewArrival,
currentTime,
self._averageTimePerCus)
# Send customer to a randomly chosen cashier
# if successfully generated
if customer != None:
random.choice(self._cashiers).addCustomer(customer)
# Tell all cashiers to provide another unit of service
for cashier in self._cashiers:
cashier.serveCustomers(currentTime)
def __str__(self):
"""Returns the string rep of the results of the simulation."""
return "CASHIER CUSTOMERS AVERAGE LEFT IN\n" + \
" PROCESSED WAIT TIME LINE\n" + \
"\n".join(map(str, self._cashiers))