-
Notifications
You must be signed in to change notification settings - Fork 1
/
queuing_models.py
304 lines (223 loc) · 9.6 KB
/
queuing_models.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
import streamlit as st
import math
from math import factorial
import numpy as np
np.bool = np.bool_
np.object = object
def mmc(lambda_val,mu_val,num_servers=1):
if num_servers < 1:
st.warning("No server is present")
elif num_servers == 1:
flag = False
if lambda_val >= mu_val:
st.warning("Error: Lambda should be less than Mu (lambda < mu)")
flag = True
rho = lambda_val / mu_val
Ls = lambda_val / (mu_val - lambda_val)
Lq = (lambda_val ** 2) / (mu_val * (mu_val - lambda_val))
Ws = 1 / (mu_val - lambda_val)
Wq = lambda_val / (mu_val * (mu_val - lambda_val))
if Ls < 0 or Lq < 0 or Ws < 0 or Wq < 0:
#st.warning("Error: Negative values encountered")
if Ls < 0:
Ls = 0.000
if Lq < 0:
Lq = 0.000
if Ws < 0:
Ws = 0.000
if Wq < 0:
Wq = 0.000
if rho > 1:
st.warning("Error: Utilization rate exceeds 1")
flag = True
if flag != True:
st.write(f"Number of customers in the system (Ls): {Ls:.3f}")
st.write(f"Number of customers in the queue (Lq): {Lq:.3f}")
st.write(f"Average wait time in the system (Ws): {Ws:.3f}")
st.write(f"Average wait time in the queue (Wq): {Wq:.3f}")
st.write(f"Total utilization rate (P): {rho:.3f}")
elif num_servers > 1:
flag = False
rho = lambda_val / (mu_val * num_servers)
Ls = ((rho ** num_servers) * (1 / factorial(num_servers)) /
(sum([(rho ** k) / factorial(k) for k in range(num_servers)]) +
((rho ** num_servers) * (1 / factorial(num_servers)))))
Lq = Ls - (lambda_val / (mu_val * num_servers))
Ws = Ls / lambda_val
Wq = Lq / lambda_val
if Ls < 0 or Lq < 0 or Ws < 0 or Wq < 0:
#st.warning("Error: Negative values encountered")
if Ls < 0:
Ls = 0.000
if Lq < 0:
Lq = 0.000
if Ws < 0:
Ws = 0.000
if Wq < 0:
Wq = 0.000
if rho > 1:
st.warning("Error: Utilization rate exceeds 1")
flag = True
if flag != True:
st.write(f"Number of customers in the system (Ls): {Ls:.3f}")
st.write(f"Number of customers in the queue (Lq): {Lq:.3f}")
st.write(f"Average wait time in the system (Ws): {Ws:.3f}")
st.write(f"Average wait time in the queue (Wq): {Wq:.3f}")
st.write(f"Total utilization rate (P): {rho:.3f}")
def mgc(exp_mean, maxval, minval, num_servers):
if num_servers < 1:
st.warning("No server is present")
elif num_servers == 1:
flag = False
exp_mean= 1/exp_mean
exp_var = (exp_mean)**2/(exp_mean)**2
mean_uniform = (maxval+minval)/2
variance_uniform = ((maxval-minval)**2)/12
mean_uniform = 1/mean_uniform
variance_uniform = 1/variance_uniform
p=exp_mean/(mean_uniform)
Lq = (exp_mean ** 2) / (2 * exp_var) + ((p ** 2) / (2 * (1 - p)))
Wq = Lq/exp_mean
Ws = Wq + (1/mean_uniform)
Ls = exp_mean * Ws
if Ls < 0 or Lq < 0 or Ws < 0 or Wq < 0:
#st.warning("Error: Negative values encountered")
if Ls < 0:
Ls = 0.000
if Lq < 0:
Lq = 0.000
if Ws < 0:
Ws = 0.000
if Wq < 0:
Wq = 0.000
if p > 1:
st.warning("Error: Utilization rate exceeds 1")
flag = True
if flag != True:
st.write(f"Number of customers in the system (Ls): {Ls:.3f}")
st.write(f"Number of customers in the queue (Lq): {Lq:.3f}")
st.write(f"Average wait time in the system (Ws): {Ws:.3f}")
st.write(f"Average wait time in the queue (Wq): {Wq:.3f}")
st.write(f"Total utilization rate (P): {p:.3f}")
elif num_servers > 1:
flag = False
exp_mean=1/exp_mean
exp_var = (exp_mean)**2/(exp_mean)**2
mean_uniform = (maxval+minval)/2
variance_uniform = ((maxval-minval)**2)/12
mean_uniform = 1/mean_uniform
variance_uniform = 1/variance_uniform
c= num_servers
p=exp_mean/(c*mean_uniform)
Lq = (exp_mean ** 2) / (num_servers * (1 - p)) * (1 + (num_servers ** 2 * exp_var) / (2 * (1 - p) ** 2)) / (1 - exp_mean / (num_servers * p))
Wq = Lq / exp_mean
Ws = Wq + 1 / (num_servers * p - exp_mean)
Ls = exp_mean * Ws
if Ls < 0 or Lq < 0 or Ws < 0 or Wq < 0:
#st.warning("Error: Negative values encountered")
if Ls < 0:
Ls = 0.000
if Lq < 0:
Lq = 0.000
if Ws < 0:
Ws = 0.000
if Wq < 0:
Wq = 0.000
if p > 1:
st.warning("Error: Utilization rate exceeds 1")
flag = True
if flag != True:
st.write(f"Number of customers in the system (Ls): {Ls:.3f}")
st.write(f"Number of customers in the queue (Lq): {Lq:.3f}")
st.write(f"Average wait time in the system (Ws): {Ws:.3f}")
st.write(f"Average wait time in the queue (Wq): {Wq:.3f}")
st.write(f"Total utilization rate (P): {p:.3f}")
def ggc(Arrival_Mean,Service_Mean,ArrivalVariance,ServiceVariance,num_servers):
if num_servers < 1:
st.warning("No server is present")
elif num_servers > 1:
flag = False
lembda=1/Arrival_Mean
meu=1/Service_Mean
c=num_servers
p=lembda/(c*meu)
Lq = (lembda ** 2) / (2 * lembda) + ((p ** 2) / (2 * (1 - p)))
Wq = Lq/lembda
Ws = Wq + (1/meu)
Ls = lembda * Ws
if Ls < 0 or Lq < 0 or Ws < 0 or Wq < 0:
#st.warning("Error: Negative values encountered")
if Ls < 0:
Ls = 0.000
if Lq < 0:
Lq = 0.000
if Ws < 0:
Ws = 0.000
if Wq < 0:
Wq = 0.000
if p > 1:
st.warning("Error: Utilization rate exceeds 1")
flag = True
if flag != True:
st.write(f"Number of customers in the system (Ls): {Ls:.3f}")
st.write(f"Number of customers in the queue (Lq): {Lq:.3f}")
st.write(f"Average wait time in the system (Ws): {Ws:.3f}")
st.write(f"Average wait time in the queue (Wq): {Wq:.3f}")
st.write(f"Total utilization rate (P): {p:.3f}")
elif num_servers == 1:
flag = False
lembda=1/Arrival_Mean
meu=1/Service_Mean
c=num_servers
p=lembda/(c*meu)
Lq = (p ** (num_servers + 1)) / (np.math.factorial(num_servers - 1) * num_servers * (1 - p) ** 2)
Wq = Lq / lembda
Ws = Wq + 1 / (num_servers * lembda / 2 - lembda)
Ls = lembda * Ws
if Ls < 0 or Lq < 0 or Ws < 0 or Wq < 0:
#st.warning("Error: Negative values encountered")
if Ls < 0:
Ls = 0.000
if Lq < 0:
Lq = 0.000
if Ws < 0:
Ws = 0.000
if Wq < 0:
Wq = 0.000
if p > 1:
p = 1.0
if flag != True:
st.write(f"Number of customers in the system (Ls): {Ls:.3f}")
st.write(f"Number of customers in the queue (Lq): {Lq:.3f}")
st.write(f"Average wait time in the system (Ws): {Ws:.3f}")
st.write(f"Average wait time in the queue (Wq): {Wq:.3f}")
st.write(f"Total utilization rate (P): {p:.2f}")
def main():
st.title("Queuing Theory Calculator")
selected = st.selectbox("Select queuing model:", ["M/M/C", "M/G/C","G/G/C"])
if selected == "M/M/C":
No_of_server = st.number_input("Number of servers",value=1)
st.subheader(f"Poisson and Exponential Distributions M/M/{No_of_server}")
Arrival_Mean = st.number_input("Enter mean inter-arrival time:", value=1.58)
Service_Mean = st.number_input("Enter average service time:", value=2.56)
elif selected == "M/G/C":
No_of_server = st.number_input("Number of servers",value=1)
st.subheader(f"Exponential and Uniform Distributions M/G/{No_of_server}")
Arrival_Mean = st.number_input("Enter mean inter-arrival time:", value=10)
maxvalue = st.number_input("Enter maximum value:", value=9)
minvalue = st.number_input("Enter minimum value:", value=7)
elif selected == "G/G/C":
No_of_server = st.number_input("Number of servers",value=1)
st.subheader(f"Noraml and Uniform Distributions G/G/{No_of_server}")
Arrival_Mean = st.number_input("Enter mean inter-arrival time:", value=10)
Service_Mean = st.number_input("Enter average service time:", value=15)
ArrivalVariance = st.number_input("Enter maximum value:", value=25)
ServiceVariance = st.number_input("Enter minimum value:", value=20)
if st.button("Run Calculator"):
if selected == "M/M/C":
mmc(Arrival_Mean,Service_Mean,No_of_server)
elif selected == "M/G/C":
mgc(Arrival_Mean,maxvalue,minvalue,No_of_server)
elif selected == "G/G/C":
ggc(Arrival_Mean,Service_Mean,ArrivalVariance,ServiceVariance,No_of_server)
main()