most-queue 2.5__py3-none-any.whl → 2.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- most_queue/__init__.py +18 -0
- most_queue/constants.py +22 -0
- most_queue/io/tables.py +129 -39
- most_queue/misc/calc_v_pls.py +3 -3
- most_queue/misc/run_mgn_with_h2_delay_cold_warm.py +11 -11
- most_queue/misc/tests/test_fj_delta.py +2 -2
- most_queue/misc/vacations_paper_utils.py +3 -3
- most_queue/random/distributions.py +10 -10
- most_queue/random/utils/fit.py +12 -10
- most_queue/sim/__init__.py +10 -0
- most_queue/sim/base.py +296 -97
- most_queue/sim/base_core.py +89 -0
- most_queue/sim/batch.py +15 -12
- most_queue/sim/finite_source.py +2 -1
- most_queue/sim/flow_sum.py +42 -110
- most_queue/sim/fork_join.py +19 -5
- most_queue/sim/fork_join_delta.py +7 -0
- most_queue/sim/impatient.py +62 -53
- most_queue/sim/negative.py +70 -38
- most_queue/sim/networks/base_network_sim.py +218 -10
- most_queue/sim/networks/negative_network.py +623 -0
- most_queue/sim/networks/network.py +28 -27
- most_queue/sim/networks/priority_network.py +33 -35
- most_queue/sim/priority.py +136 -73
- most_queue/sim/utils/events.py +123 -0
- most_queue/sim/utils/qs_queue.py +3 -2
- most_queue/sim/utils/stats_update.py +7 -4
- most_queue/sim/vacations.py +43 -47
- most_queue/structs.py +17 -10
- most_queue/theory/__init__.py +58 -0
- most_queue/theory/base_queue.py +148 -30
- most_queue/theory/batch/mm1.py +9 -7
- most_queue/theory/calc_params.py +3 -1
- most_queue/theory/closed/engset.py +9 -7
- most_queue/theory/fifo/__init__.py +25 -0
- most_queue/theory/fifo/ek_d_n.py +11 -7
- most_queue/theory/fifo/gi_m_1.py +212 -204
- most_queue/theory/fifo/gi_m_n.py +22 -28
- most_queue/theory/fifo/gmc_takahasi.py +332 -0
- most_queue/theory/fifo/hkhk_takahasi.py +486 -0
- most_queue/theory/fifo/m_d_n.py +159 -155
- most_queue/theory/fifo/mg1.py +145 -132
- most_queue/theory/fifo/mgn_takahasi.py +268 -73
- most_queue/theory/fifo/mmnr.py +172 -165
- most_queue/theory/fifo/takahasi_base.py +211 -0
- most_queue/theory/fork_join/m_m_n.py +9 -7
- most_queue/theory/fork_join/split_join.py +135 -135
- most_queue/theory/impatience/mm1.py +9 -7
- most_queue/theory/negative/mg1_disasters.py +19 -14
- most_queue/theory/negative/mg1_rcs.py +3 -3
- most_queue/theory/negative/mgn_disaster.py +37 -95
- most_queue/theory/negative/mgn_rcs.py +37 -101
- most_queue/theory/networks/__init__.py +8 -0
- most_queue/theory/networks/base_network_calc.py +17 -9
- most_queue/theory/networks/negative_network.py +247 -0
- most_queue/theory/priority/__init__.py +13 -0
- most_queue/theory/priority/mgn_invar_approx.py +12 -12
- most_queue/theory/priority/non_preemptive/mg1.py +28 -21
- most_queue/theory/priority/preemptive/m_ph_n_busy_approx.py +8 -5
- most_queue/theory/priority/preemptive/mg1.py +31 -31
- most_queue/theory/priority/preemptive/mm2_3cls_busy_approx.py +8 -5
- most_queue/theory/priority/preemptive/mmn_2cls_pr_busy_approx.py +8 -5
- most_queue/theory/utils/__init__.py +25 -0
- most_queue/theory/utils/busy_periods.py +9 -9
- most_queue/theory/utils/conditional.py +7 -5
- most_queue/theory/utils/conv.py +5 -1
- most_queue/theory/utils/max_dist.py +7 -7
- most_queue/theory/utils/moments.py +42 -0
- most_queue/theory/utils/residual.py +1 -1
- most_queue/theory/utils/timing.py +81 -0
- most_queue/theory/utils/validation.py +97 -0
- most_queue/theory/vacations/m_h2_h2warm.py +21 -16
- most_queue/theory/vacations/mg1_warm_calc.py +13 -11
- most_queue/theory/vacations/mgn_with_h2_delay_cold_warm.py +15 -13
- most_queue/theory/vacations/mmn_with_h2_cold_and_h2_warmup.py +19 -18
- most_queue-2.7.dist-info/METADATA +274 -0
- most_queue-2.7.dist-info/RECORD +121 -0
- most_queue-2.5.dist-info/METADATA +0 -204
- most_queue-2.5.dist-info/RECORD +0 -110
- {most_queue-2.5.dist-info → most_queue-2.7.dist-info}/WHEEL +0 -0
- {most_queue-2.5.dist-info → most_queue-2.7.dist-info}/licenses/LICENSE +0 -0
most_queue/__init__.py
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Most-Queue: A Python package for simulating and analyzing queueing systems.
|
|
3
|
+
|
|
4
|
+
This package provides both simulation and numerical calculation methods
|
|
5
|
+
for various types of queueing systems and networks.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "2.05"
|
|
9
|
+
|
|
10
|
+
# Import main simulation and theory classes for easy access
|
|
11
|
+
from most_queue.sim.base import QsSim
|
|
12
|
+
from most_queue.theory.base_queue import BaseQueue
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"QsSim",
|
|
16
|
+
"BaseQueue",
|
|
17
|
+
"__version__",
|
|
18
|
+
]
|
most_queue/constants.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Constants used throughout the most_queue package.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
# Default number of states for simulation
|
|
6
|
+
DEFAULT_NUM_STATES: int = 100000
|
|
7
|
+
|
|
8
|
+
# Default number of jobs for simulation
|
|
9
|
+
DEFAULT_NUM_JOBS: int = 1000000
|
|
10
|
+
|
|
11
|
+
# Default number of probabilities to calculate
|
|
12
|
+
DEFAULT_P_NUM: int = 1000
|
|
13
|
+
|
|
14
|
+
# Numerical tolerances
|
|
15
|
+
DEFAULT_TOLERANCE: float = 1e-12
|
|
16
|
+
LSTSQ_RCOND: float = 1e-8 # rcond parameter for numpy.linalg.lstsq
|
|
17
|
+
|
|
18
|
+
# Maximum iterations for fitting algorithms
|
|
19
|
+
MAX_FIT_ITERATIONS: int = 10000
|
|
20
|
+
|
|
21
|
+
# Default number of dots for approximation
|
|
22
|
+
DEFAULT_DOTS_NUM: int = 10000
|
most_queue/io/tables.py
CHANGED
|
@@ -6,18 +6,20 @@ import math
|
|
|
6
6
|
|
|
7
7
|
from colorama import Fore, Style, init
|
|
8
8
|
|
|
9
|
+
from most_queue.theory.utils.moments import convert_raw_to_central
|
|
10
|
+
|
|
9
11
|
init()
|
|
10
12
|
|
|
11
13
|
|
|
12
|
-
def
|
|
13
|
-
sim_moments: list[float] |
|
|
14
|
-
calc_moments: list[float] |
|
|
14
|
+
def print_raw_moments(
|
|
15
|
+
sim_moments: list[float] | float,
|
|
16
|
+
calc_moments: list[float] | float,
|
|
15
17
|
header=None,
|
|
16
18
|
sim_header="Sim",
|
|
17
19
|
calc_header="Num",
|
|
18
|
-
):
|
|
20
|
+
):
|
|
19
21
|
"""
|
|
20
|
-
Prints the
|
|
22
|
+
Prints the moments of waiting or sojourn time in the system.
|
|
21
23
|
Args:
|
|
22
24
|
sim_moments (list): List of simulated moments.
|
|
23
25
|
calc_moments (list): List of calculated moments.
|
|
@@ -63,14 +65,73 @@ def print_moments(
|
|
|
63
65
|
print(Style.RESET_ALL)
|
|
64
66
|
|
|
65
67
|
|
|
66
|
-
def
|
|
67
|
-
sim_moments: list[float] |
|
|
68
|
-
calc_moments: list[float] |
|
|
68
|
+
def print_central_moments(
|
|
69
|
+
sim_moments: list[float] | float,
|
|
70
|
+
calc_moments: list[float] | float,
|
|
71
|
+
header=None,
|
|
72
|
+
sim_header="Sim",
|
|
73
|
+
calc_header="Num",
|
|
74
|
+
):
|
|
75
|
+
"""
|
|
76
|
+
Prints the moments of waiting or sojourn time in the system.
|
|
77
|
+
Args:
|
|
78
|
+
sim_moments (list): List of simulated moments.
|
|
79
|
+
calc_moments (list): List of calculated moments.
|
|
80
|
+
header (str): Header for the table.
|
|
81
|
+
sim_header (str): Header for simulated moments.
|
|
82
|
+
calc_header (str): Header for calculated moments.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
if not header is None:
|
|
86
|
+
print(Fore.CYAN + f"\n{header:^45}")
|
|
87
|
+
print("-" * 45)
|
|
88
|
+
|
|
89
|
+
num_col = "Moment"
|
|
90
|
+
central_moments_names = ["Mean", "Variance", "Skewness", "Kurtosis"]
|
|
91
|
+
|
|
92
|
+
print(f"{num_col:^15s}|{calc_header:^15s}|{sim_header:^15s}")
|
|
93
|
+
print("-" * 45)
|
|
94
|
+
if isinstance(sim_moments, list):
|
|
95
|
+
for j in range(min(len(sim_moments), len(calc_moments))):
|
|
96
|
+
calc_mom = calc_moments[j].real if isinstance(calc_moments[j], complex) else calc_moments[j]
|
|
97
|
+
sim_mom = sim_moments[j].real if isinstance(sim_moments[j], complex) else sim_moments[j]
|
|
98
|
+
name = central_moments_names[j]
|
|
99
|
+
print(
|
|
100
|
+
Fore.CYAN
|
|
101
|
+
+ f"{name:^15s}|"
|
|
102
|
+
+ Fore.YELLOW
|
|
103
|
+
+ f"{calc_mom:^15.5g}"
|
|
104
|
+
+ Fore.CYAN
|
|
105
|
+
+ "|"
|
|
106
|
+
+ Fore.YELLOW
|
|
107
|
+
+ f"{sim_mom:^15.5g}"
|
|
108
|
+
)
|
|
109
|
+
else:
|
|
110
|
+
calc_mom = calc_moments.real if isinstance(calc_moments, complex) else calc_moments
|
|
111
|
+
sim_mom = sim_moments.real if isinstance(sim_moments, complex) else sim_moments
|
|
112
|
+
name = central_moments_names[0]
|
|
113
|
+
print(
|
|
114
|
+
Fore.CYAN
|
|
115
|
+
+ f"{name:^15s}|"
|
|
116
|
+
+ Fore.YELLOW
|
|
117
|
+
+ f"{calc_mom:^15.5g}"
|
|
118
|
+
+ Fore.CYAN
|
|
119
|
+
+ "|"
|
|
120
|
+
+ Fore.YELLOW
|
|
121
|
+
+ f"{sim_mom:^15.5g}"
|
|
122
|
+
)
|
|
123
|
+
print(Style.RESET_ALL)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def print_waiting_moments(
|
|
127
|
+
sim_moments: list[float] | float,
|
|
128
|
+
calc_moments: list[float] | float,
|
|
69
129
|
sim_header="Sim",
|
|
70
130
|
calc_header="Num",
|
|
71
|
-
|
|
131
|
+
convert_to_central=True,
|
|
132
|
+
):
|
|
72
133
|
"""
|
|
73
|
-
Prints the
|
|
134
|
+
Prints the moments of waiting or sojourn time in the system.
|
|
74
135
|
Args:
|
|
75
136
|
sim_moments (list): List of simulated moments.
|
|
76
137
|
calc_moments (list): List of calculated moments.
|
|
@@ -78,19 +139,28 @@ def print_waiting_times(
|
|
|
78
139
|
calc_header (str): Header for calculated moments
|
|
79
140
|
"""
|
|
80
141
|
|
|
81
|
-
header = "
|
|
142
|
+
header = "Moments of waiting time in the system"
|
|
82
143
|
|
|
83
|
-
|
|
144
|
+
if convert_to_central:
|
|
145
|
+
calc_moments_central = convert_raw_to_central(calc_moments)
|
|
146
|
+
sim_moments_central = convert_raw_to_central(sim_moments)
|
|
84
147
|
|
|
148
|
+
print_central_moments(
|
|
149
|
+
sim_moments_central, calc_moments_central, sim_header=sim_header, calc_header=calc_header, header=header
|
|
150
|
+
)
|
|
151
|
+
else:
|
|
152
|
+
print_raw_moments(sim_moments, calc_moments, sim_header=sim_header, calc_header=calc_header, header=header)
|
|
85
153
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
154
|
+
|
|
155
|
+
def print_sojourn_moments(
|
|
156
|
+
sim_moments: list[float] | float,
|
|
157
|
+
calc_moments: list[float] | float,
|
|
89
158
|
sim_header="Sim",
|
|
90
159
|
calc_header="Num",
|
|
91
|
-
|
|
160
|
+
convert_to_central=True,
|
|
161
|
+
):
|
|
92
162
|
"""
|
|
93
|
-
Prints the
|
|
163
|
+
Prints the moments of waiting or sojourn time in the system.
|
|
94
164
|
Args:
|
|
95
165
|
sim_moments (list): List of simulated moments.
|
|
96
166
|
calc_moments (list): List of calculated moments.
|
|
@@ -98,20 +168,28 @@ def print_sojourn_times(
|
|
|
98
168
|
calc_header (str): Header for calculated moments
|
|
99
169
|
"""
|
|
100
170
|
|
|
101
|
-
header = "
|
|
171
|
+
header = "Moments of sojourn time in the system"
|
|
102
172
|
|
|
103
|
-
|
|
173
|
+
if convert_to_central:
|
|
174
|
+
calc_moments_central = convert_raw_to_central(calc_moments)
|
|
175
|
+
sim_moments_central = convert_raw_to_central(sim_moments)
|
|
176
|
+
|
|
177
|
+
print_central_moments(
|
|
178
|
+
sim_moments_central, calc_moments_central, sim_header=sim_header, calc_header=calc_header, header=header
|
|
179
|
+
)
|
|
180
|
+
else:
|
|
181
|
+
print_raw_moments(sim_moments, calc_moments, sim_header=sim_header, calc_header=calc_header, header=header)
|
|
104
182
|
|
|
105
183
|
|
|
106
184
|
def print_with_two_numerical(
|
|
107
|
-
sim_moments: list[float] |
|
|
108
|
-
calc_moments1: list[float] |
|
|
109
|
-
calc_moments2: list[float] |
|
|
185
|
+
sim_moments: list[float] | float,
|
|
186
|
+
calc_moments1: list[float] | float,
|
|
187
|
+
calc_moments2: list[float] | float,
|
|
110
188
|
num1_header="Num1",
|
|
111
189
|
num2_header="Num2",
|
|
112
190
|
):
|
|
113
191
|
"""
|
|
114
|
-
Prints the
|
|
192
|
+
Prints the moments.
|
|
115
193
|
Args:
|
|
116
194
|
sim_moments (list): List of simulated moments.
|
|
117
195
|
calc_moments1 (list): List of calculated moments for the first approximation.
|
|
@@ -164,7 +242,7 @@ def print_with_two_numerical(
|
|
|
164
242
|
print(Style.RESET_ALL)
|
|
165
243
|
|
|
166
244
|
|
|
167
|
-
def
|
|
245
|
+
def print_waiting_moments_with_two_numerical(
|
|
168
246
|
sim_moments,
|
|
169
247
|
calc_moments1,
|
|
170
248
|
calc_moments2,
|
|
@@ -172,7 +250,7 @@ def print_waiting_times_with_two_numerical(
|
|
|
172
250
|
num2_header="Num2",
|
|
173
251
|
):
|
|
174
252
|
"""
|
|
175
|
-
Prints the
|
|
253
|
+
Prints the moments of waiting in the system.
|
|
176
254
|
Args:
|
|
177
255
|
sim_moments (list): List of simulated moments.
|
|
178
256
|
calc_moments1 (list): List of calculated moments for the first approximation.
|
|
@@ -182,7 +260,7 @@ def print_waiting_times_with_two_numerical(
|
|
|
182
260
|
|
|
183
261
|
"""
|
|
184
262
|
|
|
185
|
-
header = "
|
|
263
|
+
header = "Moments of waiting time in the system"
|
|
186
264
|
|
|
187
265
|
print(Fore.CYAN + f"\n{header:^45}")
|
|
188
266
|
print("-" * 60)
|
|
@@ -195,7 +273,7 @@ def print_waiting_times_with_two_numerical(
|
|
|
195
273
|
)
|
|
196
274
|
|
|
197
275
|
|
|
198
|
-
def
|
|
276
|
+
def print_sojourn_moments_with_two_numerical(
|
|
199
277
|
sim_moments,
|
|
200
278
|
calc_moments1,
|
|
201
279
|
calc_moments2,
|
|
@@ -203,7 +281,7 @@ def print_sojourn_times_with_two_numerical(
|
|
|
203
281
|
num2_header="Num2",
|
|
204
282
|
):
|
|
205
283
|
"""
|
|
206
|
-
Prints the
|
|
284
|
+
Prints the nts of sojourn time in the system.
|
|
207
285
|
Args:
|
|
208
286
|
sim_moments (list): List of simulated moments.
|
|
209
287
|
calc_moments1 (list): List of calculated moments for the first approximation.
|
|
@@ -213,7 +291,7 @@ def print_sojourn_times_with_two_numerical(
|
|
|
213
291
|
|
|
214
292
|
"""
|
|
215
293
|
|
|
216
|
-
header = "
|
|
294
|
+
header = "Moments of sojourn time in the system"
|
|
217
295
|
|
|
218
296
|
print(Fore.CYAN + f"\n{header:^45}")
|
|
219
297
|
print("-" * 60)
|
|
@@ -226,16 +304,25 @@ def print_sojourn_times_with_two_numerical(
|
|
|
226
304
|
)
|
|
227
305
|
|
|
228
306
|
|
|
229
|
-
def
|
|
307
|
+
def print_raw_moments_multiclass(sim_moments, calc_moments, convert_to_central=True):
|
|
230
308
|
"""
|
|
231
309
|
Print moments with classes
|
|
232
310
|
:param sim_moments: Simulated moments
|
|
233
311
|
:param calc_moments: Calculated moments
|
|
234
312
|
"""
|
|
313
|
+
|
|
314
|
+
if convert_to_central:
|
|
315
|
+
sim_moments = [convert_raw_to_central(mom) for mom in sim_moments]
|
|
316
|
+
calc_moments = [convert_raw_to_central(mom) for mom in calc_moments]
|
|
317
|
+
blank_col, header_col, cls_col = "", "Moment", "Cls"
|
|
318
|
+
else:
|
|
319
|
+
blank_col, header_col, cls_col = "", "Number of moment", "Cls"
|
|
320
|
+
|
|
321
|
+
central_moments_names = ["Mean", "Variance", "Skewness", "Kurtosis"]
|
|
322
|
+
|
|
235
323
|
k_num = len(sim_moments)
|
|
236
|
-
size = len(sim_moments[0])
|
|
324
|
+
size = min(len(sim_moments[0]), len(calc_moments[0]))
|
|
237
325
|
|
|
238
|
-
blank_col, header_col, cls_col = "", "Number of moment", "Cls"
|
|
239
326
|
num_col, sim_col = "Num", "Sim"
|
|
240
327
|
|
|
241
328
|
print("-" * 60)
|
|
@@ -245,7 +332,10 @@ def print_moments_with_classes(sim_moments, calc_moments):
|
|
|
245
332
|
|
|
246
333
|
print(" " * 11 + "|", end="")
|
|
247
334
|
for j in range(size):
|
|
248
|
-
|
|
335
|
+
if convert_to_central:
|
|
336
|
+
s = central_moments_names[j]
|
|
337
|
+
else:
|
|
338
|
+
s = str(j + 1)
|
|
249
339
|
print(f"{s:^15}|", end="")
|
|
250
340
|
print("")
|
|
251
341
|
print("-" * 60)
|
|
@@ -270,30 +360,30 @@ def print_moments_with_classes(sim_moments, calc_moments):
|
|
|
270
360
|
print(Style.RESET_ALL)
|
|
271
361
|
|
|
272
362
|
|
|
273
|
-
def
|
|
363
|
+
def print_waiting_multiclass(sim_moments, calc_moments, convert_to_central=True):
|
|
274
364
|
"""
|
|
275
365
|
Print waiting moments with classes
|
|
276
366
|
:param sim_moments: Simulated moments
|
|
277
367
|
:param calc_moments: Calculated moments
|
|
278
368
|
"""
|
|
279
|
-
header = "
|
|
369
|
+
header = "Moments of waiting time in the system"
|
|
280
370
|
|
|
281
371
|
print(Fore.CYAN + f"{header:^60s}")
|
|
282
372
|
|
|
283
|
-
|
|
373
|
+
print_raw_moments_multiclass(sim_moments, calc_moments, convert_to_central)
|
|
284
374
|
|
|
285
375
|
|
|
286
|
-
def
|
|
376
|
+
def print_sojourn_multiclass(sim_moments, calc_moments, convert_to_central=True):
|
|
287
377
|
"""
|
|
288
378
|
Print sojourn moments with classes
|
|
289
379
|
:param sim_moments: Simulated moments
|
|
290
380
|
:param calc_moments: Calculated moments
|
|
291
381
|
"""
|
|
292
|
-
header = "
|
|
382
|
+
header = "Moments of sojourn time in the system"
|
|
293
383
|
|
|
294
384
|
print(Fore.CYAN + f"{header:^60s}")
|
|
295
385
|
|
|
296
|
-
|
|
386
|
+
print_raw_moments_multiclass(sim_moments, calc_moments, convert_to_central)
|
|
297
387
|
|
|
298
388
|
|
|
299
389
|
def probs_print(p_sim, p_num, size=10):
|
most_queue/misc/calc_v_pls.py
CHANGED
|
@@ -29,7 +29,7 @@ class MGnNegativeRCSCalc(MGnCalc):
|
|
|
29
29
|
):
|
|
30
30
|
"""
|
|
31
31
|
n: number of servers
|
|
32
|
-
b:
|
|
32
|
+
b: raw moments of service time distribution
|
|
33
33
|
buffer: size of the buffer (optional)
|
|
34
34
|
N: number of levels in the system (default is 150)
|
|
35
35
|
accuracy: accuracy parameter for stopping the iteration
|
|
@@ -55,8 +55,8 @@ class MGnNegativeRCSCalc(MGnCalc):
|
|
|
55
55
|
|
|
56
56
|
def set_servers(self, b: list[float]): # pylint: disable=arguments-differ
|
|
57
57
|
"""
|
|
58
|
-
Set the
|
|
59
|
-
:param b:
|
|
58
|
+
Set the raw moments of service time distribution
|
|
59
|
+
:param b: raw moments of service time distribution
|
|
60
60
|
"""
|
|
61
61
|
self.b = b
|
|
62
62
|
self.is_servers_set = True
|
|
@@ -32,10 +32,10 @@ def get_sim_stat(stat, n, l, buff, b, b_c, b_w, b_d, num_of_jobs, p_limit, sim_a
|
|
|
32
32
|
:param n: number of servers
|
|
33
33
|
:param l: arrival rate
|
|
34
34
|
:param buff: buffer size
|
|
35
|
-
:param b:
|
|
36
|
-
:param b_c:
|
|
37
|
-
:param b_w:
|
|
38
|
-
:param b_d:
|
|
35
|
+
:param b: raw moments of service time
|
|
36
|
+
:param b_c: raw moments of cooling time
|
|
37
|
+
:param b_w: raw moments of warming time
|
|
38
|
+
:param b_d: raw moments of delay of the start of cooling time
|
|
39
39
|
:param num_of_jobs: number of jobs to simulate
|
|
40
40
|
:param p_limit: limit for the probability of state
|
|
41
41
|
:param sim_ave: number of simulations to average the results
|
|
@@ -107,10 +107,10 @@ def get_tt_stat(stat, n, l, buff, b, b_c, b_w, b_d, p_limit, w_pls_dt, stable_w_
|
|
|
107
107
|
:param n: number of servers
|
|
108
108
|
:param l: arrival rate
|
|
109
109
|
:param buff: buffer size (None if infinite)
|
|
110
|
-
:param b:
|
|
111
|
-
:param b_c:
|
|
112
|
-
:param b_w:
|
|
113
|
-
:param b_d:
|
|
110
|
+
:param b: raw moments of service time
|
|
111
|
+
:param b_c: raw moments of cooling time
|
|
112
|
+
:param b_w: raw moments of warming time
|
|
113
|
+
:param b_d: raw moments of delay time before cooling starts
|
|
114
114
|
:param p_limit: limit for the sum of probabilities in the Takahasi-Takami method
|
|
115
115
|
:param w_pls_dt: step for the Laplace-Stieltjes transform calculation
|
|
116
116
|
:param stable_w_pls: flag for using a stable version
|
|
@@ -189,7 +189,7 @@ def run_ro(
|
|
|
189
189
|
p_limit - max number of probabilities
|
|
190
190
|
|
|
191
191
|
w_pls_dt - some variable to stabilize derivative of the Laplace-Stieltjes transform
|
|
192
|
-
for the waiting time
|
|
192
|
+
for the waiting time raw moments calculation
|
|
193
193
|
|
|
194
194
|
stable_w_pls - if True the algorithm try to fit w_pls_dt value
|
|
195
195
|
taking into account the values of transition intensities
|
|
@@ -300,7 +300,7 @@ def run_n(
|
|
|
300
300
|
p_limit - max number of probabilities
|
|
301
301
|
|
|
302
302
|
w_pls_dt - some variable to stabilize derivative of the Laplace-Stieltjes transform
|
|
303
|
-
for the waiting time
|
|
303
|
+
for the waiting time raw moments calculation
|
|
304
304
|
|
|
305
305
|
stable_w_pls - if True the algorithm try to fit w_pls_dt value
|
|
306
306
|
taking into account the values of transition intensities
|
|
@@ -411,7 +411,7 @@ def run_delay_mean(
|
|
|
411
411
|
p_limit - max number of probabilities
|
|
412
412
|
|
|
413
413
|
w_pls_dt - some variable to stabilize derivative of the Laplace-Stieltjes transform
|
|
414
|
-
for the waiting time
|
|
414
|
+
for the waiting time raw moments calculation
|
|
415
415
|
|
|
416
416
|
stable_w_pls - if True the algorithm try to fit w_pls_dt value
|
|
417
417
|
taking into account the values of transition intensities
|
|
@@ -7,7 +7,7 @@ import os
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
import yaml
|
|
9
9
|
|
|
10
|
-
from most_queue.io.tables import
|
|
10
|
+
from most_queue.io.tables import print_sojourn_moments
|
|
11
11
|
from most_queue.random.distributions import GammaDistribution
|
|
12
12
|
from most_queue.sim.fork_join_delta import ForkJoinSimDelta
|
|
13
13
|
from most_queue.theory.fork_join.split_join import SplitJoinCalc
|
|
@@ -72,7 +72,7 @@ def test_fj_delta():
|
|
|
72
72
|
print(f"Coefficient of variation of delay: {SERVICE_TIME_CV:.3f}")
|
|
73
73
|
print(f"Utilization coefficient: {utilization:.3f}")
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
print_sojourn_moments(v_sim, v_num)
|
|
76
76
|
|
|
77
77
|
assert len(v_sim) == len(v_num)
|
|
78
78
|
assert np.allclose(np.array(v_sim), np.array(v_num), rtol=MOMENTS_RTOL, atol=MOMENTS_ATOL), ERROR_MSG
|
|
@@ -7,7 +7,7 @@ import math
|
|
|
7
7
|
|
|
8
8
|
import matplotlib.pyplot as plt
|
|
9
9
|
|
|
10
|
-
from most_queue.io.tables import
|
|
10
|
+
from most_queue.io.tables import print_waiting_moments, probs_print
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def print_table(experiments_stat):
|
|
@@ -47,7 +47,7 @@ def print_table(experiments_stat):
|
|
|
47
47
|
print(f"Simulation time: {stat['sim_time']:0.3f} c")
|
|
48
48
|
|
|
49
49
|
probs_print(p_sim=stat["p_sim"], p_num=stat["p_tt"], size=10)
|
|
50
|
-
|
|
50
|
+
print_waiting_moments(sim_moments=stat["w_sim"], calc_moments=stat["w_tt"])
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
def dump_stat(experiments_stat, save_name="run_stat.json"):
|
|
@@ -72,7 +72,7 @@ def load_stat(stat_name):
|
|
|
72
72
|
|
|
73
73
|
def make_plot(experiments_stat, w_moments_num=0, param_name="ro", mode="error", save_path=None):
|
|
74
74
|
"""
|
|
75
|
-
Build plot for wait times
|
|
75
|
+
Build plot for wait times raw moments
|
|
76
76
|
:param experiments_stat: list of experiment statistics
|
|
77
77
|
:param w_moments_num: number of moment to plot (0 - mean, 1 - variance, 2 - skewness)
|
|
78
78
|
:param param_name: name of parameter to use for x-axis
|
|
@@ -125,10 +125,10 @@ class Weibull(Distribution):
|
|
|
125
125
|
def get_params(moments: list[float]) -> WeibullParams:
|
|
126
126
|
"""
|
|
127
127
|
Parameter selection for the distribution based
|
|
128
|
-
on
|
|
128
|
+
on raw moments of the distribution
|
|
129
129
|
|
|
130
130
|
params:
|
|
131
|
-
moments:
|
|
131
|
+
moments: raw moments of the random variable
|
|
132
132
|
|
|
133
133
|
return:
|
|
134
134
|
WeibullParams
|
|
@@ -218,7 +218,7 @@ class NormalDistribution(Distribution):
|
|
|
218
218
|
@staticmethod
|
|
219
219
|
def calc_theory_moments(params: GaussianParams, num=3) -> list[float]:
|
|
220
220
|
"""
|
|
221
|
-
Method calculates theoretical
|
|
221
|
+
Method calculates theoretical raw moments for the uniform distribution.
|
|
222
222
|
:param params: list of parameters [mean, half_interval]
|
|
223
223
|
:param num: number of moments to calculate
|
|
224
224
|
:return: list of theoretical moments
|
|
@@ -434,7 +434,7 @@ class H2Distribution(Distribution):
|
|
|
434
434
|
@staticmethod
|
|
435
435
|
def get_params(moments: list[float]) -> H2Params:
|
|
436
436
|
"""
|
|
437
|
-
Aliev's method for calculating the parameters of H2 distribution by given
|
|
437
|
+
Aliev's method for calculating the parameters of H2 distribution by given raw moments.
|
|
438
438
|
Only real parameters are selected.
|
|
439
439
|
Returns a list with parameters [y1, mu1, mu2].
|
|
440
440
|
"""
|
|
@@ -444,7 +444,7 @@ class H2Distribution(Distribution):
|
|
|
444
444
|
@staticmethod
|
|
445
445
|
def get_params_clx(moments: list[float], fitting_params: FittingParams | None = None) -> H2Params:
|
|
446
446
|
"""
|
|
447
|
-
Method of fitting H2 distribution parameters to given
|
|
447
|
+
Method of fitting H2 distribution parameters to given raw moments.
|
|
448
448
|
Uses the method of moments and optimization to fit the parameters.
|
|
449
449
|
Returns H2Params object with fitted parameters.
|
|
450
450
|
"""
|
|
@@ -544,7 +544,7 @@ class CoxDistribution(Distribution):
|
|
|
544
544
|
@staticmethod
|
|
545
545
|
def calc_theory_moments(params: Cox2Params, num: int = 3) -> list[float]:
|
|
546
546
|
"""
|
|
547
|
-
Calculates the theoretical
|
|
547
|
+
Calculates the theoretical raw moments of the Coxian distribution.
|
|
548
548
|
"""
|
|
549
549
|
y1, m1, m2 = params.p1, params.mu1, params.mu2
|
|
550
550
|
|
|
@@ -568,7 +568,7 @@ class CoxDistribution(Distribution):
|
|
|
568
568
|
@staticmethod
|
|
569
569
|
def get_params(moments: list[float], fitting_params: FittingParams | None = None) -> Cox2Params:
|
|
570
570
|
"""
|
|
571
|
-
Calculates Cox-2 distribution parameters by three given
|
|
571
|
+
Calculates Cox-2 distribution parameters by three given raw moments [moments].
|
|
572
572
|
"""
|
|
573
573
|
return fit_cox(moments, fitting_params=fitting_params)
|
|
574
574
|
|
|
@@ -726,7 +726,7 @@ class ParetoDistribution(Distribution):
|
|
|
726
726
|
def get_params(moments: list[float]):
|
|
727
727
|
"""
|
|
728
728
|
Calc parameters of the distribution.
|
|
729
|
-
:param moments: list of
|
|
729
|
+
:param moments: list of raw moments
|
|
730
730
|
"""
|
|
731
731
|
|
|
732
732
|
return fit_pareto_moments(moments)
|
|
@@ -805,7 +805,7 @@ class ErlangDistribution(Distribution):
|
|
|
805
805
|
@staticmethod
|
|
806
806
|
def calc_theory_moments(params: ErlangParams, num: int = 3) -> list[float]:
|
|
807
807
|
"""
|
|
808
|
-
Calculates theoretical
|
|
808
|
+
Calculates theoretical raw moments of the distribution. By default - first three.
|
|
809
809
|
"""
|
|
810
810
|
r, mu = params.r, params.mu
|
|
811
811
|
|
|
@@ -820,7 +820,7 @@ class ErlangDistribution(Distribution):
|
|
|
820
820
|
@staticmethod
|
|
821
821
|
def get_params(moments: list[float]) -> ErlangParams:
|
|
822
822
|
"""
|
|
823
|
-
Calculates parameters of the Erlang distribution by
|
|
823
|
+
Calculates parameters of the Erlang distribution by raw moments.
|
|
824
824
|
"""
|
|
825
825
|
return fit_erlang(moments)
|
|
826
826
|
|
most_queue/random/utils/fit.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Methods for fitting distributions to given
|
|
2
|
+
Methods for fitting distributions to given raw moments.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
import cmath
|
|
@@ -8,6 +8,7 @@ from dataclasses import dataclass
|
|
|
8
8
|
|
|
9
9
|
import numpy as np
|
|
10
10
|
|
|
11
|
+
from most_queue.constants import MAX_FIT_ITERATIONS
|
|
11
12
|
from most_queue.random.utils.params import (
|
|
12
13
|
Cox2Params,
|
|
13
14
|
ErlangParams,
|
|
@@ -33,7 +34,7 @@ class FittingParams:
|
|
|
33
34
|
|
|
34
35
|
def fit_h2(moments: list[float]) -> H2Params:
|
|
35
36
|
"""
|
|
36
|
-
Aliev's method for calculating the parameters of H2 distribution by given
|
|
37
|
+
Aliev's method for calculating the parameters of H2 distribution by given raw moments.
|
|
37
38
|
Only real parameters are selected.
|
|
38
39
|
Returns a list with parameters [y1, mu1, mu2].
|
|
39
40
|
"""
|
|
@@ -60,7 +61,7 @@ def fit_h2(moments: list[float]) -> H2Params:
|
|
|
60
61
|
res = H2Params(p1=q_max, mu1=mu1, mu2=1e6)
|
|
61
62
|
return res
|
|
62
63
|
|
|
63
|
-
max_iteration =
|
|
64
|
+
max_iteration = MAX_FIT_ITERATIONS
|
|
64
65
|
tec = 0
|
|
65
66
|
t1 = 0
|
|
66
67
|
t2 = 0
|
|
@@ -83,7 +84,7 @@ def fit_h2(moments: list[float]) -> H2Params:
|
|
|
83
84
|
|
|
84
85
|
def fit_h2_clx(moments: list[float], fitting_params: FittingParams | None = None) -> H2Params:
|
|
85
86
|
"""
|
|
86
|
-
Method of fitting H2 distribution parameters to given
|
|
87
|
+
Method of fitting H2 distribution parameters to given raw moments.
|
|
87
88
|
Uses the method of moments and optimization to fit the parameters.
|
|
88
89
|
Returns H2Params object with fitted parameters.
|
|
89
90
|
"""
|
|
@@ -136,7 +137,7 @@ def fit_h2_clx(moments: list[float], fitting_params: FittingParams | None = None
|
|
|
136
137
|
|
|
137
138
|
def fit_cox(moments: list[float], fitting_params: FittingParams | None = None) -> Cox2Params:
|
|
138
139
|
"""
|
|
139
|
-
Calculates Cox-2 distribution parameters by three given
|
|
140
|
+
Calculates Cox-2 distribution parameters by three given raw moments [moments].
|
|
140
141
|
"""
|
|
141
142
|
|
|
142
143
|
if not fitting_params:
|
|
@@ -183,7 +184,7 @@ def fit_cox(moments: list[float], fitting_params: FittingParams | None = None) -
|
|
|
183
184
|
def fit_pareto_moments(moments: list[float]):
|
|
184
185
|
"""
|
|
185
186
|
Calc parameters of the distribution.
|
|
186
|
-
:param moments: list of
|
|
187
|
+
:param moments: list of raw moments
|
|
187
188
|
"""
|
|
188
189
|
d = moments[1] - moments[0] * moments[0]
|
|
189
190
|
c = moments[0] * moments[0] / d
|
|
@@ -209,7 +210,7 @@ def fit_pareto_by_mean_and_cv(f1: float, cv: float):
|
|
|
209
210
|
|
|
210
211
|
def fit_erlang(moments: list[float]) -> ErlangParams:
|
|
211
212
|
"""
|
|
212
|
-
Calculates parameters of the Erlang distribution by
|
|
213
|
+
Calculates parameters of the Erlang distribution by raw moments.
|
|
213
214
|
"""
|
|
214
215
|
r = int(math.floor(moments[0] * moments[0] / (moments[1] - moments[0] * moments[0]) + 0.5))
|
|
215
216
|
mu = r / moments[0]
|
|
@@ -290,10 +291,10 @@ def fit_gamma(moments: list[float]) -> GammaParams:
|
|
|
290
291
|
def fit_weibull(moments: list[float]) -> WeibullParams:
|
|
291
292
|
"""
|
|
292
293
|
Parameter selection for the distribution based
|
|
293
|
-
on
|
|
294
|
+
on raw moments of the distribution
|
|
294
295
|
|
|
295
296
|
params:
|
|
296
|
-
moments:
|
|
297
|
+
moments: raw moments of the random variable
|
|
297
298
|
|
|
298
299
|
return:
|
|
299
300
|
WeibullParams
|
|
@@ -319,9 +320,10 @@ def gamma_moments_by_mean_and_cv(mean: float, cv: float) -> list[float]:
|
|
|
319
320
|
Calculate the first three moments of a gamma distribution
|
|
320
321
|
given the mean and coefficient of variation.
|
|
321
322
|
"""
|
|
322
|
-
f = [0, 0, 0]
|
|
323
|
+
f = [0, 0, 0, 0]
|
|
323
324
|
alpha = 1 / (cv**2)
|
|
324
325
|
f[0] = mean
|
|
325
326
|
f[1] = pow(f[0], 2) * (pow(cv, 2) + 1)
|
|
326
327
|
f[2] = f[1] * f[0] * (1.0 + 2 / alpha)
|
|
328
|
+
f[3] = f[2] * f[0] * (1.0 + 3 / alpha)
|
|
327
329
|
return f
|
most_queue/sim/__init__.py
CHANGED