most-queue 1.49__tar.gz → 1.50__tar.gz

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.

Potentially problematic release.


This version of most-queue might be problematic. Click here for more details.

Files changed (109) hide show
  1. most_queue-1.50/PKG-INFO +250 -0
  2. most_queue-1.50/README.md +210 -0
  3. most_queue-1.50/deploy.txt +3 -0
  4. {most_queue-1.49 → most_queue-1.50}/most_queue/general_utils/tables.py +38 -14
  5. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/engset_model.py +4 -1
  6. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/m_h2_h2warm.py +2 -3
  7. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/mgn_with_h2_delay_cold_warm.py +49 -27
  8. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/mmn_with_h2_cold_and_h2_warmup.py +22 -17
  9. {most_queue-1.49 → most_queue-1.50}/pyproject.toml +5 -3
  10. {most_queue-1.49 → most_queue-1.50}/requirements.txt +1 -1
  11. {most_queue-1.49 → most_queue-1.50}/setup.py +5 -3
  12. {most_queue-1.49 → most_queue-1.50}/tests/test_mg1_calc.py +11 -11
  13. most_queue-1.50/tests/test_qs_sim_prty.py +111 -0
  14. most_queue-1.50/tutorials/m_h2_h2warm.ipynb +347 -0
  15. most_queue-1.50/tutorials/mgn_takahasi_takami.ipynb +298 -0
  16. most_queue-1.50/tutorials/priority queue.ipynb +369 -0
  17. most_queue-1.50/tutorials/queue_sim.ipynb +334 -0
  18. most_queue-1.49/PKG-INFO +0 -242
  19. most_queue-1.49/README.md +0 -204
  20. most_queue-1.49/tests/test_qs_sim_prty.py +0 -111
  21. most_queue-1.49/tutorials/1_queue_sim.ipynb +0 -377
  22. most_queue-1.49/tutorials/2_mgn_takahasi_takami.ipynb +0 -305
  23. most_queue-1.49/tutorials/3 priority queue.ipynb +0 -381
  24. most_queue-1.49/tutorials/m_h2_h2warm.ipynb +0 -338
  25. {most_queue-1.49 → most_queue-1.50}/.gitignore +0 -0
  26. {most_queue-1.49 → most_queue-1.50}/LICENSE +0 -0
  27. {most_queue-1.49 → most_queue-1.50}/assets/IMPATIENCE.jpg +0 -0
  28. {most_queue-1.49 → most_queue-1.50}/assets/queue.jpg +0 -0
  29. {most_queue-1.49 → most_queue-1.50}/assets/queue2.jpg +0 -0
  30. {most_queue-1.49 → most_queue-1.50}/assets/queue3.jpg +0 -0
  31. {most_queue-1.49 → most_queue-1.50}/assets/queue4.jpg +0 -0
  32. {most_queue-1.49 → most_queue-1.50}/assets/queue5.jpg +0 -0
  33. {most_queue-1.49 → most_queue-1.50}/assets/queue6.jpg +0 -0
  34. {most_queue-1.49 → most_queue-1.50}/most_queue/__init__.py +0 -0
  35. {most_queue-1.49 → most_queue-1.50}/most_queue/general_utils/__init__.py +0 -0
  36. {most_queue-1.49 → most_queue-1.50}/most_queue/general_utils/approx_cdf_make.py +0 -0
  37. {most_queue-1.49 → most_queue-1.50}/most_queue/general_utils/conv.py +0 -0
  38. {most_queue-1.49 → most_queue-1.50}/most_queue/general_utils/vacations_paper_utils.py +0 -0
  39. {most_queue-1.49 → most_queue-1.50}/most_queue/misc/compare_fj_calc.py +0 -0
  40. {most_queue-1.49 → most_queue-1.50}/most_queue/misc/flow_sum.py +0 -0
  41. {most_queue-1.49 → most_queue-1.50}/most_queue/misc/test_weibull.py +0 -0
  42. {most_queue-1.49 → most_queue-1.50}/most_queue/rand_distribution.py +0 -0
  43. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/__init__.py +0 -0
  44. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/batch_sim.py +0 -0
  45. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/fj_delta_sim.py +0 -0
  46. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/fj_sim.py +0 -0
  47. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/flow_sum_sim.py +0 -0
  48. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/impatient_queue_sim.py +0 -0
  49. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/priority_network.py +0 -0
  50. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/priority_queue_sim.py +0 -0
  51. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/qs_sim.py +0 -0
  52. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/queue_finite_source_sim.py +0 -0
  53. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/utils/__init__.py +0 -0
  54. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/utils/distribution_utils.py +0 -0
  55. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/utils/exceptions.py +0 -0
  56. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/utils/phase.py +0 -0
  57. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/utils/qs_queue.py +0 -0
  58. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/utils/servers.py +0 -0
  59. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/utils/stats_update.py +0 -0
  60. {most_queue-1.49 → most_queue-1.50}/most_queue/sim/utils/tasks.py +0 -0
  61. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/__init__.py +0 -0
  62. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/batch_mm1.py +0 -0
  63. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/ek_d_n_calc.py +0 -0
  64. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/fj_calc.py +0 -0
  65. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/gi_m_1_calc.py +0 -0
  66. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/gi_m_n_calc.py +0 -0
  67. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/impatience_calc.py +0 -0
  68. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/m_d_n_calc.py +0 -0
  69. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/m_ph_n_prty.py +0 -0
  70. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/mg1_calc.py +0 -0
  71. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/mg1_warm_calc.py +0 -0
  72. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/mgn_tt.py +0 -0
  73. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/mmn3_pnz_cox_approx.py +0 -0
  74. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/mmn_prty_pnz_approx.py +0 -0
  75. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/mmnr_calc.py +0 -0
  76. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/network_calc.py +0 -0
  77. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/network_viewer.py +0 -0
  78. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/priority_calc.py +0 -0
  79. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/r_example.gexf +0 -0
  80. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/utils/__init__.py +0 -0
  81. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/utils/binom_probs.py +0 -0
  82. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/utils/diff5dots.py +0 -0
  83. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/utils/flow_sum.py +0 -0
  84. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/utils/passage_time.py +0 -0
  85. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/utils/q_poisson_arrival_calc.py +0 -0
  86. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/utils/student_stat.py +0 -0
  87. {most_queue-1.49 → most_queue-1.50}/most_queue/theory/utils/weibull.py +0 -0
  88. {most_queue-1.49 → most_queue-1.50}/tests/__init__.py +0 -0
  89. {most_queue-1.49 → most_queue-1.50}/tests/n_test/ro_0.700.json +0 -0
  90. {most_queue-1.49 → most_queue-1.50}/tests/ro_test/n_3.json +0 -0
  91. {most_queue-1.49 → most_queue-1.50}/tests/test_batch.py +0 -0
  92. {most_queue-1.49 → most_queue-1.50}/tests/test_ek_d_n.py +0 -0
  93. {most_queue-1.49 → most_queue-1.50}/tests/test_engset.py +0 -0
  94. {most_queue-1.49 → most_queue-1.50}/tests/test_fj_delta.py +0 -0
  95. {most_queue-1.49 → most_queue-1.50}/tests/test_fj_im.py +0 -0
  96. {most_queue-1.49 → most_queue-1.50}/tests/test_gi_m_1_calc.py +0 -0
  97. {most_queue-1.49 → most_queue-1.50}/tests/test_gi_m_n_calc.py +0 -0
  98. {most_queue-1.49 → most_queue-1.50}/tests/test_impatience.py +0 -0
  99. {most_queue-1.49 → most_queue-1.50}/tests/test_m_d_n_calc.py +0 -0
  100. {most_queue-1.49 → most_queue-1.50}/tests/test_m_h2_h2warm.py +0 -0
  101. {most_queue-1.49 → most_queue-1.50}/tests/test_m_ph_n_prty.py +0 -0
  102. {most_queue-1.49 → most_queue-1.50}/tests/test_mgn_tt.py +0 -0
  103. {most_queue-1.49 → most_queue-1.50}/tests/test_mgn_with_h2_delay_cold_warm.py +0 -0
  104. {most_queue-1.49 → most_queue-1.50}/tests/test_mmn3_pnz_cox_approx.py +0 -0
  105. {most_queue-1.49 → most_queue-1.50}/tests/test_mmn_h2cold_h2warm.py +0 -0
  106. {most_queue-1.49 → most_queue-1.50}/tests/test_mmn_prty_pnz_approx.py +0 -0
  107. {most_queue-1.49 → most_queue-1.50}/tests/test_network_im_prty.py +0 -0
  108. {most_queue-1.49 → most_queue-1.50}/tests/test_qs_sim_test.py +0 -0
  109. {most_queue-1.49 → most_queue-1.50}/tests/test_queue_types.py +0 -0
