most-queue 1.62__tar.gz → 2.1__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 (245) hide show
  1. most_queue-2.1/.pre-commit-config.yaml +47 -0
  2. {most_queue-1.62 → most_queue-2.1}/PKG-INFO +12 -13
  3. {most_queue-1.62 → most_queue-2.1}/README.md +11 -12
  4. {most_queue-1.62 → most_queue-2.1}/docs/source/conf.py +10 -13
  5. most_queue-2.1/doctest-output/QS.gv +18 -0
  6. most_queue-2.1/most_queue/general/distribution_fitting.py +332 -0
  7. {most_queue-1.62 → most_queue-2.1}/most_queue/general/distribution_params.py +10 -1
  8. {most_queue-1.62 → most_queue-2.1}/most_queue/general/interfaces.py +3 -1
  9. {most_queue-1.62 → most_queue-2.1}/most_queue/general/plots.py +19 -11
  10. most_queue-2.1/most_queue/general/tables.py +347 -0
  11. {most_queue-1.62 → most_queue-2.1}/most_queue/misc/approx_cdf_make.py +9 -12
  12. {most_queue-1.62 → most_queue-2.1}/most_queue/misc/calc_v_pls.py +80 -49
  13. {most_queue-1.62 → most_queue-2.1}/most_queue/misc/compare_fj_calc.py +8 -5
  14. {most_queue-1.62 → most_queue-2.1}/most_queue/misc/flow_sum.py +31 -16
  15. {most_queue-1.62 → most_queue-2.1}/most_queue/misc/run_mgn_with_h2_delay_cold_warm.py +195 -80
  16. {most_queue-1.62/tests → most_queue-2.1/most_queue/misc}/test_fj_delta.py +24 -26
  17. most_queue-2.1/most_queue/misc/test_network_opt_approx.py +54 -0
  18. most_queue-2.1/most_queue/misc/test_network_opt_plus.py +63 -0
  19. {most_queue-1.62 → most_queue-2.1}/most_queue/misc/vacations_paper_utils.py +20 -37
  20. {most_queue-1.62 → most_queue-2.1}/most_queue/rand_distribution.py +100 -289
  21. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/base.py +58 -51
  22. most_queue-2.1/most_queue/sim/batch.py +92 -0
  23. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/finite_source.py +18 -13
  24. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/flow_sum.py +49 -24
  25. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/fork_join.py +88 -57
  26. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/fork_join_delta.py +62 -58
  27. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/impatient.py +10 -10
  28. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/negative.py +64 -50
  29. most_queue-2.1/most_queue/sim/networks/base_network_sim.py +103 -0
  30. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/networks/network.py +94 -57
  31. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/networks/priority_network.py +134 -89
  32. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/priority.py +149 -140
  33. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/utils/distribution_utils.py +52 -34
  34. most_queue-2.1/most_queue/sim/utils/distributions.yaml +24 -0
  35. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/utils/exceptions.py +2 -2
  36. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/utils/phase.py +2 -2
  37. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/utils/qs_queue.py +6 -6
  38. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/utils/servers.py +26 -30
  39. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/utils/stats_update.py +5 -2
  40. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/utils/tasks.py +21 -15
  41. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/vacations.py +53 -21
  42. most_queue-2.1/most_queue/structs.py +163 -0
  43. most_queue-2.1/most_queue/theory/base_queue.py +75 -0
  44. most_queue-2.1/most_queue/theory/batch/mm1.py +158 -0
  45. most_queue-2.1/most_queue/theory/calc_params.py +32 -0
  46. most_queue-2.1/most_queue/theory/closed/engset.py +193 -0
  47. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/fifo/ek_d_n.py +93 -56
  48. most_queue-2.1/most_queue/theory/fifo/gi_m_1.py +204 -0
  49. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/fifo/gi_m_n.py +121 -47
  50. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/fifo/m_d_n.py +50 -15
  51. most_queue-2.1/most_queue/theory/fifo/mg1.py +132 -0
  52. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/fifo/mgn_takahasi.py +135 -71
  53. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/fifo/mmnr.py +68 -19
  54. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/fork_join/m_m_n.py +119 -27
  55. most_queue-2.1/most_queue/theory/fork_join/split_join.py +135 -0
  56. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/impatience/mm1.py +68 -15
  57. most_queue-2.1/most_queue/theory/negative/mg1_disasters.py +129 -0
  58. most_queue-2.1/most_queue/theory/negative/mg1_rcs.py +117 -0
  59. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/negative/mgn_disaster.py +242 -206
  60. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/negative/mgn_rcs.py +175 -137
  61. most_queue-2.1/most_queue/theory/negative/structs.py +1 -0
  62. most_queue-2.1/most_queue/theory/networks/base_network_calc.py +123 -0
  63. most_queue-2.1/most_queue/theory/networks/network_viewer.py +94 -0
  64. most_queue-2.1/most_queue/theory/networks/open_network.py +165 -0
  65. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/networks/open_network_prty.py +82 -34
  66. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/networks/opt/transition.py +82 -77
  67. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/networks/opt/transition_approx.py +38 -30
  68. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/networks/opt/transition_plus.py +36 -23
  69. most_queue-2.1/most_queue/theory/priority/mgn_invar_approx.py +180 -0
  70. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/priority/non_preemptive/mg1.py +62 -10
  71. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/priority/preemptive/m_ph_n_busy_approx.py +162 -76
  72. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/priority/preemptive/mg1.py +61 -69
  73. most_queue-1.62/most_queue/theory/priority/preemptive/mmn_3cls_busy_approx.py → most_queue-2.1/most_queue/theory/priority/preemptive/mm2_3cls_busy_approx.py +283 -169
  74. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/priority/preemptive/mmn_2cls_pr_busy_approx.py +230 -145
  75. most_queue-2.1/most_queue/theory/utils/binom_probs.py +23 -0
  76. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/utils/busy_periods.py +18 -20
  77. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/utils/conditional.py +9 -12
  78. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/utils/conv.py +5 -4
  79. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/utils/diff5dots.py +12 -9
  80. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/utils/flow_sum.py +33 -29
  81. most_queue-2.1/most_queue/theory/utils/max_dist.py +196 -0
  82. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/utils/passage_time.py +241 -161
  83. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/utils/q_poisson_arrival_calc.py +6 -9
  84. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/utils/residual.py +8 -4
  85. most_queue-2.1/most_queue/theory/utils/student_stat.py +168 -0
  86. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/utils/transforms.py +3 -5
  87. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/utils/utilization_approx.py +18 -12
  88. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/vacations/m_h2_h2warm.py +259 -194
  89. most_queue-2.1/most_queue/theory/vacations/mg1_warm_calc.py +120 -0
  90. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/vacations/mgn_with_h2_delay_cold_warm.py +223 -158
  91. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/vacations/mmn_with_h2_cold_and_h2_warmup.py +308 -218
  92. most_queue-2.1/pyproject.toml +69 -0
  93. {most_queue-1.62 → most_queue-2.1}/requirements.txt +0 -1
  94. most_queue-2.1/setup.py +31 -0
  95. most_queue-2.1/tests/Dockerfile +13 -0
  96. {most_queue-1.62 → most_queue-2.1}/tests/default_params.yaml +1 -1
  97. most_queue-2.1/tests/run.sh +5 -0
  98. most_queue-2.1/tests/test_base_qs_sim.py +97 -0
  99. most_queue-2.1/tests/test_batch.py +83 -0
  100. {most_queue-1.62 → most_queue-2.1}/tests/test_ek_d_n.py +30 -24
  101. most_queue-2.1/tests/test_engset.py +78 -0
  102. {most_queue-1.62 → most_queue-2.1}/tests/test_fj_sim.py +55 -49
  103. most_queue-2.1/tests/test_gi_m_1_calc.py +90 -0
  104. most_queue-2.1/tests/test_gi_m_n_calc.py +99 -0
  105. most_queue-2.1/tests/test_impatience.py +69 -0
  106. most_queue-2.1/tests/test_m_d_n_calc.py +81 -0
  107. most_queue-2.1/tests/test_m_h2_h2warm.py +93 -0
  108. most_queue-2.1/tests/test_m_ph_n_prty.py +136 -0
  109. most_queue-2.1/tests/test_mg1_calc.py +85 -0
  110. most_queue-2.1/tests/test_mg1_disaster.py +91 -0
  111. most_queue-2.1/tests/test_mg1_rcs.py +74 -0
  112. most_queue-2.1/tests/test_mg1_warmup.py +86 -0
  113. most_queue-2.1/tests/test_mgn_disaster.py +81 -0
  114. most_queue-2.1/tests/test_mgn_rcs.py +84 -0
  115. most_queue-2.1/tests/test_mgn_tt.py +106 -0
  116. {most_queue-1.62 → most_queue-2.1}/tests/test_mgn_with_h2_delay_cold_warm.py +89 -88
  117. most_queue-2.1/tests/test_mm2_3cls_prty_busy.py +112 -0
  118. most_queue-2.1/tests/test_mmn_h2cold_h2warm.py +125 -0
  119. most_queue-2.1/tests/test_mmn_prty_busy_approx.py +114 -0
  120. most_queue-2.1/tests/test_network_im_prty.py +158 -0
  121. most_queue-2.1/tests/test_network_no_prty.py +97 -0
  122. {most_queue-1.62 → most_queue-2.1}/tests/test_network_opt.py +26 -15
  123. most_queue-2.1/tests/test_qs_sim.py +88 -0
  124. most_queue-2.1/tests/test_qs_sim_prty.py +144 -0
  125. {most_queue-1.62 → most_queue-2.1}/tests/units/test_busy_moments_calc.py +17 -12
  126. {most_queue-1.62 → most_queue-2.1}/tests/units/test_conditionals.py +44 -49
  127. {most_queue-1.62 → most_queue-2.1}/tests/units/test_h2_params_cv.py +21 -28
  128. {most_queue-1.62 → most_queue-2.1}/tests/units/test_queue_types.py +18 -19
  129. {most_queue-1.62 → most_queue-2.1}/tests/units/test_tt_up_probs.py +11 -13
  130. {most_queue-1.62 → most_queue-2.1}/tests/units/test_v1_on_channels.py +39 -21
  131. {most_queue-1.62 → most_queue-2.1}/tests/units/test_v1_utlization_approx.py +4 -2
  132. {most_queue-1.62 → most_queue-2.1}/tests/units/test_weibull.py +9 -4
  133. most_queue-2.1/tutorials/m_h2_h2warm.ipynb +334 -0
  134. most_queue-2.1/tutorials/mgn_takahasi_takami.ipynb +302 -0
  135. most_queue-2.1/tutorials/network_with_priorities.ipynb +384 -0
  136. {most_queue-1.62 → most_queue-2.1}/tutorials/priority_queue.ipynb +24 -18
  137. most_queue-2.1/tutorials/queue_sim.ipynb +382 -0
  138. most_queue-2.1/works/negative_queues/work_mgn_negatives.py +331 -0
  139. most_queue-2.1/works/vacations/channels.py +80 -0
  140. most_queue-2.1/works/vacations/cooling.py +182 -0
  141. most_queue-2.1/works/vacations/cooling_delay.py +179 -0
  142. {most_queue-1.62 → most_queue-2.1}/works/vacations/main.py +5 -9
  143. {most_queue-1.62 → most_queue-2.1}/works/vacations/run_one_calc_vs_sim.py +52 -33
  144. most_queue-2.1/works/vacations/service.py +86 -0
  145. most_queue-2.1/works/vacations/utilization.py +75 -0
  146. {most_queue-1.62 → most_queue-2.1}/works/vacations/utils.py +4 -21
  147. most_queue-2.1/works/vacations/warmup.py +180 -0
  148. most_queue-1.62/most_queue/general/tables.py +0 -324
  149. most_queue-1.62/most_queue/sim/batch.py +0 -89
  150. most_queue-1.62/most_queue/theory/batch/mm1.py +0 -111
  151. most_queue-1.62/most_queue/theory/closed/engset.py +0 -140
  152. most_queue-1.62/most_queue/theory/fifo/gi_m_1.py +0 -133
  153. most_queue-1.62/most_queue/theory/fifo/mg1.py +0 -91
  154. most_queue-1.62/most_queue/theory/fork_join/split_join.py +0 -303
  155. most_queue-1.62/most_queue/theory/negative/mg1_disasters.py +0 -78
  156. most_queue-1.62/most_queue/theory/negative/mg1_rcs.py +0 -84
  157. most_queue-1.62/most_queue/theory/negative/structs.py +0 -81
  158. most_queue-1.62/most_queue/theory/networks/network_viewer.py +0 -90
  159. most_queue-1.62/most_queue/theory/networks/open_network.py +0 -126
  160. most_queue-1.62/most_queue/theory/priority/mgn_invar_approx.py +0 -129
  161. most_queue-1.62/most_queue/theory/utils/binom_probs.py +0 -14
  162. most_queue-1.62/most_queue/theory/utils/student_stat.py +0 -184
  163. most_queue-1.62/most_queue/theory/vacations/mg1_warm_calc.py +0 -68
  164. most_queue-1.62/pyproject.toml +0 -34
  165. most_queue-1.62/setup.py +0 -29
  166. most_queue-1.62/tests/cold_warm_delay_params.yaml +0 -51
  167. most_queue-1.62/tests/test_base_qs_sim.py +0 -93
  168. most_queue-1.62/tests/test_batch.py +0 -79
  169. most_queue-1.62/tests/test_engset.py +0 -96
  170. most_queue-1.62/tests/test_gi_m_1_calc.py +0 -93
  171. most_queue-1.62/tests/test_gi_m_n_calc.py +0 -100
  172. most_queue-1.62/tests/test_impatience.py +0 -68
  173. most_queue-1.62/tests/test_m_d_n_calc.py +0 -71
  174. most_queue-1.62/tests/test_m_h2_h2warm.py +0 -108
  175. most_queue-1.62/tests/test_m_ph_n_prty.py +0 -144
  176. most_queue-1.62/tests/test_mg1_calc.py +0 -80
  177. most_queue-1.62/tests/test_mg1_disaster.py +0 -97
  178. most_queue-1.62/tests/test_mg1_rcs.py +0 -85
  179. most_queue-1.62/tests/test_mg1_warmup.py +0 -90
  180. most_queue-1.62/tests/test_mgn_disaster.py +0 -98
  181. most_queue-1.62/tests/test_mgn_rcs.py +0 -101
  182. most_queue-1.62/tests/test_mgn_tt.py +0 -118
  183. most_queue-1.62/tests/test_mmn_h2cold_h2warm.py +0 -144
  184. most_queue-1.62/tests/test_mmn_prty_pnz_approx.py +0 -110
  185. most_queue-1.62/tests/test_network_im_prty.py +0 -162
  186. most_queue-1.62/tests/test_network_no_prty.py +0 -77
  187. most_queue-1.62/tests/test_network_opt_approx.py +0 -42
  188. most_queue-1.62/tests/test_network_opt_plus.py +0 -49
  189. most_queue-1.62/tests/test_qs_sim.py +0 -75
  190. most_queue-1.62/tests/test_qs_sim_prty.py +0 -115
  191. most_queue-1.62/tutorials/m_h2_h2warm.ipynb +0 -338
  192. most_queue-1.62/tutorials/mgn_takahasi_takami.ipynb +0 -302
  193. most_queue-1.62/tutorials/network_with_priorities.ipynb +0 -371
  194. most_queue-1.62/tutorials/queue_sim.ipynb +0 -378
  195. most_queue-1.62/works/negative_queues/work_mgn_negatives.py +0 -303
  196. most_queue-1.62/works/vacations/channels.py +0 -69
  197. most_queue-1.62/works/vacations/cooling.py +0 -164
  198. most_queue-1.62/works/vacations/cooling_delay.py +0 -173
  199. most_queue-1.62/works/vacations/service.py +0 -75
  200. most_queue-1.62/works/vacations/utilization.py +0 -74
  201. most_queue-1.62/works/vacations/warmup.py +0 -166
  202. {most_queue-1.62 → most_queue-2.1}/.gitignore +0 -0
  203. {most_queue-1.62 → most_queue-2.1}/LICENSE +0 -0
  204. {most_queue-1.62 → most_queue-2.1}/assets/1.gif +0 -0
  205. {most_queue-1.62 → most_queue-2.1}/assets/2.gif +0 -0
  206. {most_queue-1.62 → most_queue-2.1}/assets/3.gif +0 -0
  207. {most_queue-1.62 → most_queue-2.1}/assets/queue_long.png +0 -0
  208. {most_queue-1.62 → most_queue-2.1}/deploy.txt +0 -0
  209. {most_queue-1.62 → most_queue-2.1}/docs/Makefile +0 -0
  210. {most_queue-1.62 → most_queue-2.1}/docs/make.bat +0 -0
  211. {most_queue-1.62 → most_queue-2.1}/docs/source/index.rst +0 -0
  212. {most_queue-1.62 → most_queue-2.1}/docs/source/modules.rst +0 -0
  213. {most_queue-1.62 → most_queue-2.1}/docs/source/most_queue.rst +0 -0
  214. {most_queue-1.62 → most_queue-2.1}/docs/source/most_queue.sim.rst +0 -0
  215. {most_queue-1.62 → most_queue-2.1}/docs/source/most_queue.theory.rst +0 -0
  216. {most_queue-1.62 → most_queue-2.1}/googleb31d3dccb40f969f.html +0 -0
  217. {most_queue-1.62 → most_queue-2.1}/most_queue/__init__.py +0 -0
  218. {most_queue-1.62 → most_queue-2.1}/most_queue/general/__init__.py +0 -0
  219. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/__init__.py +0 -0
  220. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/networks/__init__.py +0 -0
  221. {most_queue-1.62 → most_queue-2.1}/most_queue/sim/utils/__init__.py +0 -0
  222. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/__init__.py +0 -0
  223. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/batch/__init__.py +0 -0
  224. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/closed/__init__.py +0 -0
  225. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/fifo/__init__.py +0 -0
  226. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/fork_join/__init__.py +0 -0
  227. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/impatience/__init__.py +0 -0
  228. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/networks/__init__.py +0 -0
  229. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/networks/opt/__init__.py +0 -0
  230. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/priority/__init__.py +0 -0
  231. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/priority/non_preemptive/__init__.py +0 -0
  232. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/priority/preemptive/__init__.py +0 -0
  233. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/r_example.gexf +0 -0
  234. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/utils/__init__.py +0 -0
  235. {most_queue-1.62 → most_queue-2.1}/most_queue/theory/vacations/__init__.py +0 -0
  236. {most_queue-1.62 → most_queue-2.1}/tests/__init__.py +0 -0
  237. {most_queue-1.62 → most_queue-2.1}/tests/units/h2_params_cv_greater_than_exp.png +0 -0
  238. {most_queue-1.62 → most_queue-2.1}/tests/units/h2_params_cv_less_than_exp.png +0 -0
  239. {most_queue-1.62 → most_queue-2.1}/tests/units/v1_on_channels.png +0 -0
  240. {most_queue-1.62 → most_queue-2.1}/tests/units/v1_on_utilization_approx.png +0 -0
  241. {most_queue-1.62 → most_queue-2.1}/works/__init__.py +0 -0
  242. {most_queue-1.62 → most_queue-2.1}/works/negative_queues/__init__.py +0 -0
  243. {most_queue-1.62 → most_queue-2.1}/works/negative_queues/base_parameters.yaml +0 -0
  244. {most_queue-1.62 → most_queue-2.1}/works/vacations/__init__.py +0 -0
  245. {most_queue-1.62 → most_queue-2.1}/works/vacations/base_parameters.yaml +0 -0
