-
Notifications
You must be signed in to change notification settings - Fork 0
/
mva.py
40 lines (25 loc) · 874 Bytes
/
mva.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
import numpy as np
# mean value analysis
# 1. take in an array of service times multiplied by routing probabilities
TOL = 0.0001
def mva(routing_array, n_jobs, think_time):
N = routing_array.shape[0]
total_service = routing_array.sum(axis=1)
routing_probs = routing_array / total_service.reshape(N, 1)
visits = np.zeros(N)
new_visits = np.ones(N)/N
while abs((visits-new_visits).max()) > TOL:
visits = new_visits
new_visits = visits @ routing_probs
new_visits = new_visits/sum(new_visits)
visits = new_visits
visits = visits * 0.5
Q = np.zeros(N)
W = np.zeros(N)
T = 0
for job_ct in range(1, n_jobs+1):
W_q = (1 + Q) / total_service
weighted_visits = visits * W
T = job_ct / (weighted_visits.sum() + think_time)
Q = T * weighted_visits
return T, Q, W