@@ -0,0 +1,250 @@
1
+ Metadata-Version: 2.4
2
+ Name: most_queue
3
+ Version: 1.50
4
+ Summary: Software package for calculation and simulation of queuing systems
5
+ Project-URL: Homepage, https://github.com/xabarov/most-queue
6
+ Author-email: Xabarov Roman <xabarov1985@gmail.com>
7
+ License: Copyright (c) 2018 The Python Packaging Authority
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+ License-File: LICENSE
27
+ Classifier: License :: OSI Approved :: MIT License
28
+ Classifier: Operating System :: OS Independent
29
+ Classifier: Programming Language :: Python :: 3
30
+ Requires-Python: >=3.9
31
+ Requires-Dist: colorama
32
+ Requires-Dist: graphviz
33
+ Requires-Dist: matplotlib
34
+ Requires-Dist: networkx
35
+ Requires-Dist: numpy
36
+ Requires-Dist: pandas
37
+ Requires-Dist: scipy==1.13.0
38
+ Requires-Dist: tqdm
39
+ Description-Content-Type: text/markdown
40
+
41
+ # Queueing systems. Simulation and numerical methods of Queuing theory
42
+
43
+ ![Queue](assets/queue6.jpg)
44
+
45
+ Python package for calculation and simulation of queueing systems (QS) and networks.
46
+
47
+ MOST (MOCT, Массовое обслуживание стационарные задачи) stands for “Mass Service Steady-State Problems” and refers to tasks within queueing theory that involve large-scale service systems operating under steady-state conditions.
48
+ - [Рыжиков Ю. И. Вычислительные методы. – БХВ-Петербург, 2007.](https://www.litres.ru/book/uriy-ryzhikov/vychislitelnye-metody-uchebnoe-posobie-644835/)
49
+
50
+ Queueing theory. Numerical methods.
51
+
52
+
53
+ ## Authors
54
+ - [xabarov](https://github.com/xabarov)
55
+
56
+ ## Installation
57
+ Install most-queue with pip
58
+ ```bash
59
+ pip install most-queue
60
+ ```
61
+
62
+ ## DESCRIPTION
63
+ Most_queue consists of two main parts:
64
+ - **.theory** contains programs that implement methods for calculating queuing theory models.
65
+ - **.sim** contains simulation programs.
66
+ ### Package .theory
67
+ | # | Package name | Description |
68
+ |-----|-----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
69
+ | 1. | batch_mm1 | Calculation of M/M/1 QS with batch arrival |
70
+ | 2. | ek_d_n_calc | Numerical calculation of a multi-channel system Ek/D/n |
71
+ | 3. | engset_model | Calculation of the Engset model for M/M/1 with a finite number of sources. |
72
+ | 4. | fj_calc | Numerical calculation of the initial moments of the random variables maximum distribution |
73
+ | 5. | gi_m_1_calc | Numerical calculation of QS GI/M/1 |
74
+ | 6. | gi_m_n_calc | Numerical calculation of QS GI/M/n |
75
+ | 7. | impatience_calc | Calculation of M/M/1 with exponential impatience |
76
+ | 8. | m_d_n_calc | Numerical calculation of QS M/D/n |
77
+ | 9. | m_h2_h2_warm | Calculation of the M/H2/n system with H2-warming using the Takahasi-Takagi method. |
78
+ | 10. | m_ph_n_prty | Numerical calculation of QS M/Ph/n with 2 classes and PR - priority. Based on the approximation of busy periods |
79
+ | 11. | mg1_calc | Numerical calculation of QS M/G/1 |
80
+ | 12. | mg1_warm_calc | Numerical calculation of QS M/G/1 with "warm-up" |
81
+ | 13. | mgn_tt | Numerical calculation of QS M/H2/n by the Takahashi-Takami method with complex parameters when approximating the serving time by the H2 distribution |
82
+ | 14. | mgn_with_h2_delay_cold_warm.py | Multichannel queuing system with H2 serving time, H2 warm-up, H2 cold delay and H2 cold (vacations). The system uses complex parameters, which allows you to calculate systems with arbitrary serving, warm-up, cold-delay and cold variation coefficients |
83
+ | 15. | mmn_prty_pnz_approx | Calculation of QS M/M/2 with 2 classes, PR - priority by the Takahashi-Takami numerical method based on the approximation of the busy period by the Cox distribution |
84
+ | 16. | mmn_with_h2_cold_h2_warmup.py | Multichannel queuing system with exp serving time, H2 warm-up and H2 cold (vacations). The system uses complex parameters, which allows to calculate systems with arbitrary warm-up and cold variation coefficients |
85
+ | 17. | mmn3_pnz_cox_approx | Calculation of QS M/M/2 with 3 classes, PR - priority by the Takahashi-Takami numerical method based on the approximation of busy period by the Cox distribution |
86
+ | 18. | mmnr_calc | Calculation of QS M/M/n/r |
87
+ | 19. | network_calc | Calculation of queuing network with priorities in nodes |
88
+ | 20. | network_viewer.py | Utility to view network structure |
89
+ | 21. | priority_calc | A set of functions for calculating QS with priorities (single-channel, multi-channel). The multichannel calculation is carried out by the method of relation |
90
+
91
+
92
+ ### Package .sim
93
+ | # | Package name | Description |
94
+ | ------------- |----------------------------|------------- |
95
+ | 1. | batch_sim | Simulation of QS in a batch system |
96
+ | 2. | fj_delta_sim | Simulation of QS fork-join with a delay in the start of processing between channels |
97
+ | 3. | fj_sim | Simulation of QS with fork-join process |
98
+ | 4. | flow_sum_sim | Simulation of flow summation |
99
+ | 5. | impatient_sim.py | Simulation of QS GI/G/m/n with impatience |
100
+ | 6. | priority_network | Simulation of queuing network with priorities in nodes |
101
+ | 7. | priority_queue_sim | Simulation of QS GI/G/m/n with priorities |
102
+ | 8. | qs_sim | Simulation of QS GI/G/m/n |
103
+ | 9. | queue_finite_source_sim.py | Simulation of QS GI/G/m/n with finite sources |
104
+
105
+ ## Usage
106
+ - Look [here](https://github.com/xabarov/most-queue/tree/main/tests) for examples
107
+ - Look [here](https://github.com/xabarov/most-queue/tree/main/tutorials) for jupyter tutorials
108
+
109
+ ### Simple example: Calculate M/G/1 queueing system calculation with `most_queue` library. Run simulation and compare results with theory.
110
+
111
+ ```python
112
+ import numpy as np
113
+
114
+ from most_queue.general_utils.tables import probs_print, times_print
115
+ from most_queue.rand_distribution import H2_dist
116
+ from most_queue.sim.qs_sim import QueueingSystemSimulator
117
+ from most_queue.theory.mg1_calc import get_p, get_v, get_w
118
+
119
+ l = 1 # input flow intensity
120
+ b1 = 0.7 # average service time
121
+ coev = 1.2 # coefficient of variation of service time
122
+ num_of_jobs = 1000000 # number of jobs for simulation
123
+
124
+ # selecting parameters of the approximating H2-distribution for service time [y1, mu1, mu2]:
125
+ params = H2_dist.get_params_by_mean_and_coev(b1, coev)
126
+ b = H2_dist.calc_theory_moments(*params, 4)
127
+
128
+ # calculation using numerical methods
129
+ w_ch = get_w(l, b)
130
+ p_ch = get_p(l, b, 100)
131
+ v_ch = get_v(l, b)
132
+
133
+ # running simulation for verification of results
134
+ qs = QueueingSystemSimulator(1)
135
+ qs.set_servers(params, "H")
136
+ qs.set_sources(l, "M")
137
+ qs.run(num_of_jobs)
138
+ w_sim = qs.w
139
+ p_sim = qs.get_p()
140
+ v_sim = qs.v
141
+
142
+ # outputting the results
143
+ print("M/H2/1")
144
+
145
+ times_print(w_sim, w_ch, True)
146
+ times_print(v_sim, v_ch, False)
147
+ probs_print(p_sim, p_ch, 10)
148
+ ```
149
+
150
+ ### Priority queue example. For verification, comparing results with those calculated using the method of [invariant relations](https://cyberleninka.ru/article/n/raschet-mnogokanalnyh-sistem-obsluzhivaniya-s-absolyutnym-i-otnositelnym-prioritetami-na-osnove-invariantov-otnosheniya)
151
+
152
+ ```python
153
+ n = 5 # number of servers
154
+ k = 3 # number of classes of requests
155
+ l = [0.2, 0.3, 0.4] # service intensities by request classes
156
+ lsum = sum(l)
157
+ num_of_jobs = 300000 # number of jobs for the simulation
158
+
159
+ # Set up the parameters for service times at initial moments.
160
+ # Set average service times by class
161
+ b1 = [0.45 * n, 0.9 * n, 1.35 * n]
162
+
163
+ # Coefficient of variation of service time let's be the same for all classes
164
+ coev = 0.577
165
+
166
+ # second initial moments
167
+ b2 = [0] * k
168
+ for i in range(k):
169
+ b2[i] = (b1[i] ** 2) * (1 + coev ** 2)
170
+
171
+ b_sr = sum(b1) / k
172
+
173
+ # get the coefficient of load
174
+ ro = lsum * b_sr / n
175
+
176
+ # now, given the two initial moments, select parameters for the approximating Gamma distribution
177
+ # and add them to the list of parameters params
178
+ params = []
179
+ for i in range(k):
180
+ params.append(Gamma.get_mu_alpha([b1[i], b2[i]]))
181
+
182
+ b = []
183
+ for j in range(k):
184
+ b.append(Gamma.calc_theory_moments(params[j][0], params[j][1], 4))
185
+
186
+ print("\nComparison of data from the simulation and results calculated using the method of invariant relations (R) \n"
187
+ "time spent in a multi-channel queue with priorities")
188
+ print("Number of servers: " + str(n) + "\nNumber of classes: " + str(k) + "\nCoefficient of load: {0:<1.2f}".format(ro) +
189
+ "\nCoefficient of variation of service time: " + str(coev) + "\n")
190
+ print("PR (Preamptive) priority")
191
+
192
+ # when creating the simulation, pass the number of servers, number of classes and type of priority.
193
+ # PR - absolute with re-service of requests
194
+ qs = PriorityQueueSimulator(n, k, "PR")
195
+
196
+ # to set up sources of requests and service servers, we need to specify a set of dictionaries with fields
197
+ # type - distribution type,
198
+ # params - its parameters.
199
+ # The number of such dictionaries in the lists sources and servers_params corresponds to the number of classes
200
+
201
+ sources = []
202
+ servers_params = []
203
+ for j in range(k):
204
+ sources.append({'type': 'M', 'params': l[j]})
205
+ servers_params.append({'type': 'Gamma', 'params': params[j]})
206
+
207
+ qs.set_sources(sources)
208
+ qs.set_servers(servers_params)
209
+
210
+ # start the simulation
211
+ qs.run(num_of_jobs)
212
+
213
+ # get the initial moments of time spent
214
+
215
+ v_sim = qs.v
216
+
217
+ # calculate them as well using the method of invariant relations (for comparison)
218
+ v_teor = priority_calc.get_v_prty_invar(l, b, n, 'PR')
219
+
220
+ assert abs(v_sim[0][0] - v_teor[0][0]) < 0.3
221
+
222
+ times_print_with_classes(v_sim, v_teor, False)
223
+
224
+ print("NP (Non-preamptive) priority")
225
+
226
+ # The same for relative priority (NP)
227
+ qs = PriorityQueueSimulator(n, k, "NP")
228
+ sources = []
229
+ servers_params = []
230
+ for j in range(k):
231
+ sources.append({'type': 'M', 'params': l[j]})
232
+ servers_params.append({'type': 'Gamma', 'params': params[j]})
233
+
234
+ qs.set_sources(sources)
235
+ qs.set_servers(servers_params)
236
+
237
+ qs.run(num_of_jobs)
238
+
239
+ v_sim = qs.v
240
+
241
+ v_teor = priority_calc.get_v_prty_invar(l, b, n, 'NP')
242
+
243
+ times_print_with_classes(v_sim, v_teor, False)
244
+ ```
245
+
246
+
247
+
248
+
249
+
250
+
@@ -0,0 +1,210 @@
1
+ # Queueing systems. Simulation and numerical methods of Queuing theory
2
+
3
+ ![Queue](assets/queue6.jpg)
4
+
5
+ Python package for calculation and simulation of queueing systems (QS) and networks.
6
+
7
+ MOST (MOCT, Массовое обслуживание стационарные задачи) stands for “Mass Service Steady-State Problems” and refers to tasks within queueing theory that involve large-scale service systems operating under steady-state conditions.
8
+ - [Рыжиков Ю. И. Вычислительные методы. – БХВ-Петербург, 2007.](https://www.litres.ru/book/uriy-ryzhikov/vychislitelnye-metody-uchebnoe-posobie-644835/)
9
+
10
+ Queueing theory. Numerical methods.
11
+
12
+
13
+ ## Authors
14
+ - [xabarov](https://github.com/xabarov)
15
+
16
+ ## Installation
17
+ Install most-queue with pip
18
+ ```bash
19
+ pip install most-queue
20
+ ```
21
+
22
+ ## DESCRIPTION
23
+ Most_queue consists of two main parts:
24
+ - **.theory** contains programs that implement methods for calculating queuing theory models.
25
+ - **.sim** contains simulation programs.
26
+ ### Package .theory
27
+ | # | Package name | Description |
28
+ |-----|-----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
29
+ | 1. | batch_mm1 | Calculation of M/M/1 QS with batch arrival |
30
+ | 2. | ek_d_n_calc | Numerical calculation of a multi-channel system Ek/D/n |
31
+ | 3. | engset_model | Calculation of the Engset model for M/M/1 with a finite number of sources. |
32
+ | 4. | fj_calc | Numerical calculation of the initial moments of the random variables maximum distribution |
33
+ | 5. | gi_m_1_calc | Numerical calculation of QS GI/M/1 |
34
+ | 6. | gi_m_n_calc | Numerical calculation of QS GI/M/n |
35
+ | 7. | impatience_calc | Calculation of M/M/1 with exponential impatience |
36
+ | 8. | m_d_n_calc | Numerical calculation of QS M/D/n |
37
+ | 9. | m_h2_h2_warm | Calculation of the M/H2/n system with H2-warming using the Takahasi-Takagi method. |
38
+ | 10. | m_ph_n_prty | Numerical calculation of QS M/Ph/n with 2 classes and PR - priority. Based on the approximation of busy periods |
39
+ | 11. | mg1_calc | Numerical calculation of QS M/G/1 |
40
+ | 12. | mg1_warm_calc | Numerical calculation of QS M/G/1 with "warm-up" |
41
+ | 13. | mgn_tt | Numerical calculation of QS M/H2/n by the Takahashi-Takami method with complex parameters when approximating the serving time by the H2 distribution |
42
+ | 14. | mgn_with_h2_delay_cold_warm.py | Multichannel queuing system with H2 serving time, H2 warm-up, H2 cold delay and H2 cold (vacations). The system uses complex parameters, which allows you to calculate systems with arbitrary serving, warm-up, cold-delay and cold variation coefficients |
43
+ | 15. | mmn_prty_pnz_approx | Calculation of QS M/M/2 with 2 classes, PR - priority by the Takahashi-Takami numerical method based on the approximation of the busy period by the Cox distribution |
44
+ | 16. | mmn_with_h2_cold_h2_warmup.py | Multichannel queuing system with exp serving time, H2 warm-up and H2 cold (vacations). The system uses complex parameters, which allows to calculate systems with arbitrary warm-up and cold variation coefficients |
45
+ | 17. | mmn3_pnz_cox_approx | Calculation of QS M/M/2 with 3 classes, PR - priority by the Takahashi-Takami numerical method based on the approximation of busy period by the Cox distribution |
46
+ | 18. | mmnr_calc | Calculation of QS M/M/n/r |
47
+ | 19. | network_calc | Calculation of queuing network with priorities in nodes |
48
+ | 20. | network_viewer.py | Utility to view network structure |
49
+ | 21. | priority_calc | A set of functions for calculating QS with priorities (single-channel, multi-channel). The multichannel calculation is carried out by the method of relation |
50
+
51
+
52
+ ### Package .sim
53
+ | # | Package name | Description |
54
+ | ------------- |----------------------------|------------- |
55
+ | 1. | batch_sim | Simulation of QS in a batch system |
56
+ | 2. | fj_delta_sim | Simulation of QS fork-join with a delay in the start of processing between channels |
57
+ | 3. | fj_sim | Simulation of QS with fork-join process |
58
+ | 4. | flow_sum_sim | Simulation of flow summation |
59
+ | 5. | impatient_sim.py | Simulation of QS GI/G/m/n with impatience |
60
+ | 6. | priority_network | Simulation of queuing network with priorities in nodes |
61
+ | 7. | priority_queue_sim | Simulation of QS GI/G/m/n with priorities |
62
+ | 8. | qs_sim | Simulation of QS GI/G/m/n |
63
+ | 9. | queue_finite_source_sim.py | Simulation of QS GI/G/m/n with finite sources |
64
+
65
+ ## Usage
66
+ - Look [here](https://github.com/xabarov/most-queue/tree/main/tests) for examples
67
+ - Look [here](https://github.com/xabarov/most-queue/tree/main/tutorials) for jupyter tutorials
68
+
69
+ ### Simple example: Calculate M/G/1 queueing system calculation with `most_queue` library. Run simulation and compare results with theory.
70
+
71
+ ```python
72
+ import numpy as np
73
+
74
+ from most_queue.general_utils.tables import probs_print, times_print
75
+ from most_queue.rand_distribution import H2_dist
76
+ from most_queue.sim.qs_sim import QueueingSystemSimulator
77
+ from most_queue.theory.mg1_calc import get_p, get_v, get_w
78
+
79
+ l = 1 # input flow intensity
80
+ b1 = 0.7 # average service time
81
+ coev = 1.2 # coefficient of variation of service time
82
+ num_of_jobs = 1000000 # number of jobs for simulation
83
+
84
+ # selecting parameters of the approximating H2-distribution for service time [y1, mu1, mu2]:
85
+ params = H2_dist.get_params_by_mean_and_coev(b1, coev)
86
+ b = H2_dist.calc_theory_moments(*params, 4)
87
+
88
+ # calculation using numerical methods
89
+ w_ch = get_w(l, b)
90
+ p_ch = get_p(l, b, 100)
91
+ v_ch = get_v(l, b)
92
+
93
+ # running simulation for verification of results
94
+ qs = QueueingSystemSimulator(1)
95
+ qs.set_servers(params, "H")
96
+ qs.set_sources(l, "M")
97
+ qs.run(num_of_jobs)
98
+ w_sim = qs.w
99
+ p_sim = qs.get_p()
100
+ v_sim = qs.v
101
+
102
+ # outputting the results
103
+ print("M/H2/1")
104
+
105
+ times_print(w_sim, w_ch, True)
106
+ times_print(v_sim, v_ch, False)
107
+ probs_print(p_sim, p_ch, 10)
108
+ ```
109
+
110
+ ### Priority queue example. For verification, comparing results with those calculated using the method of [invariant relations](https://cyberleninka.ru/article/n/raschet-mnogokanalnyh-sistem-obsluzhivaniya-s-absolyutnym-i-otnositelnym-prioritetami-na-osnove-invariantov-otnosheniya)
111
+
112
+ ```python
113
+ n = 5 # number of servers
114
+ k = 3 # number of classes of requests
115
+ l = [0.2, 0.3, 0.4] # service intensities by request classes
116
+ lsum = sum(l)
117
+ num_of_jobs = 300000 # number of jobs for the simulation
118
+
119
+ # Set up the parameters for service times at initial moments.
120
+ # Set average service times by class
121
+ b1 = [0.45 * n, 0.9 * n, 1.35 * n]
122
+
123
+ # Coefficient of variation of service time let's be the same for all classes
124
+ coev = 0.577
125
+
126
+ # second initial moments
127
+ b2 = [0] * k
128
+ for i in range(k):
129
+ b2[i] = (b1[i] ** 2) * (1 + coev ** 2)
130
+
131
+ b_sr = sum(b1) / k
132
+
133
+ # get the coefficient of load
134
+ ro = lsum * b_sr / n
135
+
136
+ # now, given the two initial moments, select parameters for the approximating Gamma distribution
137
+ # and add them to the list of parameters params
138
+ params = []
139
+ for i in range(k):
140
+ params.append(Gamma.get_mu_alpha([b1[i], b2[i]]))
141
+
142
+ b = []
143
+ for j in range(k):
144
+ b.append(Gamma.calc_theory_moments(params[j][0], params[j][1], 4))
145
+
146
+ print("\nComparison of data from the simulation and results calculated using the method of invariant relations (R) \n"
147
+ "time spent in a multi-channel queue with priorities")
148
+ print("Number of servers: " + str(n) + "\nNumber of classes: " + str(k) + "\nCoefficient of load: {0:<1.2f}".format(ro) +
149
+ "\nCoefficient of variation of service time: " + str(coev) + "\n")
150
+ print("PR (Preamptive) priority")
151
+
152
+ # when creating the simulation, pass the number of servers, number of classes and type of priority.
153
+ # PR - absolute with re-service of requests
154
+ qs = PriorityQueueSimulator(n, k, "PR")
155
+
156
+ # to set up sources of requests and service servers, we need to specify a set of dictionaries with fields
157
+ # type - distribution type,
158
+ # params - its parameters.
159
+ # The number of such dictionaries in the lists sources and servers_params corresponds to the number of classes
160
+
161
+ sources = []
162
+ servers_params = []
163
+ for j in range(k):
164
+ sources.append({'type': 'M', 'params': l[j]})
165
+ servers_params.append({'type': 'Gamma', 'params': params[j]})
166
+
167
+ qs.set_sources(sources)
168
+ qs.set_servers(servers_params)
169
+
170
+ # start the simulation
171
+ qs.run(num_of_jobs)
172
+
173
+ # get the initial moments of time spent
174
+
175
+ v_sim = qs.v
176
+
177
+ # calculate them as well using the method of invariant relations (for comparison)
178
+ v_teor = priority_calc.get_v_prty_invar(l, b, n, 'PR')
179
+
180
+ assert abs(v_sim[0][0] - v_teor[0][0]) < 0.3
181
+
182
+ times_print_with_classes(v_sim, v_teor, False)
183
+
184
+ print("NP (Non-preamptive) priority")
185
+
186
+ # The same for relative priority (NP)
187
+ qs = PriorityQueueSimulator(n, k, "NP")
188
+ sources = []
189
+ servers_params = []
190
+ for j in range(k):
191
+ sources.append({'type': 'M', 'params': l[j]})
192
+ servers_params.append({'type': 'Gamma', 'params': params[j]})
193
+
194
+ qs.set_sources(sources)
195
+ qs.set_servers(servers_params)
196
+
197
+ qs.run(num_of_jobs)
198
+
199
+ v_sim = qs.v
200
+
201
+ v_teor = priority_calc.get_v_prty_invar(l, b, n, 'NP')
202
+
203
+ times_print_with_classes(v_sim, v_teor, False)
204
+ ```
205
+
206
+
207
+
208
+
209
+
210
+
@@ -0,0 +1,3 @@
1
+ 1. Change version in pyproject.toml and setup.py
2
+ 2. hatch build
3
+ 3. upload to PyPI: twine upload dist/*
@@ -1,19 +1,27 @@
1
- from colorama import Back, Fore, Style, init
1
+ from colorama import Fore, Style, init
2
2
 
3
3
  init()
4
4
 
5
5
 
6
6
  def times_print(sim_moments, calc_moments, is_w=True):
7
+ """
8
+ Prints the initial moments of waiting or sojourn time in the system.
9
+ Args:
10
+ sim_moments (list): List of simulated moments.
11
+ calc_moments (list): List of calculated moments.
12
+ is_w (bool, optional): If True, prints waiting time moments. Otherwise, prints sojourn time moments. Defaults to True.
13
+
14
+ """
7
15
  if is_w:
8
- spec = 'ожидания'
16
+ spec = 'waiting'
9
17
  else:
10
- spec = 'пребывания'
18
+ spec = 'soujorn'
11
19
 
12
- header = f'\rНачальные моменты времени {spec} заявок в системе:'
20
+ header = f'Initial moments of {spec} time in the system'
13
21
 
14
22
  print(Fore.CYAN + f'\r{header}')
15
23
 
16
- print("{0:^15s}|{1:^15s}|{2:^15s}".format("№ момента", "Числ", "ИМ"))
24
+ print("{0:^15s}|{1:^15s}|{2:^15s}".format("#", "Num", "Sim"))
17
25
  print("-" * 45)
18
26
  if isinstance(sim_moments, list):
19
27
  for j in range(min(len(sim_moments), len(calc_moments))):
@@ -35,10 +43,17 @@ def times_print(sim_moments, calc_moments, is_w=True):
35
43
 
36
44
 
37
45
  def probs_print(p_sim, p_ch, size=10):
46
+ """
47
+ Prints the probabilities of states.
48
+ :param p_sim: Simulated probabilities
49
+ :param p_ch: Calculated probabilities
50
+ :param size: Number of states to print
51
+ :return: None
52
+ """
38
53
  print(Fore.CYAN + "-" * 36)
39
- print("{0:^36s}".format("Вероятности состояний"))
54
+ print("{0:^36s}".format("Probabilities of states"))
40
55
  print("-" * 36)
41
- print("{0:^4s}|{1:^15s}|{2:^15s}".format("№", "Числ", "ИМ"))
56
+ print("{0:^4s}|{1:^15s}|{2:^15s}".format("#", "Num", "Sim"))
42
57
  print("-" * 36)
43
58
  size = min(len(p_sim), len(p_ch), size)
44
59
  for i in range(size):
@@ -50,20 +65,29 @@ def probs_print(p_sim, p_ch, size=10):
50
65
 
51
66
 
52
67
  def times_print_with_classes(sim_moments, calc_moments, is_w=True):
68
+ """
69
+ Print moments with classes
70
+ :param sim_moments: Simulated moments
71
+ :param calc_moments: Calculated moments
72
+ :param is_w: If True, print waiting time, else print sojourn time
73
+ :return: None
74
+
75
+ """
53
76
  if is_w:
54
- spec = 'ожидания'
77
+ spec = 'waiting'
55
78
  else:
56
- spec = 'пребывания'
79
+ spec = 'soujorn'
80
+
81
+ header = f'Initial moments of {spec} time in the system'
57
82
 
58
- header = f'Начальные моменты времени {spec} заявок в системе'
59
83
  k_num = len(sim_moments)
60
84
  size = len(sim_moments[0])
61
85
 
62
86
  print(Fore.CYAN + f'{header:^60s}')
63
87
 
64
88
  print("-" * 60)
65
- print("{0:^11s}|{1:^47s}|".format('', 'Номер начального момента'))
66
- print("{0:^11s}| ".format('№ кл'), end="")
89
+ print("{0:^11s}|{1:^47s}|".format('', 'Number of moment'))
90
+ print("{0:^11s}| ".format('Cls'), end="")
67
91
  print("-" * 45 + " |")
68
92
 
69
93
  print(" " * 11 + "|", end="")
@@ -75,7 +99,7 @@ def times_print_with_classes(sim_moments, calc_moments, is_w=True):
75
99
 
76
100
  for i in range(k_num):
77
101
  print(Fore.CYAN + " " * 5 + "|", end="")
78
- print(Fore.CYAN + "{:^5s}|".format("ИМ"), end="")
102
+ print(Fore.CYAN + "{:^5s}|".format("Sim"), end="")
79
103
  for j in range(size):
80
104
  print(
81
105
  Fore.YELLOW + "{:^15.3g}".format(sim_moments[i][j]) + Fore.CYAN + "|", end="")
@@ -83,7 +107,7 @@ def times_print_with_classes(sim_moments, calc_moments, is_w=True):
83
107
  print(Fore.CYAN + "{:^5s}".format(str(i + 1)) + "|" + "-" * 54)
84
108
 
85
109
  print(Fore.CYAN + " " * 5 + "|", end="")
86
- print(Fore.CYAN + "{:^5s}|".format("Р"), end="")
110
+ print(Fore.CYAN + "{:^5s}|".format("Num"), end="")
87
111
  for j in range(size):
88
112
  print(
89
113
  Fore.YELLOW + "{:^15.3g}".format(calc_moments[i][j]) + Fore.CYAN + "|", end="")
@@ -1,10 +1,13 @@
1
+ """
2
+ Calculation of the Engset model for M/M/1 with a finite number of sources.
3
+ """
1
4
  from most_queue.theory.utils.diff5dots import diff5dots
2
5
  from most_queue.general_utils.conv import get_moments
3
6
 
4
7
 
5
8
  class Engset:
6
9
  """
7
- Расчет СМО М\М\1 с конечным числом источников m
10
+ Calculation of the Engset model for M/M/1 with a finite number of sources.
8
11
  """
9
12
 
10
13
  def __init__(self, lam, mu, m):
@@ -10,9 +10,8 @@ from most_queue.theory.utils.binom_probs import calc_binom_probs
10
10
 
11
11
  class Mh2h2Warm:
12
12
  """
13
- Расчет СМО M/H2/n с H2-разогревом численным методом Такахаси-Таками.
14
- Используются комплексные параметры. Комплексные параметры позволяют аппроксимировать распределение времени обслуживания
15
- с произвольными коэффициентами вариации (>1, <=1)
13
+ Calculation of the M/H2/n system with H2-warming using the Takahasi-Takagi method.
14
+ Use complex parameters. Complex parameters allow to approximate the service time distribution with arbitrary coefficients of variation (>1, <=1).
16
15
  """
17
16
 
18
17
  def __init__(self, l, b, b_warm, n, buffer=None, N=150, accuracy=1e-6, dtype="c16", verbose=False,