@@ -0,0 +1,47 @@
1
+ # See https://pre-commit.com for more information
2
+ # See https://pre-commit.com/hooks.html for more hooks
3
+ repos:
4
+ - repo: https://github.com/pre-commit/pre-commit-hooks
5
+ rev: v3.2.0
6
+ hooks:
7
+ - id: check-yaml
8
+ - id: check-added-large-files
9
+ - id: check-json
10
+ - id: check-toml
11
+
12
+ # - repo: https://github.com/pycqa/isort
13
+ # rev: 6.0.1
14
+ # hooks:
15
+ # - id: isort
16
+ # name: isort (python)
17
+ # args: [ --profile, black ]
18
+
19
+ - repo: https://github.com/psf/black
20
+ rev: 25.1.0
21
+ hooks:
22
+ - id: black
23
+ language_version: python3.12
24
+
25
+ # - repo: local
26
+ # hooks:
27
+ # - id: pylint
28
+ # name: pylint
29
+ # entry: ./.venv/bin/pylint
30
+ # language: system
31
+ # types: [ python ]
32
+ # require_serial: true
33
+ # args:
34
+ # [
35
+ # "-rn", # Only display messages
36
+ # "-sn"
37
+ # ] # Don't display the score
38
+
39
+ # - repo: https://github.com/christophmeissner/pytest-pre-commit
40
+ # rev: 1.0.0
41
+ # hooks:
42
+ # - id: pytest
43
+ # entry: ./.venv/bin/pytest
44
+ # pass_filenames: false
45
+ # always_run: true
46
+ # args:
47
+ # - "tests"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: most_queue
3
- Version: 1.62
3
+ Version: 2.1
4
4
  Summary: Software package for calculation and simulation of queuing systems
