PyOR 1.1.0__tar.gz → 1.1.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.
Files changed (36) hide show
  1. {pyor-1.1.0 → pyor-1.1.1}/PKG-INFO +333 -398
  2. {pyor-1.1.0 → pyor-1.1.1}/PyOR.egg-info/PKG-INFO +333 -398
  3. {pyor-1.1.0 → pyor-1.1.1}/PyOR.egg-info/SOURCES.txt +3 -2
  4. {pyor-1.1.0 → pyor-1.1.1}/README.md +20 -85
  5. {pyor-1.1.0 → pyor-1.1.1}/pyOR/__init__.py +44 -38
  6. pyor-1.1.1/pyOR/_utils.py +45 -0
  7. pyor-1.1.1/pyOR/dynamic_programming.py +150 -0
  8. pyor-1.1.1/pyOR/game_theory.py +220 -0
  9. pyor-1.1.1/pyOR/gradient_methods.py +147 -0
  10. pyor-1.1.1/pyOR/q_simul.py +152 -0
  11. pyor-1.1.1/pyOR/q_theory.py +124 -0
  12. {pyor-1.1.0 → pyor-1.1.1}/pyproject.toml +3 -4
  13. {pyor-1.1.0 → pyor-1.1.1}/setup.cfg +4 -4
  14. {pyor-1.1.0 → pyor-1.1.1}/setup.py +1 -1
  15. pyor-1.1.1/tests/test_lab_modules.py +54 -0
  16. pyor-1.1.0/pyOR/dynamic_programming.py +0 -215
  17. pyor-1.1.0/pyOR/game_theory.py +0 -353
  18. pyor-1.1.0/pyOR/q_simul.py +0 -359
  19. pyor-1.1.0/pyOR/q_theory.py +0 -297
  20. pyor-1.1.0/pyOR/unconstrained_opt.py +0 -233
  21. pyor-1.1.0/tests/test_new_modules.py +0 -100
  22. {pyor-1.1.0 → pyor-1.1.1}/LICENSE +0 -0
  23. {pyor-1.1.0 → pyor-1.1.1}/MANIFEST.in +0 -0
  24. {pyor-1.1.0 → pyor-1.1.1}/PyOR.egg-info/dependency_links.txt +0 -0
  25. {pyor-1.1.0 → pyor-1.1.1}/PyOR.egg-info/requires.txt +0 -0
  26. {pyor-1.1.0 → pyor-1.1.1}/PyOR.egg-info/top_level.txt +0 -0
  27. {pyor-1.1.0 → pyor-1.1.1}/pyOR/assignment.py +0 -0
  28. {pyor-1.1.0 → pyor-1.1.1}/pyOR/big_m.py +0 -0
  29. {pyor-1.1.0 → pyor-1.1.1}/pyOR/curve_fitting.py +0 -0
  30. {pyor-1.1.0 → pyor-1.1.1}/pyOR/dual_simplex.py +0 -0
  31. {pyor-1.1.0 → pyor-1.1.1}/pyOR/graphical_method.py +0 -0
  32. {pyor-1.1.0 → pyor-1.1.1}/pyOR/linear_programming.py +0 -0
  33. {pyor-1.1.0 → pyor-1.1.1}/pyOR/project_management.py +0 -0
  34. {pyor-1.1.0 → pyor-1.1.1}/pyOR/simplex.py +0 -0
  35. {pyor-1.1.0 → pyor-1.1.1}/pyOR/spline_fitting.py +0 -0
  36. {pyor-1.1.0 → pyor-1.1.1}/pyOR/transportation.py +0 -0
