Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 360
Image: ubuntu2004
Kernel: Python 3 (system-wide)
import math from random import randint import numpy as np

0.Define a service time assignment function and a time between arrival assigner function.

Hint: You may want to refer back to the unfair die example in the craps notebook.

#insert 0 here def arrival(time, weights, times): print(random.choices(time, weights, k=times)) arrival([0,1,2,3,4,5], [.10, .15, .10, .35, .25, .05],4) time2 = [1,2,3,4] weights2 = [.25, .20, .40, .15] def service(times2): print(random.choices(time2, weights2, k=times2)) service(1)
[2, 1, 0, 3] [2]

1.Create empty lists for each of the 150 customers’ arrival times, service times, help start, help end, and wait times.

#insert 1 here a_time = [] s_time = [] h_start = [] h_end = [] w_time = []

2.Assume the first person arrives when the bank opens at t=0. Assign the first customer their arrival time, random service time, help start, help end, and wait time in each list. Hint: Use .append

#insert 2

3.Give all of the other customers their random service times.

Hint: You'll want to use a for loop.

#insert 3

4.Give all of the other customers their random times between arrivals.

Hint: You'll want to use a for loop.

#insert 4

5.Update each customer’s help start, help end, and wait times. You will need to update differently depending on whether the next customer arrived before or after the last person’s service finished.

Hint: You will need an if/else statement within a for loop.

#insert 5

6.Calculate the average wait time on this day.

Hint: if you import numpy then you can use np.mean(wait_time).

#insert 6

7.Simulate 10,000 days to calculate the average wait time.

Hint 1: you'll need an outer loop (corresponding to each day) with all of the previous stuff inside it.

Hint 2: Make sure to clear the lists each time you start a new day by setting them equal to empty brackets (ex: wait_time = []).

Hint 3: Create an additional list called total_waittime that keeps track of each day's wait time and then you can find the average of this list at the very end.

Hint 4: The answer should be approximately 4.9 mins.

#insert 7

8.What was the longest wait time?

Hint: max is a built-in function for lists

#insert 8

9.Plot the day versus the day's wait time.

Hint: You can make a list of 10,000 days quickly using the range function.

#insert 9

10.Play around with changing the probability distributions for service time and time between arrivals until your average wait time is less than 2 minutes.

#insert 10