5
5
  Project-URL: Homepage, https://github.com/xabarov/most-queue
6
6
  Author-email: Xabarov Roman <xabarov1985@gmail.com>
@@ -43,7 +43,7 @@ Description-Content-Type: text/markdown
43
43
 
44
44
  ![Queue](assets/3.gif)
45
45
 
46
- A Python package for simulating and analyzing queueing systems (QS) and networks.
46
+ A Python package for simulating and analyzing queueing systems (QS) and networks.
47
47
 
48
48
  ![GitHub commit activity](https://img.shields.io/github/commit-activity/m/xabarov/most-queue)
49
49
 
@@ -76,13 +76,13 @@ Or install from the repository:
76
76
  pip install -e .
77
77
  ```
78
78
 
79
- ---
79
+ ---
80
80
 
81
81
  ## 📚 Project Overview
82
82
 
83
83
  Most_queue consists of two main parts:
84
- - **most_queue.theory** contains programs that implement methods for calculating queueing theory models.
85
- - **most_queue.sim** contains simulation programs.
84
+ - **most_queue.theory** contains programs that implement methods for calculating queueing theory models.
85
+ - **most_queue.sim** contains simulation programs.
86
86
 
87
87
  ## 🧪 Example Use Cases
88
88
 
@@ -103,16 +103,15 @@ Most_queue consists of two main parts:
103
103
  | # | Kendall Notations | Description | Example | Tutorial |
104
104
  |-----|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|-------------------|
105
105
  | 1. | M/Ph/c/PR | Numerical calculation of QS M/Ph/c with 2 classes and PR - priority. Based on the approximation of busy periods | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_m_ph_n_prty.py) | |
106
- | 2. | M/M/c/PR | Numerical calculation of QS M/M/c with 2 classes, PR - priority by the Takahashi-Takami numerical method based on the approximation of the busy period by the Cox distribution | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_mmn_prty_pnz_approx.py) | |
107
- | 3. | M/M/c/PR | Numerical calculation of QS M/M/c with 3 classes, PR - priority by the Takahashi-Takami numerical method based on the approximation of busy period by the Cox distribution | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_mmn3_pnz_cox_approx.py) | |
108
- | 4. | M/G/1/PR | Calculating QS with preemtive priorities (single-channel). | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
109
- | 5. | M/G/1/NP | Calculating QS with non-preemtive priorities (single-channel). | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
110
- | 6. | M/G/c/Priority | Calculating QS with NP and PR (multi-channel) by method of relation | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
106
+ | 2. | M/M/c/PR | Numerical calculation of QS M/M/c with 2 classes, PR - priority by the Takahashi-Takami numerical method based on the approximation of the busy period by the Cox distribution | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_mmn_prty_busy_approx.py) | |
107
+ | 3. | M/G/1/PR | Calculating QS with preemtive priorities (single-channel). | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
108
+ | 4. | M/G/1/NP | Calculating QS with non-preemtive priorities (single-channel). | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
109
+ | 5. | M/G/c/Priority | Calculating QS with NP and PR (multi-channel) by method of relation | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
111
110
 
112
111
  ### Queueing Systems with Vacations
113
112
  | # | Kendall Notations | Description | Example | Tutorial |
114
113
  |-----|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|-------------------|
115
- | 1. | M/H<SUB>2</SUB>/c | Numerical calculation of the M/H<SUB>2</SUB>/c system with H<SUB>2</SUB>-warming using the Takahasi-Takagi method. | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_m_h2_h2warm.py) | [link](https://github.com/xabarov/most-queue/blob/main/tutorials/m_h2_h2warm.ipynb)| |
114
+ | 1. | M/H<SUB>2</SUB>/c | Numerical calculation of the M/H<SUB>2</SUB>/c system with H<SUB>2</SUB>-warming using the Takahashi-Takami method. | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_m_h2_h2warm.py) | [link](https://github.com/xabarov/most-queue/blob/main/tutorials/m_h2_h2warm.ipynb)| |
116
115
  | 2. | M/G/1 | Solving for QS M/G/1 with warm-up | | |
117
116
  | 3. | M/Ph/c | Multichannel queuing system with H<SUB>2</SUB>-serving time, H<SUB>2</SUB>-warm-up, H<SUB>2</SUB>-cold delay and H<SUB>2</SUB>-cold (vacations). The system uses complex parameters, which allows you to calculate systems with arbitrary serving, warm-up, cold-delay and cold variation coefficients | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_mgn_with_h2_delay_cold_warm.py) | |
118
117
  | 4. | M/M/c | Multichannel queuing system with exp serving time, H<SUB>2</SUB>-warm-up and H<SUB>2</SUB>-cold (vacations). The system uses complex parameters, which allows to calculate systems with arbitrary warm-up and cold variation coefficients | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_mmn_h2cold_h2warm.py) | |
@@ -164,7 +163,7 @@ Most_queue consists of two main parts:
164
163
  - Look [here](https://github.com/xabarov/most-queue/tree/main/tests) for examples
165
164
  - Look [here](https://github.com/xabarov/most-queue/tree/main/tutorials) for jupyter tutorials
166
165
 
167
- ---
166
+ ---
168
167
 
169
168
  ### 👥 Contributing
170
169
 
@@ -172,4 +171,4 @@ Contributions are welcome!
172
171
 
173
172
  - Open an [issue](https://github.com/xabarov/most-queue/issues) for bugs or suggestions.
174
173
  - Submit a pull request for feature enhancements.
175
- - Contact me at xabarov1985@gmail.com for questions.
174
+ - Contact me at xabarov1985@gmail.com for questions.
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![Queue](assets/3.gif)
4
4
 
5
- A Python package for simulating and analyzing queueing systems (QS) and networks.
5
+ A Python package for simulating and analyzing queueing systems (QS) and networks.
6
6
 
7
7
  ![GitHub commit activity](https://img.shields.io/github/commit-activity/m/xabarov/most-queue)
8
8
 
@@ -35,13 +35,13 @@ Or install from the repository:
35
35
  pip install -e .
36
36
  ```
37
37
 
38
- ---
38
+ ---
39
39
 
40
40
  ## 📚 Project Overview
41
41
 
42
42
  Most_queue consists of two main parts:
43
- - **most_queue.theory** contains programs that implement methods for calculating queueing theory models.
44
- - **most_queue.sim** contains simulation programs.
43
+ - **most_queue.theory** contains programs that implement methods for calculating queueing theory models.
44
+ - **most_queue.sim** contains simulation programs.
45
45
 
46
46
  ## 🧪 Example Use Cases
47
47
 
@@ -62,16 +62,15 @@ Most_queue consists of two main parts:
62
62
  | # | Kendall Notations | Description | Example | Tutorial |
63
63
  |-----|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|-------------------|
64
64
  | 1. | M/Ph/c/PR | Numerical calculation of QS M/Ph/c with 2 classes and PR - priority. Based on the approximation of busy periods | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_m_ph_n_prty.py) | |