@@ -1,398 +1,333 @@
1
- Metadata-Version: 2.4
2
- Name: PyOR
3
- Version: 1.1.0
4
- Summary: Python Operations Research — LP, Simplex, Transportation, Assignment, PERT/CPM, Game Theory, Queueing, Simulation, Optimisation, DP & more
5
- Author: PyOR Contributors
6
- License: MIT License
7
-
8
- Copyright (c) 2025 PyOR Contributors
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
- SOFTWARE.
27
-
28
- Project-URL: Homepage, https://github.com/PyOR-dev/PyOR
29
- Project-URL: Documentation, https://github.com/PyOR-dev/PyOR#readme
30
- Project-URL: Issues, https://github.com/PyOR-dev/PyOR/issues
31
- Keywords: operations research,linear programming,simplex,transportation,assignment,PERT,CPM,curve fitting,spline,optimization,game theory,queueing theory,simulation,dynamic programming,gradient descent,BFGS
32
- Classifier: Development Status :: 4 - Beta
33
- Classifier: Intended Audience :: Science/Research
34
- Classifier: Intended Audience :: Education
35
- Classifier: Topic :: Scientific/Engineering :: Mathematics
36
- Classifier: License :: OSI Approved :: MIT License
37
- Classifier: Programming Language :: Python :: 3
38
- Classifier: Programming Language :: Python :: 3.8
39
- Classifier: Programming Language :: Python :: 3.9
40
- Classifier: Programming Language :: Python :: 3.10
41
- Classifier: Programming Language :: Python :: 3.11
42
- Classifier: Programming Language :: Python :: 3.12
43
- Requires-Python: >=3.8
44
- Description-Content-Type: text/markdown
45
- License-File: LICENSE
46
- Requires-Dist: numpy>=1.21
47
- Requires-Dist: scipy>=1.7
48
- Provides-Extra: plot
49
- Requires-Dist: matplotlib>=3.4; extra == "plot"
50
- Provides-Extra: dev
51
- Requires-Dist: pytest>=7; extra == "dev"
52
- Requires-Dist: pytest-cov; extra == "dev"
53
- Requires-Dist: matplotlib>=3.4; extra == "dev"
54
- Requires-Dist: twine; extra == "dev"
55
- Requires-Dist: build; extra == "dev"
56
- Dynamic: license-file
57
- Dynamic: requires-python
58
-
59
- # PyOR — Python Operations Research Library
60
-
61
- [![PyPI version](https://img.shields.io/pypi/v/PyOR.svg)](https://pypi.org/project/PyOR/)
62
- [![Python](https://img.shields.io/pypi/pyversions/PyOR.svg)](https://pypi.org/project/PyOR/)
63
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
64
-
65
- **PyOR** is a comprehensive, educational Operations Research library for Python.
66
- It covers all major OR methods with clear docstrings, step-by-step output, and optional plots.
67
-
68
- ---
69
-
70
- ## 📦 Installation
71
-
72
- ```bash
73
- pip install PyOR
74
- # With plotting support
75
- pip install PyOR[plot]
76
- ```
77
-
78
- ---
79
-
80
- ## 🆕 What's new in 1.1.0
81
-
82
- New modules: `game_theory`, `q_theory`, `q_simul`, `unconstrained_opt`, `dynamic_programming`.
83
-
84
- ---
85
-
86
- ## 🗂️ Modules & Methods
87
-
88
- | # | Method | Class / Function |
89
- |---|--------|-----------------|
90
- | 1 | Linear Programming Formulation | `LinearProgram` |
91
- | 2 | Graphical Method | `GraphicalMethod` |
92
- | 3 | Simplex Method | `SimplexMethod` |
93
- | 4 | Dual Simplex Method | `DualSimplex` |
94
- | 5 | Big-M Method | `BigMMethod` |
95
- | 6 | Transportation — North-West Corner | `north_west_corner()` |
96
- | 7 | Transportation — Least Cost | `least_cost_method()` |
97
- | 8 | Transportation — Vogel's Approximation | `vogel_approximation()` |
98
- | 9 | Transportation — MODI (Optimality) | `modi_method()` |
99
- | 10 | Assignment Problem | `AssignmentProblem` |
100
- | 11 | Project Management (PERT / CPM) | `PERTCPMNetwork` |
101
- | 12 | Curve Fitting — Least Squares | `CurveFitter` |
102
- | 13 | Cubic Spline Interpolation | `CubicSplineFitter` |
103
- | 14 | Game Theory (saddle, 2x2, graphical, LP) | `GameTheory` — `pyOR.game_theory` |
104
- | 15 | Queueing Theory (analytical) | `QueueModel`, `erlang_b`, `erlang_c`, `min_servers`, `optimal_servers` — `pyOR.q_theory` |
105
- | 16 | Queue Simulation (M/M/c, airport counters) | `MMcSimulation`, `AirportSimulation` — `pyOR.q_simul` |
106
- | 17 | Unconstrained Optimisation (GD, Newton, BFGS) | `UnconstrainedOptimizer` — `pyOR.unconstrained_opt` |
107
- | 18 | Dynamic Programming (resource allocation) | `ResourceAllocation` — `pyOR.dynamic_programming` |
108
-
109
- ---
110
-
111
- ## 🚀 Quick Examples
112
-
113
- ### 1. Linear Programming
114
-
115
- ```python
116
- from pyOR import LinearProgram
117
-
118
- lp = LinearProgram(
119
- c = [-3, -5], # maximise 3x₁ + 5x₂
120
- A_ub = [[1,0],[0,2],[3,2]],
121
- b_ub = [4, 12, 18],
122
- objective = 'max'
123
- )
124
- result = lp.solve()
125
- lp.display()
126
- # → x1=2, x2=6, Z*=36
127
- ```
128
-
129
- ### 2. Graphical Method
130
-
131
- ```python
132
- from pyOR import GraphicalMethod
133
-
134
- gm = GraphicalMethod(
135
- c = [3, 5],
136
- constraints = [(1, 0, '<=', 4),
137
- (0, 2, '<=', 12),
138
- (3, 2, '<=', 18)],
139
- objective = 'max'
140
- )
141
- result = gm.solve()
142
- gm.display()
143
- gm.plot() # requires matplotlib
144
- ```
145
-
146
- ### 3. Simplex Method
147
-
148
- ```python
149
- from pyOR import SimplexMethod
150
-
151
- sm = SimplexMethod(
152
- c = [5, 4, 3],
153
- A = [[6,4,2],[3,2,5],[5,6,5]],
154
- b = [240, 270, 420],
155
- objective = 'max'
156
- )
157
- result = sm.solve()
158
- sm.display(show_tableaux=True)
159
- ```
160
-
161
- ### 4. Dual Simplex Method
162
-
163
- ```python
164
- from pyOR import DualSimplex
165
-
166
- ds = DualSimplex(
167
- c = [2, 3],
168
- A = [[1,1],[1,0],[0,1]],
169
- b = [4, 2, 3],
170
- senses = ['<=','<=','<='],
171
- objective= 'min'
172
- )
173
- ds.solve()
174
- ds.display()
175
- ```
176
-
177
- ### 5. Big-M Method
178
-
179
- ```python
180
- from pyOR import BigMMethod
181
-
182
- bm = BigMMethod(
183
- c = [2, 3],
184
- A = [[1,1],[1,0],[0,1]],
185
- b = [4, 2, 3],
186
- senses = ['<=','>=','>='],
187
- objective= 'min'
188
- )
189
- bm.solve()
190
- bm.display()
191
- ```
192
-
193
- ### 6–9. Transportation Problem
194
-
195
- ```python
196
- from pyOR import north_west_corner, least_cost_method, vogel_approximation, modi_method
197
-
198
- cost = [[2, 3, 1], [5, 4, 8], [5, 6, 8]]
199
- supply = [120, 80, 80]
200
- demand = [150, 70, 60]
201
-
202
- # Initial BFS methods
203
- north_west_corner(cost, supply, demand)
204
- least_cost_method(cost, supply, demand)
205
- vogel_approximation(cost, supply, demand)
206
-
207
- # Optimal solution using MODI
208
- result = modi_method(cost, supply, demand, initial_method='vam')
209
- print("Optimal Cost:", result['total_cost'])
210
- ```
211
-
212
- ### 10. Assignment Problem
213
-
214
- ```python
215
- from pyOR import AssignmentProblem
216
-
217
- ap = AssignmentProblem(
218
- cost_matrix = [[9,2,7,8],
219
- [6,4,3,7],
220
- [5,8,1,8],
221
- [7,6,9,4]],
222
- objective = 'min',
223
- row_names = ['Worker A','Worker B','Worker C','Worker D'],
224
- col_names = ['Job 1','Job 2','Job 3','Job 4']
225
- )
226
- ap.solve()
227
- ap.display()
228
- ```
229
-
230
- ### 11. PERT / CPM
231
-
232
- ```python
233
- from pyOR import PERTCPMNetwork
234
-
235
- # CPM
236
- activities = [
237
- {'name':'A','depends':[], 'duration':4},
238
- {'name':'B','depends':[], 'duration':5},
239
- {'name':'C','depends':['A'], 'duration':3},
240
- {'name':'D','depends':['B'], 'duration':4},
241
- {'name':'E','depends':['C','D'],'duration':6},
242
- ]
243
- net = PERTCPMNetwork(activities)
244
- net.solve()
245
- net.display()
246
-
247
- # PERT with probability
248
- activities_pert = [
249
- {'name':'A','depends':[],'optimistic':2,'most_likely':4,'pessimistic':6},
250
- {'name':'B','depends':['A'],'optimistic':3,'most_likely':5,'pessimistic':9},
251
- ]
252
- net2 = PERTCPMNetwork(activities_pert)
253
- net2.solve()
254
- net2.display(show_probability=15)
255
- print(net2.completion_probability(15))
256
- ```
257
-
258
- ### 12. Curve Fitting
259
-
260
- ```python
261
- from pyOR import CurveFitter
262
-
263
- cf = CurveFitter(x=[1,2,3,4,5], y=[2.1,3.9,6.1,8.1,10.1])
264
-
265
- # Linear
266
- cf.fit('linear')
267
- cf.display()
268
- cf.plot()
269
-
270
- # Polynomial degree 2
271
- cf.fit('polynomial', degree=2)
272
- cf.display()
273
-
274
- # Exponential, Power, Logarithmic, Reciprocal
275
- for model in ['exponential', 'power', 'logarithmic', 'reciprocal']:
276
- cf.fit(model)
277
- print(f"{model}: R² = {cf.result['r_squared']:.4f}")
278
- ```
279
-
280
- ### 13. Cubic Spline
281
-
282
- ```python
283
- from pyOR import CubicSplineFitter
284
-
285
- sf = CubicSplineFitter(
286
- x=[0, 1, 2, 3, 4],
287
- y=[0, 1, 0, 1, 0],
288
- bc_type='natural'
289
- )
290
- sf.fit()
291
- sf.display()
292
-
293
- # Evaluate at a point
294
- y_val = sf.evaluate(1.5)
295
- dy = sf.derivative(1.5, order=1)
296
- print(f"S(1.5) = {y_val}, S'(1.5) = {dy}")
297
-
298
- sf.plot()
299
- ```
300
-
301
- ### 14. Game Theory
302
-
303
- ```python
304
- from pyOR import GameTheory
305
-
306
- g = GameTheory([[3, -1], [-2, 4]])
307
- g.solve() # auto: saddle -> 2x2 formula -> graphical -> LP
308
- g.display() # p=(0.6, 0.4), q=(0.5, 0.5), value = 1
309
-
310
- g = GameTheory([[1, 3, 11], [8, 5, 2]])
311
- g.solve(method='graphical'); g.plot()
312
-
313
- GameTheory([[3,-1,-3],[-2,4,-1],[-5,-6,2]]).solve(method='lp')
314
- ```
315
-
316
- ### 15. Queueing Theory
317
-
318
- ```python
319
- from pyOR import QueueModel, optimal_servers, min_servers
320
-
321
- QueueModel('M/M/1', lam=8, mu=10).display() # Wq = 0.4, Lq = 3.2
322
- QueueModel('M/M/c', lam=24, mu=10, c=3).solve() # Erlang-C
323
- QueueModel('M/M/c/K', lam=12, mu=10, c=2, K=10).solve()['p_block']
324
- QueueModel('M/G/1', lam=8, mu=10, service_var=0.01).solve()
325
-
326
- min_servers(24, 10, max_Wq=0.05) # smallest c meeting a target
327
- optimal_servers(24, 10, cost_server=50, cost_wait=10)['best_c']
328
- ```
329
-
330
- ### 16. Queue Simulation
331
-
332
- ```python
333
- from pyOR import MMcSimulation, AirportSimulation
334
-
335
- MMcSimulation(lam=8, mu=10, c=1).display() # simulation vs theory
336
- MMcSimulation.compare([("M/M/1", 8, 10, 1), ("M/M/2", 16, 10, 2)])
337
- MMcSimulation.plot_utilisation()
338
-
339
- ap = AirportSimulation(lam=1.0, svc_mean=4.0, cap=25, patience=12)
340
- ap.optimise(k_values=range(2, 11), reps=20,
341
- cost_counter=160, cost_wait=0.5, cost_lost=30)
342
- ap.display(); ap.plot() # blocking, balking, reneging
343
- ```
344
-
345
- ### 17. Unconstrained Optimisation
346
-
347
- ```python
348
- from pyOR import UnconstrainedOptimizer, rosenbrock
349
-
350
- f, grad, hess, x0 = rosenbrock()
351
- opt = UnconstrainedOptimizer(f, x0, grad=grad, hess=hess)
352
- opt.compare() # gradient descent vs Newton vs BFGS
353
- opt.plot_convergence()
354
-
355
- # gradient / Hessian optional (finite differences are used)
356
- UnconstrainedOptimizer(lambda x: (x[0]-3)**2 + (x[1]+1)**2, [0, 0]).solve('bfgs')
357
- ```
358
-
359
- ### 18. Dynamic Programming — Resource Allocation
360
-
361
- ```python
362
- from pyOR import ResourceAllocation
363
-
364
- r = [[0,5,9,12,14,15,15],
365
- [0,4,8,11,13,14,14],
366
- [0,6,10,13,15,16,16],
367
- [0,3,7,10,12,13,13]]
368
- ra = ResourceAllocation(r) # 6 units, 4 activities
369
- ra.solve(); ra.display() # allocation [2, 2, 2, 0], return 27
370
- ra.sensitivity() # optimal value for every budget
371
- ra.brute_force() # verification
372
- ra.plot_value(); ra.plot_policy()
373
- ```
374
-
375
- ---
376
-
377
- ## 📐 Dependencies
378
-
379
- | Package | Version |
380
- |---------|---------|
381
- | numpy | ≥ 1.21 |
382
- | scipy | ≥ 1.7 |
383
- | matplotlib | ≥ 3.4 (optional, for plots) |
384
-
385
- ---
386
-
387
- ## 🧪 Running Tests
388
-
389
- ```bash
390
- pip install PyOR[dev]
391
- pytest tests/ -v
392
- ```
393
-
394
- ---
395
-
396
- ## 📜 License
397
-
398
- MIT © 2025 PyOR Contributors
1
+ Metadata-Version: 2.4
2
+ Name: PyOR
3
+ Version: 1.1.1
4
+ Summary: Python Operations Research — LP, Simplex, Transportation, Assignment, PERT/CPM, Curve Fitting & more
5
+ Author: PyOR Contributors
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 PyOR Contributors
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/PyOR-dev/PyOR
29
+ Project-URL: Documentation, https://github.com/PyOR-dev/PyOR#readme
30
+ Project-URL: Issues, https://github.com/PyOR-dev/PyOR/issues
31
+ Keywords: operations research,linear programming,simplex,transportation,assignment,PERT,CPM,curve fitting,spline,optimization,game theory,queueing,simulation,dynamic programming,gradient descent
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: Intended Audience :: Education
35
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.8
39
+ Classifier: Programming Language :: Python :: 3.9
40
+ Classifier: Programming Language :: Python :: 3.10
41
+ Classifier: Programming Language :: Python :: 3.11
42
+ Classifier: Programming Language :: Python :: 3.12
43
+ Requires-Python: >=3.8
44
+ Description-Content-Type: text/markdown
45
+ License-File: LICENSE
46
+ Requires-Dist: numpy>=1.21
47
+ Requires-Dist: scipy>=1.7
48
+ Provides-Extra: plot
49
+ Requires-Dist: matplotlib>=3.4; extra == "plot"
50
+ Provides-Extra: dev
51
+ Requires-Dist: pytest>=7; extra == "dev"
52
+ Requires-Dist: pytest-cov; extra == "dev"
53
+ Requires-Dist: matplotlib>=3.4; extra == "dev"
54
+ Requires-Dist: twine; extra == "dev"
55
+ Requires-Dist: build; extra == "dev"
56
+ Dynamic: license-file
57
+ Dynamic: requires-python
58
+
59
+ # PyOR — Python Operations Research Library
60
+
61
+ [![PyPI version](https://img.shields.io/pypi/v/PyOR.svg)](https://pypi.org/project/PyOR/)
62
+ [![Python](https://img.shields.io/pypi/pyversions/PyOR.svg)](https://pypi.org/project/PyOR/)
63
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
64
+
65
+ **PyOR** is a comprehensive, educational Operations Research library for Python.
66
+ It covers all major OR methods with clear docstrings, step-by-step output, and optional plots.
67
+
68
+ ---
69
+
70
+ ## 📦 Installation
71
+
72
+ ```bash
73
+ pip install PyOR
74
+ # With plotting support
75
+ pip install PyOR[plot]
76
+ ```
77
+
78
+ ---
79
+
80
+ ## 🗂️ Modules & Methods
81
+
82
+ | # | Method | Class / Function |
83
+ |---|--------|-----------------|
84
+ | 1 | Linear Programming Formulation | `LinearProgram` |
85
+ | 2 | Graphical Method | `GraphicalMethod` |
86
+ | 3 | Simplex Method | `SimplexMethod` |
87
+ | 4 | Dual Simplex Method | `DualSimplex` |
88
+ | 5 | Big-M Method | `BigMMethod` |
89
+ | 6 | Transportation — North-West Corner | `north_west_corner()` |
90
+ | 7 | Transportation — Least Cost | `least_cost_method()` |
91
+ | 8 | Transportation — Vogel's Approximation | `vogel_approximation()` |
92
+ | 9 | Transportation — MODI (Optimality) | `modi_method()` |
93
+ | 10 | Assignment Problem | `AssignmentProblem` |
94
+ | 11 | Project Management (PERT / CPM) | `PERTCPMNetwork` |
95
+ | 12 | Curve Fitting — Least Squares | `CurveFitter` |
96
+ | 13 | Cubic Spline Interpolation | `CubicSplineFitter` |
97
+ | 14 | Game Theory (saddle, 2x2, graphical, LP) — *new in 1.1.0* | `pyOR.game_theory` · `MatrixGame` |
98
+ | 15 | Queueing theory M/M/1, M/M/k (Erlang-C vs simulation) — *new* | `pyOR.q_theory` |
99
+ | 16 | Airport queue simulation & staffing optimisation — *new* | `pyOR.q_simul` |
100
+ | 17 | Gradient descent, Newton, BFGS — *new* | `pyOR.gradient_methods` |
101
+ | 18 | Multi-stage resource allocation (DP) — *new* | `pyOR.dynamic_programming` · `ResourceAllocationDP` |
102
+
103
+ ### New in 1.1.0 — printing the complete code
104
+
105
+ Each new module has `demo()` (runs the lab example) and `code()` (prints the
106
+ module's complete source):
107
+
108
+ ```python
109
+ import pyOR
110
+ from pyOR import q_theory, q_simul, game_theory, gradient_methods, dynamic_programming
111
+
112
+ q_theory.demo() # run the M/M/k experiment
113
+ q_theory.code() # print the complete source code
114
+ pyOR.code("q_simul") # same thing, by name
115
+ pyOR.list_modules()
116
+ ```
117
+
118
+ ---
119
+
120
+ ## 🚀 Quick Examples
121
+
122
+ ### 1. Linear Programming
123
+
124
+ ```python
125
+ from pyOR import LinearProgram
126
+
127
+ lp = LinearProgram(
128
+ c = [-3, -5], # maximise 3x₁ + 5x₂
129
+ A_ub = [[1,0],[0,2],[3,2]],
130
+ b_ub = [4, 12, 18],
131
+ objective = 'max'
132
+ )
133
+ result = lp.solve()
134
+ lp.display()
135
+ # → x1=2, x2=6, Z*=36
136
+ ```
137
+
138
+ ### 2. Graphical Method
139
+
140
+ ```python
141
+ from pyOR import GraphicalMethod
142
+
143
+ gm = GraphicalMethod(
144
+ c = [3, 5],
145
+ constraints = [(1, 0, '<=', 4),
146
+ (0, 2, '<=', 12),
147
+ (3, 2, '<=', 18)],
148
+ objective = 'max'
149
+ )
150
+ result = gm.solve()
151
+ gm.display()
152
+ gm.plot() # requires matplotlib
153
+ ```
154
+
155
+ ### 3. Simplex Method
156
+
157
+ ```python
158
+ from pyOR import SimplexMethod
159
+
160
+ sm = SimplexMethod(
161
+ c = [5, 4, 3],
162
+ A = [[6,4,2],[3,2,5],[5,6,5]],
163
+ b = [240, 270, 420],
164
+ objective = 'max'
165
+ )
166
+ result = sm.solve()
167
+ sm.display(show_tableaux=True)
168
+ ```
169
+
170
+ ### 4. Dual Simplex Method
171
+
172
+ ```python
173
+ from pyOR import DualSimplex
174
+
175
+ ds = DualSimplex(
176
+ c = [2, 3],
177
+ A = [[1,1],[1,0],[0,1]],
178
+ b = [4, 2, 3],
179
+ senses = ['<=','<=','<='],
180
+ objective= 'min'
181
+ )
182
+ ds.solve()
183
+ ds.display()
184
+ ```
185
+
186
+ ### 5. Big-M Method
187
+
188
+ ```python
189
+ from pyOR import BigMMethod
190
+
191
+ bm = BigMMethod(
192
+ c = [2, 3],
193
+ A = [[1,1],[1,0],[0,1]],
194
+ b = [4, 2, 3],
195
+ senses = ['<=','>=','>='],
196
+ objective= 'min'
197
+ )
198
+ bm.solve()
199
+ bm.display()
200
+ ```
201
+
202
+ ### 6–9. Transportation Problem
203
+
204
+ ```python
205
+ from pyOR import north_west_corner, least_cost_method, vogel_approximation, modi_method
206
+
207
+ cost = [[2, 3, 1], [5, 4, 8], [5, 6, 8]]
208
+ supply = [120, 80, 80]
209
+ demand = [150, 70, 60]
210
+
211
+ # Initial BFS methods
212
+ north_west_corner(cost, supply, demand)
213
+ least_cost_method(cost, supply, demand)
214
+ vogel_approximation(cost, supply, demand)
215
+
216
+ # Optimal solution using MODI
217
+ result = modi_method(cost, supply, demand, initial_method='vam')
218
+ print("Optimal Cost:", result['total_cost'])
219
+ ```
220
+
221
+ ### 10. Assignment Problem
222
+
223
+ ```python
224
+ from pyOR import AssignmentProblem
225
+
226
+ ap = AssignmentProblem(
227
+ cost_matrix = [[9,2,7,8],
228
+ [6,4,3,7],
229
+ [5,8,1,8],
230
+ [7,6,9,4]],
231
+ objective = 'min',
232
+ row_names = ['Worker A','Worker B','Worker C','Worker D'],
233
+ col_names = ['Job 1','Job 2','Job 3','Job 4']
234
+ )
235
+ ap.solve()
236
+ ap.display()
237
+ ```
238
+
239
+ ### 11. PERT / CPM
240
+
241
+ ```python
242
+ from pyOR import PERTCPMNetwork
243
+
244
+ # CPM
245
+ activities = [
246
+ {'name':'A','depends':[], 'duration':4},
247
+ {'name':'B','depends':[], 'duration':5},
248
+ {'name':'C','depends':['A'], 'duration':3},
249
+ {'name':'D','depends':['B'], 'duration':4},
250
+ {'name':'E','depends':['C','D'],'duration':6},
251
+ ]
252
+ net = PERTCPMNetwork(activities)
253
+ net.solve()
254
+ net.display()
255
+
256
+ # PERT with probability
257
+ activities_pert = [
258
+ {'name':'A','depends':[],'optimistic':2,'most_likely':4,'pessimistic':6},
259
+ {'name':'B','depends':['A'],'optimistic':3,'most_likely':5,'pessimistic':9},
260
+ ]
261
+ net2 = PERTCPMNetwork(activities_pert)
262
+ net2.solve()
263
+ net2.display(show_probability=15)
264
+ print(net2.completion_probability(15))
265
+ ```
266
+
267
+ ### 12. Curve Fitting
268
+
269
+ ```python
270
+ from pyOR import CurveFitter
271
+
272
+ cf = CurveFitter(x=[1,2,3,4,5], y=[2.1,3.9,6.1,8.1,10.1])
273
+
274
+ # Linear
275
+ cf.fit('linear')
276
+ cf.display()
277
+ cf.plot()
278
+
279
+ # Polynomial degree 2
280
+ cf.fit('polynomial', degree=2)
281
+ cf.display()
282
+
283
+ # Exponential, Power, Logarithmic, Reciprocal
284
+ for model in ['exponential', 'power', 'logarithmic', 'reciprocal']:
285
+ cf.fit(model)
286
+ print(f"{model}: R² = {cf.result['r_squared']:.4f}")
287
+ ```
288
+
289
+ ### 13. Cubic Spline
290
+
291
+ ```python
292
+ from pyOR import CubicSplineFitter
293
+
294
+ sf = CubicSplineFitter(
295
+ x=[0, 1, 2, 3, 4],
296
+ y=[0, 1, 0, 1, 0],
297
+ bc_type='natural'
298
+ )
299
+ sf.fit()
300
+ sf.display()
301
+
302
+ # Evaluate at a point
303
+ y_val = sf.evaluate(1.5)
304
+ dy = sf.derivative(1.5, order=1)
305
+ print(f"S(1.5) = {y_val}, S'(1.5) = {dy}")
306
+
307
+ sf.plot()
308
+ ```
309
+
310
+ ---
311
+
312
+ ## 📐 Dependencies
313
+
314
+ | Package | Version |
315
+ |---------|---------|
316
+ | numpy | ≥ 1.21 |
317
+ | scipy | ≥ 1.7 |
318
+ | matplotlib | ≥ 3.4 (optional, for plots) |
319
+
320
+ ---
321
+
322
+ ## 🧪 Running Tests
323
+
324
+ ```bash
325
+ pip install PyOR[dev]
326
+ pytest tests/ -v
327
+ ```
328
+
329
+ ---
330
+
331
+ ## 📜 License
332
+
333
+ MIT © 2025 PyOR Contributors