pycombinatorial 2.1.8__tar.gz → 2.2.2__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.
Files changed (153) hide show
  1. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/LICENSE +1 -1
  2. pycombinatorial-2.2.2/MANIFEST.in +2 -0
  3. {pycombinatorial-2.1.8/pycombinatorial.egg-info → pycombinatorial-2.2.2}/PKG-INFO +22 -4
  4. pycombinatorial-2.1.8/PKG-INFO → pycombinatorial-2.2.2/README.md +145 -138
  5. pycombinatorial-2.2.2/pyCombinatorial/__init__.py +5 -0
  6. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/__init__.py +1 -1
  7. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/aco.py +1 -1
  8. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/christofides.py +1 -1
  9. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/opt_4.py +1 -1
  10. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/rr.py +4 -2
  11. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/sa.py +2 -2
  12. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/ssi.py +2 -1
  13. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/utils/graphs.py +1 -1
  14. pycombinatorial-2.2.2/pyCombinatorial/web/__init__.py +116 -0
  15. pycombinatorial-2.2.2/pyCombinatorial/web/__main__.py +5 -0
  16. pycombinatorial-2.2.2/pyCombinatorial/web/css/style.css +808 -0
  17. pycombinatorial-2.2.2/pyCombinatorial/web/index.html +192 -0
  18. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/_kopt.js +199 -0
  19. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/_kopt_trials.js +434 -0
  20. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/_ksp_helpers.js +139 -0
  21. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/_shared.js +386 -0
  22. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/aco.js +145 -0
  23. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/alns.js +124 -0
  24. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/bb.js +189 -0
  25. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/bf.js +76 -0
  26. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/bhk.js +111 -0
  27. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/brkga.js +101 -0
  28. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/bt.js +72 -0
  29. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/christofides.js +99 -0
  30. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/conc_hull.js +172 -0
  31. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/conv_hull.js +63 -0
  32. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/cw.js +90 -0
  33. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/eln.js +150 -0
  34. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/eo.js +153 -0
  35. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/frnn.js +80 -0
  36. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/ga.js +230 -0
  37. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/gksp.js +77 -0
  38. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/grasp.js +121 -0
  39. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/hpn.js +134 -0
  40. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/index.js +150 -0
  41. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/ins_c.js +58 -0
  42. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/ins_f.js +80 -0
  43. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/ins_n.js +82 -0
  44. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/ins_r.js +69 -0
  45. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/ksp.js +63 -0
  46. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/lns.js +97 -0
  47. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/mf.js +67 -0
  48. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/nn.js +128 -0
  49. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/opt_2.js +172 -0
  50. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/opt_2_5.js +103 -0
  51. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/opt_2_5s.js +107 -0
  52. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/opt_2s.js +100 -0
  53. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/opt_3.js +26 -0
  54. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/opt_3s.js +26 -0
  55. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/opt_4.js +26 -0
  56. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/opt_4s.js +25 -0
  57. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/opt_5.js +26 -0
  58. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/opt_5s.js +25 -0
  59. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/opt_or.js +166 -0
  60. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/rl_double_ql.js +129 -0
  61. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/rl_ql.js +117 -0
  62. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/rl_sarsa.js +123 -0
  63. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/rr.js +99 -0
  64. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/rss.js +129 -0
  65. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/rt.js +40 -0
  66. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/s_gui.js +111 -0
  67. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/s_itr.js +113 -0
  68. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/s_sct.js +107 -0
  69. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/s_shc.js +64 -0
  70. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/s_tabu.js +102 -0
  71. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/s_vns.js +83 -0
  72. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/sa.js +122 -0
  73. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/som.js +143 -0
  74. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/spfc_h.js +73 -0
  75. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/spfc_m.js +57 -0
  76. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/spfc_s.js +67 -0
  77. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/ssi.js +71 -0
  78. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/swp.js +60 -0
  79. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/tat.js +66 -0
  80. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/tbb.js +92 -0
  81. pycombinatorial-2.2.2/pyCombinatorial/web/js/algorithms/zs.js +124 -0
  82. pycombinatorial-2.2.2/pyCombinatorial/web/js/core/dataset.js +254 -0
  83. pycombinatorial-2.2.2/pyCombinatorial/web/js/core/distance.js +49 -0
  84. pycombinatorial-2.2.2/pyCombinatorial/web/js/core/renderer.js +352 -0
  85. pycombinatorial-2.2.2/pyCombinatorial/web/js/core/seed.js +52 -0
  86. pycombinatorial-2.2.2/pyCombinatorial/web/js/core/stepper.js +139 -0
  87. pycombinatorial-2.2.2/pyCombinatorial/web/js/core/twoopt_refiner.js +21 -0
  88. pycombinatorial-2.2.2/pyCombinatorial/web/js/main.js +623 -0
  89. pycombinatorial-2.1.8/README.md → pycombinatorial-2.2.2/pycombinatorial.egg-info/PKG-INFO +156 -127
  90. pycombinatorial-2.2.2/pycombinatorial.egg-info/SOURCES.txt +149 -0
  91. pycombinatorial-2.2.2/pycombinatorial.egg-info/entry_points.txt +2 -0
  92. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/setup.py +20 -4
  93. pycombinatorial-2.1.8/pyCombinatorial/__init__.py +0 -0
  94. pycombinatorial-2.1.8/pycombinatorial.egg-info/SOURCES.txt +0 -72
  95. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/alns.py +0 -0
  96. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/bb.py +0 -0
  97. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/bf.py +0 -0
  98. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/bhk.py +0 -0
  99. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/brkga.py +0 -0
  100. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/bt.py +0 -0
  101. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/conc_hull.py +0 -0
  102. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/conv_hull.py +0 -0
  103. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/cw.py +0 -0
  104. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/eln.py +0 -0
  105. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/eo.py +0 -0
  106. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/frnn.py +0 -0
  107. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/ga.py +0 -0
  108. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/gksp.py +0 -0
  109. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/grasp.py +0 -0
  110. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/hpn.py +0 -0
  111. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/ins_c.py +0 -0
  112. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/ins_f.py +0 -0
  113. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/ins_n.py +0 -0
  114. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/ins_r.py +0 -0
  115. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/ksp.py +0 -0
  116. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/lns.py +0 -0
  117. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/mf.py +0 -0
  118. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/nn.py +0 -0
  119. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/opt_2.py +0 -0
  120. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/opt_2_5.py +0 -0
  121. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/opt_2_5s.py +0 -0
  122. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/opt_2s.py +0 -0
  123. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/opt_3.py +0 -0
  124. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/opt_3s.py +0 -0
  125. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/opt_4s.py +0 -0
  126. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/opt_5.py +0 -0
  127. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/opt_5s.py +0 -0
  128. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/opt_or.py +0 -0
  129. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/rl_double_ql.py +0 -0
  130. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/rl_ql.py +0 -0
  131. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/rl_sarsa.py +0 -0
  132. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/rss.py +0 -0
  133. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/rt.py +0 -0
  134. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/s_gui.py +0 -0
  135. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/s_itr.py +0 -0
  136. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/s_sct.py +0 -0
  137. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/s_shc.py +0 -0
  138. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/s_tabu.py +0 -0
  139. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/s_vns.py +0 -0
  140. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/som.py +0 -0
  141. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/spfc_h.py +0 -0
  142. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/spfc_m.py +0 -0
  143. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/spfc_s.py +0 -0
  144. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/swp.py +0 -0
  145. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/tat.py +0 -0
  146. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/tbb.py +0 -0
  147. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/algorithm/zs.py +0 -0
  148. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/utils/__init__.py +0 -0
  149. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pyCombinatorial/utils/util.py +0 -0
  150. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pycombinatorial.egg-info/dependency_links.txt +0 -0
  151. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pycombinatorial.egg-info/requires.txt +0 -0
  152. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/pycombinatorial.egg-info/top_level.txt +0 -0
  153. {pycombinatorial-2.1.8 → pycombinatorial-2.2.2}/setup.cfg +0 -0