65
- | 2. | M/M/c/PR | Numerical calculation of QS M/M/c with 2 classes, PR - priority by the Takahashi-Takami numerical method based on the approximation of the busy period by the Cox distribution | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_mmn_prty_pnz_approx.py) | |
66
- | 3. | M/M/c/PR | Numerical calculation of QS M/M/c with 3 classes, PR - priority by the Takahashi-Takami numerical method based on the approximation of busy period by the Cox distribution | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_mmn3_pnz_cox_approx.py) | |
67
- | 4. | M/G/1/PR | Calculating QS with preemtive priorities (single-channel). | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
68
- | 5. | M/G/1/NP | Calculating QS with non-preemtive priorities (single-channel). | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
69
- | 6. | M/G/c/Priority | Calculating QS with NP and PR (multi-channel) by method of relation | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
65
+ | 2. | M/M/c/PR | Numerical calculation of QS M/M/c with 2 classes, PR - priority by the Takahashi-Takami numerical method based on the approximation of the busy period by the Cox distribution | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_mmn_prty_busy_approx.py) | |
66
+ | 3. | M/G/1/PR | Calculating QS with preemtive priorities (single-channel). | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
67
+ | 4. | M/G/1/NP | Calculating QS with non-preemtive priorities (single-channel). | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
68
+ | 5. | M/G/c/Priority | Calculating QS with NP and PR (multi-channel) by method of relation | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_qs_sim_prty.py) |[link](https://github.com/xabarov/most-queue/blob/main/tutorials/priority_queue.ipynb) |
70
69
 
71
70
  ### Queueing Systems with Vacations
72
71
  | # | Kendall Notations | Description | Example | Tutorial |
73
72
  |-----|-------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|-------------------|
74
- | 1. | M/H<SUB>2</SUB>/c | Numerical calculation of the M/H<SUB>2</SUB>/c system with H<SUB>2</SUB>-warming using the Takahasi-Takagi method. | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_m_h2_h2warm.py) | [link](https://github.com/xabarov/most-queue/blob/main/tutorials/m_h2_h2warm.ipynb)| |
73
+ | 1. | M/H<SUB>2</SUB>/c | Numerical calculation of the M/H<SUB>2</SUB>/c system with H<SUB>2</SUB>-warming using the Takahashi-Takami method. | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_m_h2_h2warm.py) | [link](https://github.com/xabarov/most-queue/blob/main/tutorials/m_h2_h2warm.ipynb)| |
75
74
  | 2. | M/G/1 | Solving for QS M/G/1 with warm-up | | |
76
75
  | 3. | M/Ph/c | Multichannel queuing system with H<SUB>2</SUB>-serving time, H<SUB>2</SUB>-warm-up, H<SUB>2</SUB>-cold delay and H<SUB>2</SUB>-cold (vacations). The system uses complex parameters, which allows you to calculate systems with arbitrary serving, warm-up, cold-delay and cold variation coefficients | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_mgn_with_h2_delay_cold_warm.py) | |
