HW3
pdf
keyboard_arrow_up
School
University of California, Berkeley *
*We aren’t endorsed by this school
Course
174
Subject
Industrial Engineering
Date
Apr 3, 2024
Type
Pages
3
Uploaded by ElderPower5469
In [31]:
import
import pandas
pandas as
as pd
pd
import
import numpy
numpy as
as np
np
import
import matplotlib.pyplot
matplotlib.pyplot as
as plt
plt
import
import math
math
In [32]:
def
def lambda_
(k):
return
return 0.5 + (
0.5/120
) * k
Part a) Use simulation to compute the expectation of the number of customers at time 1PM
In [33]:
#variables specified by description of problem
time_start = 11*60
time_end = 13*60
simulations = 100
rate_at_start = 0.5 / 60
rate_at_end = 1 / 60
rate_of_service = 1 / 35
def
def simulation
():
customers = 0
arrivals = []
departures = []
for
for i in
in range
(time_start, time_end):
y = rate_at_start + (rate_at_end - rate_at_start) * (i - time_start) / (time_end
- time_start)
if
if np
.
random
.
rand() < y:
arrivals
.
append(i)
customers = customers + 1
time_of_service = np
.
random
.
exponential(
1/
rate_of_service)
time_of_departure = i + time_of_service
departures
.
append(time_of_departure)
customers = customers - 1
customers_1 = sum
(
1 for
for d in
in departures if
if d >= time_end)
return
return customers_1
ran_simulations = [simulation() for
for x in
in range
(simulations)]
expected_value = np
.
mean(ran_simulations)
std_dev = np
.
std(ran_simulations)
difference = (
1/
np
.
sqrt(
100
))
*1.96*
std_dev
lower_ci = round
(expected_value - difference, 3
)
upper_ci = round
(expected_value + difference, 3
)
print
print
(
'We can expect'
, expected_value, 'customers at 1pm.'
)
print
print
(
'95
% c
% c
onfidence interval is'
, [lower_ci,upper_ci])
Part b) Use simulation to compute the expectation of averaged waiting time for all those customers that arrive
between 12:45 PM to 1 PM.
In [34]:
services = []
wait_times = []
lambda2 = 1
cust_arrive = []
wait_times_105120 = []
for
for _ in
in range
(simulations):
We can expect 0.46 customers at 1pm.
95% confidence interval is [0.338, 0.582]
other_arrive = []
time_depart = []
one_arrival = np
.
random
.
poisson(lambda2 * time_start)
cust_arrive
.
append(one_arrival)
times_of_arrivals = np
.
random
.
uniform(
0
,time_start,one_arrival)
for
for x in
in range
(one_arrival):
y = 0.5+ (times_of_arrivals[x]
/240
)
z = np
.
random
.
uniform(
0
,
1
)
if
if z < y:
other_arrive
.
append(times_of_arrivals[x])
other_arrive
.
sort()
time_of_service = np
.
random
.
exponential(
1
, size
= len
(other_arrive))
services
.
append(time_of_service)
for
for k in
in range
(
len
(other_arrive)):
if
if k
==0
:
departed = other_arrive[k] + time_of_service[k]
else
else
:
departed = max
(other_arrive[k], departed) + time_of_service[k]
time_depart
.
append(departed)
waited = time_depart[k] - other_arrive[k] - time_of_service[k]
wait_times
.
append(waited)
if
if 105 <= other_arrive[k] <=120
:
waiting = time_depart[k] - other_arrive[k] - time_of_service[k]
wait_times_105120
.
append(waiting)
wait_time_avg = sum
(wait_times_105120)
/
len
(wait_times_105120)
wait_time_std_105120 = np
.
std(wait_times_105120)
diff = (
1/
np
.
sqrt(
100
))
*1.96*
wait_time_std_105120
lower_ci1 = round
(wait_time_avg - diff, 3
)
upper_ci1 = round
(wait_time_avg + diff, 3
)
print
print
(
'The average wait time between 12:45pm and 1:00pm is'
, wait_time_avg)
print
print
(
'95
% c
% c
onfidence interval is'
, [lower_ci1,upper_ci1])
Part c) Use simulation to compute the expectation of averaged waiting time for all those customers that arrive
between 11:45 AM to 12:00 PM.
In [35]:
services = []
wait_times = []
lambda2 = 1
cust_arrive = []
wait_times_1530 = []
for
for _ in
in range
(simulations):
other_arrive = []
time_depart = []
one_arrival = np
.
random
.
poisson(lambda2 * time_start)
cust_arrive
.
append(one_arrival)
times_of_arrivals = np
.
random
.
uniform(
0
,time_start,one_arrival)
for
for x in
in range
(one_arrival):
y = 0.5+ (times_of_arrivals[x]
/240
)
z = np
.
random
.
uniform(
0
,
1
)
if
if z < y:
other_arrive
.
append(times_of_arrivals[x])
other_arrive
.
sort()
time_of_service = np
.
random
.
exponential(
1
, size
= len
(other_arrive))
services
.
append(time_of_service)
for
for k in
in range
(
len
(other_arrive)):
if
if k
==0
:
departed = other_arrive[k] + time_of_service[k]
else
else
:
departed = max
(other_arrive[k], departed) + time_of_service[k]
time_depart
.
append(departed)
waited = time_depart[k] - other_arrive[k] - time_of_service[k]
The average wait time between 12:45pm and 1:00pm is 5.490142732423501
95% confidence interval is [4.322, 6.659]
wait_times
.
append(waited)
if
if 15 <= other_arrive[k] <=30
:
waiting = time_depart[k] - other_arrive[k] - time_of_service[k]
wait_times_1530
.
append(waiting)
wait_time_avg = sum
(wait_times_1530)
/
len
(wait_times_1530)
wait_time_std_1530 = np
.
std(wait_times_1530)
diff = (
1/
np
.
sqrt(
100
))
*1.96*
wait_time_std_1530
lower_ci1 = round
(wait_time_avg - diff, 3
)
upper_ci1 = round
(wait_time_avg + diff, 3
)
print
print
(
'The average wait time between 11:45am and 12:00pm is'
, wait_time_avg)
print
print
(
'95
% c
% c
onfidence interval is'
, [lower_ci1,upper_ci1])
The average wait time between 11:45am and 12:00pm is 1.2796944347929933
95% confidence interval is [0.922, 1.637]
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help