@@ -11,4 +11,4 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
  GNU General Public License for more details.
12
12
 
13
13
  You should have received a copy of the GNU General Public License
14
- along with pyCombinatorial. If not, see <http://www.gnu.org/licenses/>.
14
+ along with pyCombinatorial. If not, see <http://www.gnu.org/licenses/>.
@@ -0,0 +1,2 @@
1
+ include README.md
2
+ recursive-include pyCombinatorial/web *
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pycombinatorial
3
- Version: 2.1.8
3
+ Version: 2.2.2
4
4
  Summary: A library to solve TSP (Travelling Salesman Problem) using Exact Algorithms, Heuristics, Metaheuristics and Reinforcement Learning
5
5
  Home-page: https://github.com/Valdecy/pyCombinatorial
6
6
  Author: Valdecy Pereira
@@ -11,9 +11,27 @@ License-File: LICENSE
11
11
 
12
12
  # pyCombinatorial
13
13
 
14
+ New to Python or prefer a graphical interface? The **pyCombinatorial Web App** lets you run your analysis in clicks, not lines of code.
15
+
16
+ ```python
17
+ import pyCombinatorial
18
+
19
+ # Start the web service using:
20
+ pyCombinatorial.web_app()
21
+
22
+ ```
23
+
24
+ <p align="center">
25
+ <img src="https://github.com/Valdecy/Datasets/raw/master/Data%20Science/lab_pc.png" alt="Lab" width="700"/>
26
+ </p>
27
+
28
+ * [Preview -- **pyCombinatorial Web App** -- in Google Colab](https://colab.research.google.com/drive/11o2o_BTskKsS2Ybbs7vrwAzdLTczxhaJ?usp=sharing)
29
+
30
+ _This Google Colab Demo is intended for quick demos only. For the best experience, run the Web UI locally or open it directly in a full browser._
31
+
14
32
  ## Introduction
15
33
 
16
- **pyCombinatorial** is a Python-based library designed to tackle the classic Travelling Salesman Problem (TSP) through a diverse set of **Exact Algorithms**, **Heuristics**, **Metaheuristics** and **Reinforcement Learning**. It brings together both well-established and cutting-edge methodologies, offering end-users a flexible toolkit to generate high-quality solutions for TSP instances of various sizes and complexities.
34
+ **pyCombinatorial** is a Python-based library designed to tackle the classic Traveling Salesman Problem (TSP) through a diverse set of **Exact Algorithms**, **Heuristics**, **Metaheuristics**, and **Reinforcement Learning**. It brings together well-established and cutting-edge methodologies, offering end users a flexible toolkit to generate high-quality solutions for TSP instances of varying sizes and complexities.
17
35
 
18
36
  Techniques: **2-opt**; **2.5-opt**; **3-opt**; **4-opt**; **5-opt**; **Or-opt**; **2-opt Stochastic**; **2.5-opt Stochastic**; **3-opt Stochastic**; **4-opt Stochastic**; **5-opt Stochastic**; **Ant Colony Optimization**; **Adaptive Large Neighborhood Search**; **Bellman-Held-Karp Exact Algorithm**; **Bitonic Tour**; **Branch & Bound**; **BRKGA** (Biased Random Key Genetic Algorithm); **Brute Force**; **Cheapest Insertion**; **Christofides Algorithm**; **Clarke & Wright** (Savings Heuristic); **Concave Hull Algorithm**; **Convex Hull Algorithm**; **Elastic Net**; **Extremal Optimization**; **Farthest Insertion**; **FRNN** (Fixed Radius Near Neighbor); **Genetic Algorithm**; **GRASP** (Greedy Randomized Adaptive Search Procedure); **Greedy Karp-Steele Patching**; **Guided Search**; **Hopfield Network**; **Iterated Search**; **Karp-Steele Patching**; **Large Neighborhood Search**; **Multifragment Heuristic**; **Nearest Insertion**; **Nearest Neighbour**; **Random Insertion**; **Random Tour**; **Randomized Spectral Seriation**; **RL Q-Learning**; **RL Double Q-Learning**; **RL S.A.R.S.A** (State Action Reward State Action); **Ruin & Recreate**; **Scatter Search**; **Simulated Annealing**; **SOM** (Self Organizing Maps); **Space Filling Curve** (Hilbert); **Space Filling Curve** (Morton); **Space Filling Curve** (Sierpinski); **Spectral Seriation Initializer**; **Stochastic Hill Climbing**; **Sweep**; **Tabu Search**; **Truncated Branch & Bound**; **Twice-Around the Tree Algorithm** (Double Tree Algorithm); **Variable Neighborhood Search**; **Zero Suffix Method**.
19
37
 
@@ -132,7 +150,7 @@ print('Total Distance: ', round(distance, 2))
132
150
  - Zero Suffix Method ([ Colab Demo ](https://colab.research.google.com/drive/1IXiZ8eQThElMFK-ATD1GoUyKC02LI3ij?usp=sharing)) ( [ Paper ](https://www.m-hikari.com/ijcms-2011/21-24-2011/sudhakarIJCMS21-24-2011.pdf))
133
151
 
134
152
  # Single Objective Optimization
135
- For Single Objective Optimization try [pyMetaheuristic](https://github.com/Valdecy/pyMetaheuristic)
153
+ For Single Objective Optimization, try [pyMetaheuristic](https://github.com/Valdecy/pyMetaheuristic)
136
154
 
137
155
  # Multiobjective Optimization or Many Objectives Optimization
138
- For Multiobjective Optimization or Many Objectives Optimization try [pyMultiobjective](https://github.com/Valdecy/pyMultiobjective)
156
+ For Multiobjective Optimization or Many Objectives Optimization, try [pyMultiobjective](https://github.com/Valdecy/pyMultiobjective)
@@ -1,138 +1,145 @@
1
- Metadata-Version: 2.1
2
- Name: pycombinatorial
3
- Version: 2.1.8
4
- Summary: A library to solve TSP (Travelling Salesman Problem) using Exact Algorithms, Heuristics, Metaheuristics and Reinforcement Learning
5
- Home-page: https://github.com/Valdecy/pyCombinatorial
6
- Author: Valdecy Pereira
7
- Author-email: valdecy.pereira@gmail.com
8
- License: GNU
9
- Description-Content-Type: text/markdown
10
- License-File: LICENSE
11
-
12
- # pyCombinatorial
13
-
14
- ## Introduction
15
-
16
- **pyCombinatorial** is a Python-based library designed to tackle the classic Travelling Salesman Problem (TSP) through a diverse set of **Exact Algorithms**, **Heuristics**, **Metaheuristics** and **Reinforcement Learning**. It brings together both well-established and cutting-edge methodologies, offering end-users a flexible toolkit to generate high-quality solutions for TSP instances of various sizes and complexities.
17
-
18
- Techniques: **2-opt**; **2.5-opt**; **3-opt**; **4-opt**; **5-opt**; **Or-opt**; **2-opt Stochastic**; **2.5-opt Stochastic**; **3-opt Stochastic**; **4-opt Stochastic**; **5-opt Stochastic**; **Ant Colony Optimization**; **Adaptive Large Neighborhood Search**; **Bellman-Held-Karp Exact Algorithm**; **Bitonic Tour**; **Branch & Bound**; **BRKGA** (Biased Random Key Genetic Algorithm); **Brute Force**; **Cheapest Insertion**; **Christofides Algorithm**; **Clarke & Wright** (Savings Heuristic); **Concave Hull Algorithm**; **Convex Hull Algorithm**; **Elastic Net**; **Extremal Optimization**; **Farthest Insertion**; **FRNN** (Fixed Radius Near Neighbor); **Genetic Algorithm**; **GRASP** (Greedy Randomized Adaptive Search Procedure); **Greedy Karp-Steele Patching**; **Guided Search**; **Hopfield Network**; **Iterated Search**; **Karp-Steele Patching**; **Large Neighborhood Search**; **Multifragment Heuristic**; **Nearest Insertion**; **Nearest Neighbour**; **Random Insertion**; **Random Tour**; **Randomized Spectral Seriation**; **RL Q-Learning**; **RL Double Q-Learning**; **RL S.A.R.S.A** (State Action Reward State Action); **Ruin & Recreate**; **Scatter Search**; **Simulated Annealing**; **SOM** (Self Organizing Maps); **Space Filling Curve** (Hilbert); **Space Filling Curve** (Morton); **Space Filling Curve** (Sierpinski); **Spectral Seriation Initializer**; **Stochastic Hill Climbing**; **Sweep**; **Tabu Search**; **Truncated Branch & Bound**; **Twice-Around the Tree Algorithm** (Double Tree Algorithm); **Variable Neighborhood Search**; **Zero Suffix Method**.
19
-
20
- ## Usage
21
-
22
- 1. Install
23
-
24
- ```bash
25
- pip install pycombinatorial
26
- ```
27
-
28
- 2. Import
29
-
30
- ```py3
31
-
32
-
33
- # Required Libraries
34
- import pandas as pd
35
-
36
- # GA
37
- from pyCombinatorial.algorithm import genetic_algorithm
38
- from pyCombinatorial.utils import graphs, util
39
-
40
- # Loading Coordinates # Berlin 52 (Minimum Distance = 7544.3659)
41
- coordinates = pd.read_csv('https://bit.ly/3Oyn3hN', sep = '\t')
42
- coordinates = coordinates.values
43
-
44
- # Obtaining the Distance Matrix
45
- distance_matrix = util.build_distance_matrix(coordinates)
46
-
47
- # GA - Parameters
48
- parameters = {
49
- 'population_size': 15,
50
- 'elite': 1,
51
- 'mutation_rate': 0.1,
52
- 'mutation_search': 8,
53
- 'generations': 1000,
54
- 'verbose': True
55
- }
56
-
57
- # GA - Algorithm
58
- route, distance = genetic_algorithm(distance_matrix, **parameters)
59
-
60
- # Plot Locations and Tour
61
- graphs.plot_tour(coordinates, city_tour = route, view = 'browser', size = 10)
62
- print('Total Distance: ', round(distance, 2))
63
-
64
- ```
65
-
66
- 3. Try it in **Colab**
67
-
68
- 3.1 Lat Long Datasets
69
-
70
- - Lat Long ([ Colab Demo ](https://colab.research.google.com/drive/17jFw4z1R9gOoAfB-ZCZa6c-PukVKdrt3?usp=sharing))
71
-
72
- 3.2 Algorithms
73
-
74
- - 2-opt ([ Colab Demo ](https://colab.research.google.com/drive/1SLkM8r_VdlFCpNpm-2yTfr_ynSC5WIX9?usp=sharing)) ( [ Paper ](https://www.jstor.org/stable/167074))
75
- - 2.5-opt ([ Colab Demo ](https://colab.research.google.com/drive/17bJ-I26prnryAU8p-xf0l7R91cJzb85N?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/s10955-007-9382-1))
76
- - 3-opt ([ Colab Demo ](https://colab.research.google.com/drive/1iAZLawLBZ-7yaPCyobMtel1SvBamxtjL?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
77
- - 4-opt ([ Colab Demo ](https://colab.research.google.com/drive/1N8HKhVY4s20sfqo8IWIaCY-NHVk6gARS?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
78
- - 5-opt ([ Colab Demo ](https://colab.research.google.com/drive/15Qrk-7H4oRaTR77ADvwkiN0sLvycgFDH?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
79
- - Or-opt ([ Colab Demo ](https://colab.research.google.com/drive/1p7JwrFLH83ZroCzIweXLCAXYgA3FKAI0?usp=sharing)) ( [ Paper ](https://doi.org/10.1057/palgrave.jors.2602160))
80
- - 2-opt Stochastic ([ Colab Demo ](https://colab.research.google.com/drive/1xTm__7OwQVC_KX2b-eExLGgG1DgnJ10a?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/j.trpro.2014.10.001))
81
- - 2.5-opt Stochastic ([ Colab Demo ](https://colab.research.google.com/drive/16W_QqJ1PebVgqUx8NFOSS5kG3DsJ51UQ?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/s10955-007-9382-1))
82
- - 3-opt Stochastic ([ Colab Demo ](https://colab.research.google.com/drive/1A5lPW6BSDD2rLNDlnpQo44U8jwKcAGXL?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
83
- - 4-opt Stochastic ([ Colab Demo ](https://colab.research.google.com/drive/1igWrUMVSInzyeOdhPcGuMjyooZ6elvLY?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
84
- - 5-opt Stochastic ([ Colab Demo ](https://colab.research.google.com/drive/13vS5MCeFqb3F4ntxrw3iCsMbJTfEVyeo?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
85
- - Ant Colony Optimization ([ Colab Demo ](https://colab.research.google.com/drive/1O2qogrjE4mZUZX3nsSxw43crumlBnd-D?usp=sharing)) ( [ Paper ](https://doi.org/10.1109/4235.585892))
86
- - Adaptive Large Neighborhood Search ([ Colab Demo ](https://colab.research.google.com/drive/1vShK5fe2xRCpMkurgd4PzmstGtn6d_LQ?usp=sharing)) ( [ Paper ](https://www.jstor.org/stable/25769321))
87
- - Bellman-Held-Karp Exact Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1HSnArk-v8PWY4dlCvT5zcSAnT1FJEDaf?usp=sharing)) ( [ Paper ](https://dl.acm.org/doi/10.1145/321105.321111))
88
- - Bitonic Tour([ Colab Demo ](https://colab.research.google.com/drive/1AopZ7IBgC_2fhLE0E4yAgxofYc0wTnge?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/978-3-030-63920-4_12))
89
- - Branch & Bound ([ Colab Demo ](https://colab.research.google.com/drive/1oDHrECSW3g4vBEsrO8T7qSHID4fxFiqs?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/j.disopt.2016.01.005))
90
- - BRKGA (Biased Random Key Genetic Algorithm) ([ Colab Demo ](https://colab.research.google.com/drive/1lwnpUBl1P1LIvzN1saLgEvnaKZRMWLHn?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/s10732-010-9143-1))
91
- - Brute Force ([ Colab Demo ](https://colab.research.google.com/drive/10vOkBz3Cv9UdHPlcBWkDmJO7EvDg96ar?usp=sharing)) ( [ Paper ](https://swarm.cs.pub.ro/~mbarbulescu/cripto/Understanding%20Cryptography%20by%20Christof%20Paar%20.pdf))
92
- - Cheapest Insertion ([ Colab Demo ](https://colab.research.google.com/drive/1QOg8FDvrFUgojwLXD2BBvEuB9Mu7q88a?usp=sharing)) ( [ Paper ](https://disco.ethz.ch/courses/fs16/podc/readingAssignment/1.pdf))
93
- - Christofides Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1Wbm-YQ9TeH2OU-IjZzVdDkWGQILv4Pj_?usp=sharing)) ( [ Paper ](https://web.archive.org/web/20190721172134/https://apps.dtic.mil/dtic/tr/fulltext/u2/a025602.pdf))
94
- - Clarke & Wright (Savings Heuristic) ([ Colab Demo ](https://colab.research.google.com/drive/1XC2yoVe6wTsjt7u2fBaL3LcKUu42FG8r?usp=sharing)) ( [ Paper ](http://dx.doi.org/10.1287/opre.12.4.568))
95
- - Concave Hull Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1P96DerRe7CLyC9dQNr96nEkNHnxpGYY4?usp=sharing)) ( [ Paper ](http://repositorium.sdum.uminho.pt/bitstream/1822/6429/1/ConcaveHull_ACM_MYS.pdf))
96
- - Convex Hull Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1Wn2OWccZukOfMtJuGV9laklLTc8vjOFq?usp=sharing)) ( [ Paper ](https://doi.org/10.1109/TSMC.1974.4309370))
97
- - Elastic Net ([ Colab Demo ](https://colab.research.google.com/drive/1F7IlkKdZ3_zQ_MkhknkIPHvE5RqJG7YC?usp=sharing)) ( [ Paper ](https://doi.org/10.1038/326689a0))
98
- - Extremal Optimization ([ Colab Demo ](https://colab.research.google.com/drive/1Y5YH0eYKjr1nj_IfhJXaILRDIXm-LWLs?usp=sharing)) ( [ Paper ](https://doi.org/10.1109/5992.881710))
99
- - Farthest Insertion ([ Colab Demo ](https://colab.research.google.com/drive/13pWiLL_dO9Y1lvQO0zD50MXk4mD0Tn1W?usp=sharing)) ( [ Paper ](https://disco.ethz.ch/courses/fs16/podc/readingAssignment/1.pdf))
100
- - FRNN (Fixed Radius Near Neighbor) ([ Colab Demo ](https://colab.research.google.com/drive/16GgUGA0_TyR6UOqg0TtndjjuZhQ0TTYT?usp=sharing)) ( [ Paper ](https://dl.acm.org/doi/pdf/10.5555/320176.320186))
101
- - Genetic Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1zO9rm-G6HOMeg1Q_ptMHJr48EpHcCAIS?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/BF02125403))
102
- - GRASP (Greedy Randomized Adaptive Search Procedure) ([ Colab Demo ](https://colab.research.google.com/drive/1OnRyCc6C_QL6wr6-l5RlQI4eGbMdwuhS?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/BF01096763))
103
- - Greedy Karp-Steele Patching ([ Colab Demo ](https://colab.research.google.com/drive/1to3u45QWWQK8REj1_YiF5rUqUqNjB18q?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/S0377-2217(99)00468-3))
104
- - Guided Search ([ Colab Demo ](https://colab.research.google.com/drive/1uT9mlDoo37Ni7hqziGNELEGQCGBKQ83o?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/S0377-2217(98)00099-X))
105
- - Hopfield Network ([ Colab Demo ](https://colab.research.google.com/drive/1Io20FFsndsRT3Bc1nimLBcpH5WtEt7Pe?usp=sharing)) ( [ Paper ](https://doi.org/10.1515/dema-1996-0126))
106
- - Iterated Search ([ Colab Demo ](https://colab.research.google.com/drive/1U3sPpknulwsCUQq9mK7Ywfb8ap2GIXZv?usp=sharing)) ( [ Paper ](https://doi.org/10.1063/1.36219))
107
- - Karp-Steele Patching ([ Colab Demo ](https://colab.research.google.com/drive/12xLLDNIk6OOSNQXqYSYtdwhupZ9Kt5xb?usp=sharing)) ( [ Paper ](https://doi.org/10.1137/0208045))
108
- - Large Neighborhood Search ([ Colab Demo ](https://colab.research.google.com/drive/1t4cafHRRzOLN4xth96jE-2qHoPQOLsn5?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/3-540-49481-2_30))
109
- - Multifragment Heuristic ([ Colab Demo ](https://colab.research.google.com/drive/1YNHVjS6P35bAnqGZyP7ERNrTnG9tNuhF?usp=sharing)) ( [ Paper ](https://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=08D176AEFA57EF1941645F2B31DF1686?doi=10.1.1.92.1635&rep=rep1&type=pdf))
110
- - Nearest Insertion ([ Colab Demo ](https://colab.research.google.com/drive/1R4mz604EG-unKktu8ON_Hpoywi3OIRHK?usp=sharing)) ( [ Paper ](https://disco.ethz.ch/courses/fs16/podc/readingAssignment/1.pdf))
111
- - Nearest Neighbour ([ Colab Demo ](https://colab.research.google.com/drive/1aL1kYXgSjUJYPfYSMy_0SWq4hJ3nrueJ?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/S0166-218X(01)00195-0))
112
- - Random Insertion ([ Colab Demo ](https://colab.research.google.com/drive/1RP_grqrTXyDkHOLB_L1H8TkvxdLli5hG?usp=sharing)) ( [ Paper ](https://disco.ethz.ch/courses/fs16/podc/readingAssignment/1.pdf))
113
- - Random Tour ([ Colab Demo ](https://colab.research.google.com/drive/1DPXMJXInkGKTyVFDAQ2bKXjglhy3DaCS?usp=sharing)) ( [ Paper ](https://doi.org/10.1023/A:1011263204536))
114
- - Randomized Spectral Seriation ([ Colab Demo ](https://colab.research.google.com/drive/1PTtO6HJfftsFZEScCYZvzpBJsgMyjBCY?usp=sharing)) ( [ Paper ](https://doi.org/10.1137/S0097539795285771))
115
- - RL Q-Learning ([ Colab Demo ](https://colab.research.google.com/drive/1dnZhLAzQdz9kzxKrVcwMECWbyEKkZ7St?usp=sharing)) ( [ Paper ](https://doi.org/10.1049/tje2.12303))
116
- - RL Double Q-Learning ([ Colab Demo ](https://colab.research.google.com/drive/1VTv8A6Ac-LvBxsereFyGRfkiLRbJI547?usp=sharing)) ( [ Paper ](https://doi.org/10.1049/tje2.12303))
117
- - RL S.A.R.S.A ([ Colab Demo ](https://colab.research.google.com/drive/1q9hon3jFf8xVCw4idxhu7goLREKbQ6N3?usp=sharing)) ( [ Paper ](https://doi.org/10.1049/tje2.12303))
118
- - Ruin & Recreate ([ Colab Demo ](https://colab.research.google.com/drive/18uPEZqwOZa07YdVoNht_VMH3SGhLBo-A?usp=sharing)) ( [ Paper ](https://doi.org/10.1006/jcph.1999.6413))
119
- - Scatter Search ([ Colab Demo ](https://colab.research.google.com/drive/115Ql6KegvOjlNUUfsbY4fA8Vab-db26N?usp=sharing)) ( [ Paper ](https://doi.org/10.1111/j.1540-5915.1977.tb01074.x))
120
- - Simulated Annealing ([ Colab Demo ](https://colab.research.google.com/drive/10Th0yLaAeSqp9FhYB0H00e4sXTbg7Jp2?usp=sharing)) ( [ Paper ](https://www.jstor.org/stable/1690046))
121
- - SOM (Self Organizing Maps) ([ Colab Demo ](https://colab.research.google.com/drive/1-ZwSFnXf1_kCeY_p3SC3N21T8QeSWsg6?usp=sharing)) ( [ Paper ](https://arxiv.org/pdf/2201.07208.pdf))
122
- - Space Filling Curve (Hilbert) ([ Colab Demo ](https://colab.research.google.com/drive/1FXzWrUBjdbJBngRFHv66CZw5pFN3yOs8?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/0960-0779(95)80046-J))
123
- - Space Filling Curve (Morton) ([ Colab Demo ](https://colab.research.google.com/drive/1Z13kXyi7eaNQbBUmhvwuQjY4VaUfGVbs?usp=sharing)) ( [ Paper ](https://dominoweb.draco.res.ibm.com/reports/Morton1966.pdf))
124
- - Space Filling Curve (Sierpinski) ([ Colab Demo ](https://colab.research.google.com/drive/1w-Zptd5kOryCwvQ0qSNBNhPXC61c8QXF?usp=sharing)) ( [ Paper ](https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.67.9061&rep=rep1&type=pdf))
125
- - Spectral Seriation Initializer ([ Colab Demo ](https://colab.research.google.com/drive/1lG0pYxASU75qh0jK-A_eMCoPpCWv0I4V?usp=sharing)) ( [ Paper ](https://doi.org/10.1137/S0097539795285771))
126
- - Stochastic Hill Climbing ([ Colab Demo ](https://colab.research.google.com/drive/1_wP6vg4JoRHGItGxEtXcf9Y9OuuoDlDl?usp=sharing)) ( [ Paper ](http://aima.cs.berkeley.edu/))
127
- - Sweep ([ Colab Demo ](https://colab.research.google.com/drive/1AkAn4yeomAp6POBslk3Asd6OrxfBrHT7?usp=sharing)) ( [ Paper ](http://dx.doi.org/10.1287/opre.22.2.340))
128
- - Tabu Search ([ Colab Demo ](https://colab.research.google.com/drive/1SRwQrBaxkKk18SDvQPy--0yNRWdl6Y1G?usp=sharing)) ( [ Paper ](https://doi.org/10.1287/ijoc.1.3.190))
129
- - Truncated Branch & Bound ([ Colab Demo ](https://colab.research.google.com/drive/16m72PrBZN8mWMCer12dgsStcNGs4DVdQ?usp=sharing)) ( [ Paper ](https://research.ijcaonline.org/volume65/number5/pxc3885866.pdf))
130
- - Twice-Around the Tree Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1tf5tc5DxvEUc89JaaFgzmK1TtD1e4fkc?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/0196-6774(84)90029-4))
131
- - Variable Neighborhood Search ([ Colab Demo ](https://colab.research.google.com/drive/1yMWjYuurzpcijsCFDTA76fAwJmSaDkZq?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/S0305-0548(97)00031-2))
132
- - Zero Suffix Method ([ Colab Demo ](https://colab.research.google.com/drive/1IXiZ8eQThElMFK-ATD1GoUyKC02LI3ij?usp=sharing)) ( [ Paper ](https://www.m-hikari.com/ijcms-2011/21-24-2011/sudhakarIJCMS21-24-2011.pdf))
133
-
134
- # Single Objective Optimization
135
- For Single Objective Optimization try [pyMetaheuristic](https://github.com/Valdecy/pyMetaheuristic)
136
-
137
- # Multiobjective Optimization or Many Objectives Optimization
138
- For Multiobjective Optimization or Many Objectives Optimization try [pyMultiobjective](https://github.com/Valdecy/pyMultiobjective)
1
+ # pyCombinatorial
2
+
3
+ New to Python or prefer a graphical interface? The **pyCombinatorial Web App** lets you run your analysis in clicks, not lines of code.
4
+
5
+ ```python
6
+ import pyCombinatorial
7
+
8
+ # Start the web service using:
9
+ pyCombinatorial.web_app()
10
+
11
+ ```
12
+
13
+ <p align="center">
14
+ <img src="https://github.com/Valdecy/Datasets/raw/master/Data%20Science/lab_pc.png" alt="Lab" width="700"/>
15
+ </p>
16
+
17
+ * [Preview -- **pyCombinatorial Web App** -- in Google Colab](https://colab.research.google.com/drive/11o2o_BTskKsS2Ybbs7vrwAzdLTczxhaJ?usp=sharing)
18
+
19
+ _This Google Colab Demo is intended for quick demos only. For the best experience, run the Web UI locally or open it directly in a full browser._
20
+
21
+ ## Introduction
22
+
23
+ **pyCombinatorial** is a Python-based library designed to tackle the classic Traveling Salesman Problem (TSP) through a diverse set of **Exact Algorithms**, **Heuristics**, **Metaheuristics**, and **Reinforcement Learning**. It brings together well-established and cutting-edge methodologies, offering end users a flexible toolkit to generate high-quality solutions for TSP instances of varying sizes and complexities.
24
+
25
+ Techniques: **2-opt**; **2.5-opt**; **3-opt**; **4-opt**; **5-opt**; **Or-opt**; **2-opt Stochastic**; **2.5-opt Stochastic**; **3-opt Stochastic**; **4-opt Stochastic**; **5-opt Stochastic**; **Ant Colony Optimization**; **Adaptive Large Neighborhood Search**; **Bellman-Held-Karp Exact Algorithm**; **Bitonic Tour**; **Branch & Bound**; **BRKGA** (Biased Random Key Genetic Algorithm); **Brute Force**; **Cheapest Insertion**; **Christofides Algorithm**; **Clarke & Wright** (Savings Heuristic); **Concave Hull Algorithm**; **Convex Hull Algorithm**; **Elastic Net**; **Extremal Optimization**; **Farthest Insertion**; **FRNN** (Fixed Radius Near Neighbor); **Genetic Algorithm**; **GRASP** (Greedy Randomized Adaptive Search Procedure); **Greedy Karp-Steele Patching**; **Guided Search**; **Hopfield Network**; **Iterated Search**; **Karp-Steele Patching**; **Large Neighborhood Search**; **Multifragment Heuristic**; **Nearest Insertion**; **Nearest Neighbour**; **Random Insertion**; **Random Tour**; **Randomized Spectral Seriation**; **RL Q-Learning**; **RL Double Q-Learning**; **RL S.A.R.S.A** (State Action Reward State Action); **Ruin & Recreate**; **Scatter Search**; **Simulated Annealing**; **SOM** (Self Organizing Maps); **Space Filling Curve** (Hilbert); **Space Filling Curve** (Morton); **Space Filling Curve** (Sierpinski); **Spectral Seriation Initializer**; **Stochastic Hill Climbing**; **Sweep**; **Tabu Search**; **Truncated Branch & Bound**; **Twice-Around the Tree Algorithm** (Double Tree Algorithm); **Variable Neighborhood Search**; **Zero Suffix Method**.
26
+
27
+ ## Usage
28
+
29
+ 1. Install
30
+
31
+ ```bash
32
+ pip install pycombinatorial
33
+ ```
34
+
35
+ 2. Import
36
+
37
+ ```py3
38
+
39
+
40
+ # Required Libraries
41
+ import pandas as pd
42
+
43
+ # GA
44
+ from pyCombinatorial.algorithm import genetic_algorithm
45
+ from pyCombinatorial.utils import graphs, util
46
+
47
+ # Loading Coordinates # Berlin 52 (Minimum Distance = 7544.3659)
48
+ coordinates = pd.read_csv('https://bit.ly/3Oyn3hN', sep = '\t')
49
+ coordinates = coordinates.values
50
+
51
+ # Obtaining the Distance Matrix
52
+ distance_matrix = util.build_distance_matrix(coordinates)
53
+
54
+ # GA - Parameters
55
+ parameters = {
56
+ 'population_size': 15,
57
+ 'elite': 1,
58
+ 'mutation_rate': 0.1,
59
+ 'mutation_search': 8,
60
+ 'generations': 1000,
61
+ 'verbose': True
62
+ }
63
+
64
+ # GA - Algorithm
65
+ route, distance = genetic_algorithm(distance_matrix, **parameters)
66
+
67
+ # Plot Locations and Tour
68
+ graphs.plot_tour(coordinates, city_tour = route, view = 'browser', size = 10)
69
+ print('Total Distance: ', round(distance, 2))
70
+
71
+ ```
72
+
73
+ 3. Try it in **Colab**
74
+
75
+ 3.1 Lat Long Datasets
76
+
77
+ - Lat Long ([ Colab Demo ](https://colab.research.google.com/drive/17jFw4z1R9gOoAfB-ZCZa6c-PukVKdrt3?usp=sharing))
78
+
79
+ 3.2 Algorithms
80
+
81
+ - 2-opt ([ Colab Demo ](https://colab.research.google.com/drive/1SLkM8r_VdlFCpNpm-2yTfr_ynSC5WIX9?usp=sharing)) ( [ Paper ](https://www.jstor.org/stable/167074))
82
+ - 2.5-opt ([ Colab Demo ](https://colab.research.google.com/drive/17bJ-I26prnryAU8p-xf0l7R91cJzb85N?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/s10955-007-9382-1))
83
+ - 3-opt ([ Colab Demo ](https://colab.research.google.com/drive/1iAZLawLBZ-7yaPCyobMtel1SvBamxtjL?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
84
+ - 4-opt ([ Colab Demo ](https://colab.research.google.com/drive/1N8HKhVY4s20sfqo8IWIaCY-NHVk6gARS?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
85
+ - 5-opt ([ Colab Demo ](https://colab.research.google.com/drive/15Qrk-7H4oRaTR77ADvwkiN0sLvycgFDH?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
86
+ - Or-opt ([ Colab Demo ](https://colab.research.google.com/drive/1p7JwrFLH83ZroCzIweXLCAXYgA3FKAI0?usp=sharing)) ( [ Paper ](https://doi.org/10.1057/palgrave.jors.2602160))
87
+ - 2-opt Stochastic ([ Colab Demo ](https://colab.research.google.com/drive/1xTm__7OwQVC_KX2b-eExLGgG1DgnJ10a?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/j.trpro.2014.10.001))
88
+ - 2.5-opt Stochastic ([ Colab Demo ](https://colab.research.google.com/drive/16W_QqJ1PebVgqUx8NFOSS5kG3DsJ51UQ?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/s10955-007-9382-1))
89
+ - 3-opt Stochastic ([ Colab Demo ](https://colab.research.google.com/drive/1A5lPW6BSDD2rLNDlnpQo44U8jwKcAGXL?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
90
+ - 4-opt Stochastic ([ Colab Demo ](https://colab.research.google.com/drive/1igWrUMVSInzyeOdhPcGuMjyooZ6elvLY?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
91
+ - 5-opt Stochastic ([ Colab Demo ](https://colab.research.google.com/drive/13vS5MCeFqb3F4ntxrw3iCsMbJTfEVyeo?usp=sharing)) ( [ Paper ](https://isd.ktu.lt/it2011//material/Proceedings/1_AI_5.pdf))
92
+ - Ant Colony Optimization ([ Colab Demo ](https://colab.research.google.com/drive/1O2qogrjE4mZUZX3nsSxw43crumlBnd-D?usp=sharing)) ( [ Paper ](https://doi.org/10.1109/4235.585892))
93
+ - Adaptive Large Neighborhood Search ([ Colab Demo ](https://colab.research.google.com/drive/1vShK5fe2xRCpMkurgd4PzmstGtn6d_LQ?usp=sharing)) ( [ Paper ](https://www.jstor.org/stable/25769321))
94
+ - Bellman-Held-Karp Exact Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1HSnArk-v8PWY4dlCvT5zcSAnT1FJEDaf?usp=sharing)) ( [ Paper ](https://dl.acm.org/doi/10.1145/321105.321111))
95
+ - Bitonic Tour([ Colab Demo ](https://colab.research.google.com/drive/1AopZ7IBgC_2fhLE0E4yAgxofYc0wTnge?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/978-3-030-63920-4_12))
96
+ - Branch & Bound ([ Colab Demo ](https://colab.research.google.com/drive/1oDHrECSW3g4vBEsrO8T7qSHID4fxFiqs?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/j.disopt.2016.01.005))
97
+ - BRKGA (Biased Random Key Genetic Algorithm) ([ Colab Demo ](https://colab.research.google.com/drive/1lwnpUBl1P1LIvzN1saLgEvnaKZRMWLHn?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/s10732-010-9143-1))
98
+ - Brute Force ([ Colab Demo ](https://colab.research.google.com/drive/10vOkBz3Cv9UdHPlcBWkDmJO7EvDg96ar?usp=sharing)) ( [ Paper ](https://swarm.cs.pub.ro/~mbarbulescu/cripto/Understanding%20Cryptography%20by%20Christof%20Paar%20.pdf))
99
+ - Cheapest Insertion ([ Colab Demo ](https://colab.research.google.com/drive/1QOg8FDvrFUgojwLXD2BBvEuB9Mu7q88a?usp=sharing)) ( [ Paper ](https://disco.ethz.ch/courses/fs16/podc/readingAssignment/1.pdf))
100
+ - Christofides Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1Wbm-YQ9TeH2OU-IjZzVdDkWGQILv4Pj_?usp=sharing)) ( [ Paper ](https://web.archive.org/web/20190721172134/https://apps.dtic.mil/dtic/tr/fulltext/u2/a025602.pdf))
101
+ - Clarke & Wright (Savings Heuristic) ([ Colab Demo ](https://colab.research.google.com/drive/1XC2yoVe6wTsjt7u2fBaL3LcKUu42FG8r?usp=sharing)) ( [ Paper ](http://dx.doi.org/10.1287/opre.12.4.568))
102
+ - Concave Hull Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1P96DerRe7CLyC9dQNr96nEkNHnxpGYY4?usp=sharing)) ( [ Paper ](http://repositorium.sdum.uminho.pt/bitstream/1822/6429/1/ConcaveHull_ACM_MYS.pdf))
103
+ - Convex Hull Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1Wn2OWccZukOfMtJuGV9laklLTc8vjOFq?usp=sharing)) ( [ Paper ](https://doi.org/10.1109/TSMC.1974.4309370))
104
+ - Elastic Net ([ Colab Demo ](https://colab.research.google.com/drive/1F7IlkKdZ3_zQ_MkhknkIPHvE5RqJG7YC?usp=sharing)) ( [ Paper ](https://doi.org/10.1038/326689a0))
105
+ - Extremal Optimization ([ Colab Demo ](https://colab.research.google.com/drive/1Y5YH0eYKjr1nj_IfhJXaILRDIXm-LWLs?usp=sharing)) ( [ Paper ](https://doi.org/10.1109/5992.881710))
106
+ - Farthest Insertion ([ Colab Demo ](https://colab.research.google.com/drive/13pWiLL_dO9Y1lvQO0zD50MXk4mD0Tn1W?usp=sharing)) ( [ Paper ](https://disco.ethz.ch/courses/fs16/podc/readingAssignment/1.pdf))
107
+ - FRNN (Fixed Radius Near Neighbor) ([ Colab Demo ](https://colab.research.google.com/drive/16GgUGA0_TyR6UOqg0TtndjjuZhQ0TTYT?usp=sharing)) ( [ Paper ](https://dl.acm.org/doi/pdf/10.5555/320176.320186))
108
+ - Genetic Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1zO9rm-G6HOMeg1Q_ptMHJr48EpHcCAIS?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/BF02125403))
109
+ - GRASP (Greedy Randomized Adaptive Search Procedure) ([ Colab Demo ](https://colab.research.google.com/drive/1OnRyCc6C_QL6wr6-l5RlQI4eGbMdwuhS?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/BF01096763))
110
+ - Greedy Karp-Steele Patching ([ Colab Demo ](https://colab.research.google.com/drive/1to3u45QWWQK8REj1_YiF5rUqUqNjB18q?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/S0377-2217(99)00468-3))
111
+ - Guided Search ([ Colab Demo ](https://colab.research.google.com/drive/1uT9mlDoo37Ni7hqziGNELEGQCGBKQ83o?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/S0377-2217(98)00099-X))
112
+ - Hopfield Network ([ Colab Demo ](https://colab.research.google.com/drive/1Io20FFsndsRT3Bc1nimLBcpH5WtEt7Pe?usp=sharing)) ( [ Paper ](https://doi.org/10.1515/dema-1996-0126))
113
+ - Iterated Search ([ Colab Demo ](https://colab.research.google.com/drive/1U3sPpknulwsCUQq9mK7Ywfb8ap2GIXZv?usp=sharing)) ( [ Paper ](https://doi.org/10.1063/1.36219))
114
+ - Karp-Steele Patching ([ Colab Demo ](https://colab.research.google.com/drive/12xLLDNIk6OOSNQXqYSYtdwhupZ9Kt5xb?usp=sharing)) ( [ Paper ](https://doi.org/10.1137/0208045))
115
+ - Large Neighborhood Search ([ Colab Demo ](https://colab.research.google.com/drive/1t4cafHRRzOLN4xth96jE-2qHoPQOLsn5?usp=sharing)) ( [ Paper ](https://doi.org/10.1007/3-540-49481-2_30))
116
+ - Multifragment Heuristic ([ Colab Demo ](https://colab.research.google.com/drive/1YNHVjS6P35bAnqGZyP7ERNrTnG9tNuhF?usp=sharing)) ( [ Paper ](https://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=08D176AEFA57EF1941645F2B31DF1686?doi=10.1.1.92.1635&rep=rep1&type=pdf))
117
+ - Nearest Insertion ([ Colab Demo ](https://colab.research.google.com/drive/1R4mz604EG-unKktu8ON_Hpoywi3OIRHK?usp=sharing)) ( [ Paper ](https://disco.ethz.ch/courses/fs16/podc/readingAssignment/1.pdf))
118
+ - Nearest Neighbour ([ Colab Demo ](https://colab.research.google.com/drive/1aL1kYXgSjUJYPfYSMy_0SWq4hJ3nrueJ?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/S0166-218X(01)00195-0))
119
+ - Random Insertion ([ Colab Demo ](https://colab.research.google.com/drive/1RP_grqrTXyDkHOLB_L1H8TkvxdLli5hG?usp=sharing)) ( [ Paper ](https://disco.ethz.ch/courses/fs16/podc/readingAssignment/1.pdf))
120
+ - Random Tour ([ Colab Demo ](https://colab.research.google.com/drive/1DPXMJXInkGKTyVFDAQ2bKXjglhy3DaCS?usp=sharing)) ( [ Paper ](https://doi.org/10.1023/A:1011263204536))
121
+ - Randomized Spectral Seriation ([ Colab Demo ](https://colab.research.google.com/drive/1PTtO6HJfftsFZEScCYZvzpBJsgMyjBCY?usp=sharing)) ( [ Paper ](https://doi.org/10.1137/S0097539795285771))
122
+ - RL Q-Learning ([ Colab Demo ](https://colab.research.google.com/drive/1dnZhLAzQdz9kzxKrVcwMECWbyEKkZ7St?usp=sharing)) ( [ Paper ](https://doi.org/10.1049/tje2.12303))
123
+ - RL Double Q-Learning ([ Colab Demo ](https://colab.research.google.com/drive/1VTv8A6Ac-LvBxsereFyGRfkiLRbJI547?usp=sharing)) ( [ Paper ](https://doi.org/10.1049/tje2.12303))
124
+ - RL S.A.R.S.A ([ Colab Demo ](https://colab.research.google.com/drive/1q9hon3jFf8xVCw4idxhu7goLREKbQ6N3?usp=sharing)) ( [ Paper ](https://doi.org/10.1049/tje2.12303))
125
+ - Ruin & Recreate ([ Colab Demo ](https://colab.research.google.com/drive/18uPEZqwOZa07YdVoNht_VMH3SGhLBo-A?usp=sharing)) ( [ Paper ](https://doi.org/10.1006/jcph.1999.6413))
126
+ - Scatter Search ([ Colab Demo ](https://colab.research.google.com/drive/115Ql6KegvOjlNUUfsbY4fA8Vab-db26N?usp=sharing)) ( [ Paper ](https://doi.org/10.1111/j.1540-5915.1977.tb01074.x))
127
+ - Simulated Annealing ([ Colab Demo ](https://colab.research.google.com/drive/10Th0yLaAeSqp9FhYB0H00e4sXTbg7Jp2?usp=sharing)) ( [ Paper ](https://www.jstor.org/stable/1690046))
128
+ - SOM (Self Organizing Maps) ([ Colab Demo ](https://colab.research.google.com/drive/1-ZwSFnXf1_kCeY_p3SC3N21T8QeSWsg6?usp=sharing)) ( [ Paper ](https://arxiv.org/pdf/2201.07208.pdf))
129
+ - Space Filling Curve (Hilbert) ([ Colab Demo ](https://colab.research.google.com/drive/1FXzWrUBjdbJBngRFHv66CZw5pFN3yOs8?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/0960-0779(95)80046-J))
130
+ - Space Filling Curve (Morton) ([ Colab Demo ](https://colab.research.google.com/drive/1Z13kXyi7eaNQbBUmhvwuQjY4VaUfGVbs?usp=sharing)) ( [ Paper ](https://dominoweb.draco.res.ibm.com/reports/Morton1966.pdf))
131
+ - Space Filling Curve (Sierpinski) ([ Colab Demo ](https://colab.research.google.com/drive/1w-Zptd5kOryCwvQ0qSNBNhPXC61c8QXF?usp=sharing)) ( [ Paper ](https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.67.9061&rep=rep1&type=pdf))
132
+ - Spectral Seriation Initializer ([ Colab Demo ](https://colab.research.google.com/drive/1lG0pYxASU75qh0jK-A_eMCoPpCWv0I4V?usp=sharing)) ( [ Paper ](https://doi.org/10.1137/S0097539795285771))
133
+ - Stochastic Hill Climbing ([ Colab Demo ](https://colab.research.google.com/drive/1_wP6vg4JoRHGItGxEtXcf9Y9OuuoDlDl?usp=sharing)) ( [ Paper ](http://aima.cs.berkeley.edu/))
134
+ - Sweep ([ Colab Demo ](https://colab.research.google.com/drive/1AkAn4yeomAp6POBslk3Asd6OrxfBrHT7?usp=sharing)) ( [ Paper ](http://dx.doi.org/10.1287/opre.22.2.340))
135
+ - Tabu Search ([ Colab Demo ](https://colab.research.google.com/drive/1SRwQrBaxkKk18SDvQPy--0yNRWdl6Y1G?usp=sharing)) ( [ Paper ](https://doi.org/10.1287/ijoc.1.3.190))
136
+ - Truncated Branch & Bound ([ Colab Demo ](https://colab.research.google.com/drive/16m72PrBZN8mWMCer12dgsStcNGs4DVdQ?usp=sharing)) ( [ Paper ](https://research.ijcaonline.org/volume65/number5/pxc3885866.pdf))
137
+ - Twice-Around the Tree Algorithm ([ Colab Demo ](https://colab.research.google.com/drive/1tf5tc5DxvEUc89JaaFgzmK1TtD1e4fkc?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/0196-6774(84)90029-4))
138
+ - Variable Neighborhood Search ([ Colab Demo ](https://colab.research.google.com/drive/1yMWjYuurzpcijsCFDTA76fAwJmSaDkZq?usp=sharing)) ( [ Paper ](https://doi.org/10.1016/S0305-0548(97)00031-2))
139
+ - Zero Suffix Method ([ Colab Demo ](https://colab.research.google.com/drive/1IXiZ8eQThElMFK-ATD1GoUyKC02LI3ij?usp=sharing)) ( [ Paper ](https://www.m-hikari.com/ijcms-2011/21-24-2011/sudhakarIJCMS21-24-2011.pdf))
140
+
141
+ # Single Objective Optimization
142
+ For Single Objective Optimization, try [pyMetaheuristic](https://github.com/Valdecy/pyMetaheuristic)
143
+
144
+ # Multiobjective Optimization or Many Objectives Optimization
145
+ For Multiobjective Optimization or Many Objectives Optimization, try [pyMultiobjective](https://github.com/Valdecy/pyMultiobjective)
@@ -0,0 +1,5 @@
1
+ """Top-level package for pyCombinatorial."""
2
+
3
+ from .web import web_app
4
+
5
+ __all__ = ['web_app']
@@ -56,4 +56,4 @@ from .ssi import spectral_seriation_initializer
56
56
  from .swp import sweep
57
57
  from .tat import tat_algorithm
58
58
  from .tbb import truncated_branch_and_bound
59
- from .zs import zero_suffix_method
59
+ from .zs import zero_suffix_method
@@ -124,4 +124,4 @@ def ant_colony_optimization(distance_matrix, ants = 15, iterations = 100, alpha
124
124
  best_route[0].append(init_city)
125
125
  return best_route[0], best_route[1]
126
126
 
127
- ############################################################################
127
+ ############################################################################
@@ -125,4 +125,4 @@ def christofides_algorithm(distance_matrix, local_search = True, verbose = True)
125
125
  return route, distance
126
126
 
127
127
  ############################################################################
128
-
128
+
@@ -145,7 +145,7 @@ def local_search_4_opt(distance_matrix, city_tour, recursive_seeding = -1, verbo
145
145
  [a + c + b + d],
146
146
  [a + c + d + b],
147
147
 
148
- ]
148
+ ]
149
149
  for item in trial:
150
150
  best_route_1[0] = item[0]
151
151
  best_route_1[1] = distance_calc(distance_matrix, [best_route_1[0] + [best_route_1[0][0]], 1])
@@ -97,7 +97,8 @@ def ruin_and_recreate(city_tour, distance_matrix, iterations = 100, ruin_rate =
97
97
  distance = city_list[1]
98
98
  best_r = copy.deepcopy(route)
99
99
  best_d = distance
100
- for i in range(0, iterations):
100
+ iteration = 0
101
+ for _ in range(0, iterations):
101
102
  n_remove = max(1, int(len(removable) * ruin_rate))
102
103
  to_remove = set(np.random.choice(removable, min(n_remove, len(removable)), replace = False))
103
104
  route = [city for city in route if city not in to_remove]
@@ -106,10 +107,11 @@ def ruin_and_recreate(city_tour, distance_matrix, iterations = 100, ruin_rate =
106
107
  route = regret2_insertion(route, to_remove, distance_matrix)
107
108
  distance = distance_calc(distance_matrix, [route, distance])
108
109
  if (verbose == True):
109
- print('Iteration = ', i, 'Distance = ', round(best_d, 2))
110
+ print('Iteration = ', iteration, 'Distance = ', round(best_d, 2))
110
111
  if distance < best_d:
111
112
  best_r = copy.deepcopy(route)
112
113
  best_d = distance
114
+ iteration = iteration + 1
113
115
  if (local_search == True):
114
116
  print('')
115
117
  print('Local Search:')
@@ -119,7 +119,7 @@ def simulated_annealing_tsp(distance_matrix, initial_temperature = 1.0, temperat
119
119
  fx_new = new_guess[1]
120
120
  delta = (fx_new - fx_old)
121
121
  r = int.from_bytes(os.urandom(8), byteorder = 'big') / ((1 << 64) - 1)
122
- p = np.exp(-delta/temperature) #p = np.exp(np.clip(-delta/temperature, -30, 30))
122
+ p = np.exp(-delta/temperature)
123
123
  if (delta < 0 or r <= p):
124
124
  guess = copy.deepcopy(new_guess)
125
125
  if (fx_new < fx_best):
@@ -129,4 +129,4 @@ def simulated_annealing_tsp(distance_matrix, initial_temperature = 1.0, temperat
129
129
  route, distance = guess
130
130
  return route, distance
131
131
 
132
- ############################################################################
132
+ ############################################################################
@@ -140,4 +140,5 @@ def spectral_seriation_initializer(D, k = 12, iterations = 800, sigma_noise = 0.
140
140
  best_tour.append(best_tour[0])
141
141
  return best_tour, int(best_L)
142
142
 
143
- ############################################################################
143
+
144
+ ############################################################################
@@ -161,4 +161,4 @@ def plot_tour_latlong(lat_long, solution):
161
161
  folium.PolyLine(locations , color = '#0a0a0a', weight = 1.5, opacity = 1).add_to(m)
162
162
  return m
163
163
 
164
- ############################################################################
164
+ ############################################################################
@@ -0,0 +1,116 @@
1
+ from __future__ import annotations
2
+
3
+ import threading
4
+ import webbrowser
5
+ from functools import partial
6
+ from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
7
+ from pathlib import Path
8
+ from typing import Optional
9
+
10
+ __all__ = ["WebVisualizerServer", "web_app"]
11
+
12
+
13
+ class _QuietHandler(SimpleHTTPRequestHandler):
14
+ """HTTP handler that serves the packaged web assets with minimal logging."""
15
+
16
+ def log_message(self, format: str, *args) -> None: # noqa: A003
17
+ return
18
+
19
+
20
+ class WebVisualizerServer:
21
+ """Container for a running pyCombinatorial web visualizer server."""
22
+
23
+ def __init__(
24
+ self,
25
+ server: ThreadingHTTPServer,
26
+ thread: Optional[threading.Thread],
27
+ url: str,
28
+ directory: Path,
29
+ ) -> None:
30
+ self.server = server
31
+ self.thread = thread
32
+ self.url = url
33
+ self.directory = directory
34
+
35
+ @property
36
+ def host(self) -> str:
37
+ return str(self.server.server_address[0])
38
+
39
+ @property
40
+ def port(self) -> int:
41
+ return int(self.server.server_address[1])
42
+
43
+ def shutdown(self) -> None:
44
+ self.server.shutdown()
45
+ self.server.server_close()
46
+ if self.thread is not None and self.thread.is_alive():
47
+ self.thread.join(timeout=2.0)
48
+
49
+ def __repr__(self) -> str:
50
+ return f"WebVisualizerServer(url={self.url!r}, directory={str(self.directory)!r})"
51
+
52
+
53
+ def _build_url(host: str, port: int) -> str:
54
+ display_host = '127.0.0.1' if host in ('0.0.0.0', '::') else host
55
+ return f'http://{display_host}:{port}/'
56
+
57
+
58
+
59
+ def web_app(
60
+ host: str = '127.0.0.1',
61
+ port: int = 8000,
62
+ open_browser: bool = True,
63
+ block: bool = True,
64
+ ) -> WebVisualizerServer:
65
+ """
66
+ Launch the packaged pyCombinatorial web visualizer.
67
+
68
+ Parameters
69
+ ----------
70
+ host : str, default='127.0.0.1'
71
+ Network interface used by the local HTTP server.
72
+ port : int, default=8000
73
+ Port used by the local HTTP server. Use 0 for an ephemeral free port.
74
+ open_browser : bool, default=True
75
+ Open the default browser automatically.
76
+ block : bool, default=True
77
+ If True, keep the server in the foreground until interrupted.
78
+ If False, run it in a daemon thread and return immediately.
79
+
80
+ Returns
81
+ -------
82
+ WebVisualizerServer
83
+ Object containing the server, thread handle, served directory, and URL.
84
+ """
85
+
86
+ web_dir = Path(__file__).resolve().parent
87
+ index_html = web_dir / 'index.html'
88
+ if not index_html.exists():
89
+ raise FileNotFoundError(
90
+ 'The packaged web visualizer assets were not found. '
91
+ 'Reinstall pyCombinatorial ensuring package data is included.'
92
+ )
93
+
94
+ handler = partial(_QuietHandler, directory=str(web_dir))
95
+ server = ThreadingHTTPServer((host, port), handler)
96
+ actual_host, actual_port = server.server_address[:2]
97
+ url = _build_url(str(actual_host), int(actual_port))
98
+ app = WebVisualizerServer(server=server, thread=None, url=url, directory=web_dir)
99
+
100
+ if open_browser:
101
+ webbrowser.open(url)
102
+
103
+ if block:
104
+ print(f'pyCombinatorial web visualizer available at {url}')
105
+ try:
106
+ server.serve_forever()
107
+ except KeyboardInterrupt:
108
+ pass
109
+ finally:
110
+ app.shutdown()
111
+ return app
112
+
113
+ thread = threading.Thread(target=server.serve_forever, daemon=True)
114
+ thread.start()
115
+ app.thread = thread
116
+ return app
@@ -0,0 +1,5 @@
1
+ from . import web_app
2
+
3
+
4
+ if __name__ == '__main__':
5
+ web_app()