77
76
  | 4. | M/M/c | Multichannel queuing system with exp serving time, H<SUB>2</SUB>-warm-up and H<SUB>2</SUB>-cold (vacations). The system uses complex parameters, which allows to calculate systems with arbitrary warm-up and cold variation coefficients | [link](https://github.com/xabarov/most-queue/blob/main/tests/test_mmn_h2cold_h2warm.py) | |
@@ -123,7 +122,7 @@ Most_queue consists of two main parts:
123
122
  - Look [here](https://github.com/xabarov/most-queue/tree/main/tests) for examples
124
123
  - Look [here](https://github.com/xabarov/most-queue/tree/main/tutorials) for jupyter tutorials
125
124
 
126
- ---
125
+ ---
127
126
 
128
127
  ### 👥 Contributing
129
128
 
@@ -131,4 +130,4 @@ Contributions are welcome!
131
130
 
132
131
  - Open an [issue](https://github.com/xabarov/most-queue/issues) for bugs or suggestions.
133
132
  - Submit a pull request for feature enhancements.
134
- - Contact me at xabarov1985@gmail.com for questions.
133
+ - Contact me at xabarov1985@gmail.com for questions.
@@ -9,27 +9,24 @@ import os
9
9
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
10
10
  import sys
11
11
 
12
- project = 'most-queue'
13
- copyright = '2025, xabarov'
14
- author = 'xabarov'
15
- release = '1.51'
12
+ project = "most-queue"
13
+ copyright = "2025, xabarov"
14
+ author = "xabarov"
15
+ release = "1.51"
16
16
 
17
17
  # -- General configuration ---------------------------------------------------
18
18
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
19
- sys.path.insert(0, os.path.abspath('../most_queue'))
19
+ sys.path.insert(0, os.path.abspath("../most_queue"))
20
20
 
21
- extensions = ['sphinx.ext.autodoc',
22
- 'sphinx.ext.napoleon',
23
- 'autodocsumm',
24
- 'sphinx.ext.coverage']
21
+ extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "autodocsumm", "sphinx.ext.coverage"]
25
22
 
26
- auto_doc_default_options = {'autosummary': True}
27
- templates_path = ['_templates']
23
+ auto_doc_default_options = {"autosummary": True}
24
+ templates_path = ["_templates"]
28
25
  exclude_patterns = []
29
26
 
30
27
 
31
28
  # -- Options for HTML output -------------------------------------------------
32
29
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
33
30
 
34
- html_theme = 'sphinx_book_theme'
35
- html_static_path = ['_static']
31
+ html_theme = "sphinx_book_theme"
32
+ html_static_path = ["_static"]
@@ -0,0 +1,18 @@
1
+ digraph QS {
2
+ graph [rankdir=LR]
3
+ 0 [label=0 color=lightblue2 style=filled]
4
+ 1 [label=1]
5
+ 2 [label=2]
6
+ 3 [label=3]
7
+ 4 [label=4]
8
+ 5 [label=5]
9
+ 6 [label=6 color=lightblue2 style=filled]
10
+ 0 -> 1 [label=1.0]
11
+ 1 -> 2 [label=0.4]
12
+ 1 -> 3 [label=0.6]
13
+ 2 -> 4 [label=0.6]
14
+ 2 -> 5 [label=0.4]
15
+ 3 -> 5 [label=1.0]
16
+ 4 -> 5 [label=1.0]
17
+ 5 -> 6 [label=1.0]
18
+ }
@@ -0,0 +1,332 @@
1
+ """
2
+ Methods for fitting distributions to given initial moments.
3
+ """
4
+
5
+ import cmath
6
+ import math
7
+ from dataclasses import dataclass
8
+
9
+ import numpy as np
10
+
11
+ from most_queue.general.distribution_params import (
12
+ Cox2Params,
13
+ ErlangParams,
14
+ GammaParams,
15
+ H2Params,
16
+ ParetoParams,
17
+ WeibullParams,
18
+ )
19
+
20
+
21
+ @dataclass
22
+ class FittingParams:
23
+ """
24
+ Parameters for distribution fitting.
25
+ """
26
+
27
+ verbose: bool = True
28
+ ee: float = 0.001
29
+ e: float = 0.02
30
+ e_percent: float = 0.15
31
+ is_fitting: bool = True
32
+
33
+
34
+ def fit_h2(moments: list[float]) -> H2Params:
35
+ """
36
+ Aliev's method for calculating the parameters of H2 distribution by given initial moments.
37
+ Only real parameters are selected.
38
+ Returns a list with parameters [y1, mu1, mu2].
39
+ """
40
+
41
+ v = moments[1] - moments[0] * moments[0]
42
+ v = math.sqrt(v) / moments[0]
43
+ res = [0.0] * 3
44
+ if v < 1.0:
45
+ return H2Params(p1=0, mu1=0, mu2=0)
46
+
47
+ q_max = 2.0 / (1.0 + v * v)
48
+ t_min = 1.5 * ((1 + v * v) ** 2) * math.pow(moments[0], 3)
49
+ q_min = 0.0
50
+ tn = 0.0
51
+
52
+ if t_min > moments[2]:
53
+ # one phase distibution
54
+ q_new = q_max
55
+ mu1 = (1.0 - math.sqrt(q_new * (v * v - 1.0) / (2 * (1.0 - q_new)))) * moments[0]
56
+ if math.isclose(mu1, 0):
57
+ mu1 = 1e10
58
+ else:
59
+ mu1 = 1.0 / mu1
60
+ res = H2Params(p1=q_max, mu1=mu1, mu2=1e6)
61
+ return res
62
+
63
+ max_iteration = 10000
64
+ tec = 0
65
+ t1 = 0
66
+ t2 = 0
67
+ while abs(tn - moments[2]) > 1e-8 and tec < max_iteration:
68
+ tec += 1
69
+ q_new = (q_max + q_min) / 2.0
70
+ t1 = (1.0 + math.sqrt((1.0 - q_new) * (v * v - 1.0) / (2 * q_new))) * moments[0]
71
+ t2 = (1.0 - math.sqrt(q_new * (v * v - 1.0) / (2 * (1.0 - q_new)))) * moments[0]
72
+
73
+ tn = 6 * (q_new * math.pow(t1, 3) + (1.0 - q_new) * math.pow(t2, 3))
74
+
75
+ if tn - moments[2] > 0:
76
+ q_min = q_new
77
+ else:
78
+ q_max = q_new
79
+
80
+ res = H2Params(p1=q_max, mu1=1.0 / t1, mu2=1.0 / t2)
81
+ return res
82
+
83
+
84
+ def fit_h2_clx(moments: list[float], fitting_params: FittingParams | None = None) -> H2Params:
85
+ """
86
+ Method of fitting H2 distribution parameters to given initial moments.
87
+ Uses the method of moments and optimization to fit the parameters.
88
+ Returns H2Params object with fitted parameters.
89
+ """
90
+
91
+ if fitting_params is None:
92
+ fitting_params = FittingParams()
93
+
94
+ f = [0.0] * 3
95
+ for i in range(3):
96
+ f[i] = complex(moments[i] / math.factorial(i + 1))
97
+ znam = f[1] - pow(f[0], 2)
98
+ c0 = (f[0] * f[2] - pow(f[1], 2)) / znam
99
+ c1 = (f[0] * f[1] - f[2]) / znam
100
+
101
+ d = pow(c1 / 2.0, 2.0) - c0
102
+
103
+ if fitting_params.is_fitting:
104
+ # проверка на близость распределения к экспоненциальному
105
+ coev = cmath.sqrt(moments[1] - moments[0] ** 2) / moments[0]
106
+ if math.fabs(coev.real - 1.0) < fitting_params.ee:
107
+ if fitting_params.verbose:
108
+ print(
109
+ f"H2 is close to Exp. Multiply moments to (1+je)"
110
+ f"coev = {coev:5.3f}, e = {fitting_params.e:5.3f}."
111
+ )
112
+ f = []
113
+ for i, mom in enumerate(moments):
114
+ f.append(mom * complex(1, (i + 1) * fitting_params.e))
115
+
116
+ return fit_h2_clx(f, fitting_params=fitting_params)
117
+
118
+ coev = cmath.sqrt(moments[1] - moments[0] ** 2) / moments[0]
119
+
120
+ # проверка на близость распределения к Эрланга 2-го порядка
121
+ if math.fabs(coev.real - 1.0 / math.sqrt(2.0)) < fitting_params.ee:
122
+ if fitting_params.verbose:
123
+ print(
124
+ f"H2 is close to E2. Multiply moments to (1+je)" f"coev = {coev:5.3f}, e = {fitting_params.e:5.3f}."
125
+ )
126
+ f = []
127
+ for i, mom in enumerate(moments):
128
+ f.append(mom * complex(1, (i + 1) * fitting_params.e))
129
+ return fit_h2_clx(f, fitting_params=fitting_params)
130
+
131
+ res = [0, 0, 0] # y1, mu1, mu2
132
+ c1 = complex(c1)
133
+ x1 = -c1 / 2 + cmath.sqrt(d)
134
+ x2 = -c1 / 2 - cmath.sqrt(d)
135
+ y1 = (f[0] - x2) / (x1 - x2)
136
+
137
+ res = H2Params(p1=y1, mu1=1.0 / x1, mu2=1.0 / x2)
138
+
139
+ return res
140
+
141
+
142
+ def fit_cox(moments: list[float], fitting_params: FittingParams | None = None) -> Cox2Params:
143
+ """
144
+ Calculates Cox-2 distribution parameters by three given initial moments [moments].
145
+ """
146
+
147
+ if not fitting_params:
148
+ fitting_params = FittingParams()
149
+
150
+ f = [0.0] * 3
151
+
152
+ if fitting_params.is_fitting:
153
+ # проверка на близость распределения к экспоненциальному
154
+ coev = cmath.sqrt(moments[1] - moments[0] ** 2) / moments[0]
155
+ if abs(moments[1] - moments[0] * moments[0]) < fitting_params.ee:
156
+ if fitting_params.verbose:
157
+ print(f"Cox special 1. Multiply moments to (1+je)" f"coev = {coev:5.3f} e = {fitting_params.e:5.3f}.")
158
+ f = []
159
+ for i, mom in enumerate(moments):
160
+ f.append(mom * complex(1, (i + 1) * fitting_params.e))
161
+
162
+ return fit_cox(f, fitting_params=fitting_params)
163
+
164
+ coev = cmath.sqrt(moments[1] - moments[0] ** 2) / moments[0]
165
+
166
+ # проверка на близость распределения к Эрланга 2-го порядка
167
+ if abs(moments[1] - (3.0 / 4) * moments[0] * moments[0]) < fitting_params.ee:
168
+ if fitting_params.verbose:
169
+ print("Cox special 2. Multiply moments to (1+je)")
170
+ print(f"\tcoev = {coev:5.3f}, e = {fitting_params.e:5.3f}")
171
+ f = []
172
+ for i, mom in enumerate(moments):
173
+ f.append(mom * complex(1, (i + 1) * fitting_params.e))
174
+ return fit_cox(f, fitting_params=fitting_params)
175
+
176
+ for i in range(3):
177
+ f[i] = moments[i] / math.factorial(i + 1)
178
+
179
+ d = np.power(f[2] - f[0] * f[1], 2) - 4.0 * (f[1] - np.power(f[0], 2)) * (f[0] * f[2] - np.power(f[1], 2))
180
+ mu2 = f[0] * f[1] - f[2] + cmath.sqrt(d)
181
+ mu2 /= 2.0 * (np.power(f[1], 2) - f[0] * f[2])
182
+ mu1 = (mu2 * f[0] - 1.0) / (mu2 * f[1] - f[0])
183
+ y1 = (mu1 * f[0] - 1.0) * mu2 / mu1
184
+
185
+ return Cox2Params(p1=y1, mu1=mu1, mu2=mu2)
186
+
187
+
188
+ def fit_pareto_moments(moments: list[float]):
189
+ """
190
+ Calc parameters of the distribution.
191
+ :param moments: list of initial moments
192
+ """
193
+ d = moments[1] - moments[0] * moments[0]
194
+ c = moments[0] * moments[0] / d
195
+ disc = 4 * (1 + c)
196
+ a = (2 + math.sqrt(disc)) / 2
197
+ k = (a - 1) * moments[0] / a
198
+ return ParetoParams(alpha=a, K=k)
199
+
200
+
201
+ def fit_pareto_by_mean_and_coev(f1: float, coev: float):
202
+ """
203
+ Get parameters of the distribution by mean and coefficient of variation.
204
+ :param f1: float, mean value of the distribution
205
+ :param coev: float, coefficient of variation (mean / std)
206
+ """
207
+ d = pow(f1 * coev, 2)
208
+ c = pow(f1, 2) / d
209
+ disc = 4 * (1 + c)
210
+ a = (2 + math.sqrt(disc)) / 2
211
+ k = (a - 1) * f1 / a
212
+ return ParetoParams(alpha=a, K=k)
213
+
214
+
215
+ def fit_erlang(moments: list[float]) -> ErlangParams:
216
+ """
217
+ Calculates parameters of the Erlang distribution by initial moments.
218
+ """
219
+ r = int(math.floor(moments[0] * moments[0] / (moments[1] - moments[0] * moments[0]) + 0.5))
220
+ mu = r / moments[0]
221
+ return ErlangParams(r=r, mu=mu)
222
+
223
+
224
+ def calc_gamma_func(x):
225
+ """
226
+ Gamma-function Г(x)
227
+ """
228
+ if (x > 0.0) & (x < 1.0):
229
+ return calc_gamma_func(x + 1.0) / x
230
+ if x > 2:
231
+ return (x - 1) * calc_gamma_func(x - 1)
232
+ if x <= 0:
233
+ return math.pi / (math.sin(math.pi * x) * calc_gamma_func(1 - x))
234
+ return gamma_approx(x)
235
+
236
+
237
+ def gamma_approx(x):
238
+ """
239
+ Get approximation of Gamma function for x in [1,2]
240
+ """
241
+ p = [
242
+ -1.71618513886549492533811e0,
243
+ 2.47656508055759199108314e1,
244
+ -3.79804256470945635097577e2,
245
+ 6.29331155312818442661052e2,
246
+ 8.66966202790413211295064e2,
247
+ -3.14512729688483657254357e4,
248
+ -3.61444134186911729807069e4,
249
+ 6.6456143820240544627855e4,
250
+ ]
251
+ q = [
252
+ -3.08402300119738975254354e1,
253
+ 3.15350626979604161529144e2,
254
+ -1.01515636749021914166146e3,
255
+ -3.10777167157231109440444e3,
256
+ 2.253811842098015100330112e4,
257
+ 4.75584667752788110767815e3,
258
+ -1.34659959864969306392456e5,
259
+ -1.15132259675553483497211e5,
260
+ ]
261
+ z = x - 1.0
262
+ a = 0.0
263
+ b = 1.0
264
+ for i in range(0, 8):
265
+ a = (a + p[i]) * z
266
+ b = b * z + q[i]
267
+ return a / b + 1.0
268
+
269
+
270
+ def fit_gamma(moments: list[float]) -> GammaParams:
271
+ """
272
+ Get parameters of the Gamma distribution from theoretical moments.
273
+ """
274
+ d = moments[1] - moments[0] * moments[0]
275
+ mu = moments[0] / d
276
+ alpha = mu * moments[0]
277
+ if len(moments) > 2:
278
+ # подбор коэффициентов g
279
+ A = []
280
+ B = []
281
+ for i in range(len(moments) + 1):
282
+ A.append([])
283
+ if i == 0:
284
+ B.append(1)
285
+ else:
286
+ B.append(moments[i - 1])
287
+ for j in range(len(moments) + 1):
288
+ A[i].append(calc_gamma_func(alpha + i + j) / (pow(mu, i + j) * calc_gamma_func(alpha)))
289
+ g = np.linalg.solve(A, B)
290
+ return GammaParams(mu=mu, alpha=alpha, g=g)
291
+
292
+ return GammaParams(mu=mu, alpha=alpha)
293
+
294
+
295
+ def fit_weibull(moments: list[float]) -> WeibullParams:
296
+ """
297
+ Parameter selection for the distribution based
298
+ on initial moments of the distribution
299
+
300
+ params:
301
+ moments: initial moments of the random variable
302
+
303
+ return:
304
+ WeibullParams
305
+
306
+ """
307
+ a = moments[1] / (moments[0] * moments[0])
308
+ u0 = math.log(2 * a) / (2.0 * math.log(2))
309
+ ee = 1e-6
310
+ u1 = (1.0 / (2 * math.log(2))) * math.log(a * math.sqrt(math.pi) * math.gamma(u0 + 1) / math.gamma(u0 + 0.5))
311
+ delta = u1 - u0
312
+ while math.fabs(delta) > ee:
313
+ u1 = (1.0 / (2 * math.log(2))) * math.log(a * math.sqrt(math.pi) * math.gamma(u0 + 1) / math.gamma(u0 + 0.5))
314
+ delta = u1 - u0
315
+ u0 = u1
316
+ k = 1 / u1
317
+ big_w = math.pow(moments[0] / math.gamma(u1 + 1), k)
318
+
319
+ return WeibullParams(k=k, W=big_w)
320
+
321
+
322
+ def gamma_moments_by_mean_and_coev(mean: float, coev: float) -> list[float]:
323
+ """
324
+ Calculate the first three moments of a gamma distribution
325
+ given the mean and coefficient of variation.
326
+ """
327
+ f = [0, 0, 0]
328
+ alpha = 1 / (coev**2)
329
+ f[0] = mean
330
+ f[1] = pow(f[0], 2) * (pow(coev, 2) + 1)
331
+ f[2] = f[1] * f[0] * (1.0 + 2 / alpha)
332
+ return f
@@ -1,6 +1,7 @@
1
1
  """
2
2
  Distribution parameters classes.
3
3
  """
4
+
4
5
  from dataclasses import dataclass
5
6
 
6
7
 
@@ -9,6 +10,7 @@ class H2Params:
9
10
  """
10
11
  H2 distribution parameters.
11
12
  """
13
+
12
14
  mu1: float | complex # Mean of the first phase
13
15
  mu2: float | complex # Mean of the second phase
14
16
  p1: float | complex # Probability of being in the first phase
@@ -19,6 +21,7 @@ class Cox2Params:
19
21
  """
20
22
  Coxian second order distribution parameters.
21
23
  """
24
+
22
25
  mu1: float | complex # Mean of the first phase
23
26
  mu2: float | complex # Mean of the second phase
24
27
  # probability for transition between phase 1 and phase 2.
@@ -30,6 +33,7 @@ class GammaParams:
30
33
  """
31
34
  Gamma distribution parameters.
32
35
  """
36
+
33
37
  mu: float # 1/theta
34
38
  alpha: float
35
39
  g: list[float] | None = None
@@ -38,8 +42,9 @@ class GammaParams:
38
42
  @dataclass
39
43
  class WeibullParams:
40
44
  """
41
- Weibull distribution parameters.
45
+ Weibull distribution parameters.
42
46
  """
47
+
43
48
  k: float # Shape parameter
44
49
  W: float # Scale parameter
45
50
 
@@ -49,6 +54,7 @@ class GaussianParams:
49
54
  """
50
55
  Normal distribution parameters.
51
56
  """
57
+
52
58
  mean: float # Mean of the distribution
53
59
  std_dev: float # Standard deviation of the distribution
54
60
 
@@ -58,6 +64,7 @@ class UniformParams:
58
64
  """
59
65
  Uniform distribution parameters.
60
66
  """
67
+
61
68
  mean: float # Mean of the distribution
62
69
  half_interval: float # Half interval of the distribution
63
70
 
@@ -67,6 +74,7 @@ class ParetoParams:
67
74
  """
68
75
  Pareto distribution parameters.
69
76
  """
77
+
70
78
  alpha: float # alpha of the distribution
71
79
  K: float # K of the distribution (or x_m, minimum value of x)
72
80
 
@@ -76,5 +84,6 @@ class ErlangParams:
76
84
  """
77
85
  Erlang distribution parameters.
78
86
  """
87
+
79
88
  r: int
80
89
  mu: float
@@ -1,6 +1,7 @@
1
1
  """
2
2
  Abstract base class for all distributions.
3
3
  """
4
+
4
5
  from abc import ABC, abstractmethod
5
6
 
6
7
 
@@ -58,5 +59,6 @@ class Distribution(ABC):
58
59
  """
59
60
  :param f1: mean of the distribution.
60
61
  :param coev: coefficient of variation (std_dev / mean).
61
- :return: Parameters for the distribution that correspond to the given mean and coefficient of variation.
62
+ :return: Parameters for the distribution that correspond
63
+ to the given mean and coefficient of variation.
62
64
  """