PyOR — Python Operations Research Library
PyOR is a comprehensive, educational Operations Research library for Python.
It covers all major OR methods with clear docstrings, step-by-step output, and optional plots.
📦 Installation
pip install PyOR
# With plotting support
pip install PyOR[plot]
🗂️ Modules & Methods
| # | Method | Class / Function |
|---|---|---|
| 1 | Linear Programming Formulation | LinearProgram |
| 2 | Graphical Method | GraphicalMethod |
| 3 | Simplex Method | SimplexMethod |
| 4 | Dual Simplex Method | DualSimplex |
| 5 | Big-M Method | BigMMethod |
| 6 | Transportation — North-West Corner | north_west_corner() |
| 7 | Transportation — Least Cost | least_cost_method() |
| 8 | Transportation — Vogel's Approximation | vogel_approximation() |
| 9 | Transportation — MODI (Optimality) | modi_method() |
| 10 | Assignment Problem | AssignmentProblem |
| 11 | Project Management (PERT / CPM) | PERTCPMNetwork |
| 12 | Curve Fitting — Least Squares | CurveFitter |
| 13 | Cubic Spline Interpolation | CubicSplineFitter |
| 14 | Game Theory (saddle, 2x2, graphical, LP) — new in 1.1.0 | pyOR.game_theory() · solvers.game_theory |
| 15 | Queueing theory M/M/1, M/M/k (Erlang-C vs simulation) — new | pyOR.q_theory() · solvers.q_theory |
| 16 | Airport queue simulation & staffing optimisation — new | pyOR.q_simul() · solvers.q_simul |
| 17 | Gradient descent, Newton, BFGS — new | pyOR.gradient_methods() · solvers.gradient_methods |
| 18 | Multi-stage resource allocation (DP) — new | pyOR.dynamic_programming() · solvers.dynamic_programming |
New in 1.1.x — lab code printers
Calling any of these prints the complete lab code (copied exactly from the lab scripts):
import pyOR
pyOR.game_theory() # Lab 1 - Game theory
pyOR.q_theory() # Lab 2 - M/M/1, M/M/k queue simulation vs theory
pyOR.q_simul() # Lab 4 - Airport check-in simulation
pyOR.gradient_methods() # Lab 6 - Gradient descent, Newton, BFGS
pyOR.dynamic_programming() # Lab 10 - Multi-stage resource allocation (DP)
pyOR.list_labs()
The same methods are importable and runnable from pyOR.solvers:
from pyOR.solvers import q_theory
q_theory.compare_mmc() # run it
q_theory.code() # print this module's own source
🚀 Quick Examples
1. Linear Programming
from pyOR import LinearProgram
lp = LinearProgram(
c = [-3, -5], # maximise 3x₁ + 5x₂
A_ub = [[1,0],[0,2],[3,2]],
b_ub = [4, 12, 18],
objective = 'max'
)
result = lp.solve()
lp.display()
# → x1=2, x2=6, Z*=36
2. Graphical Method
from pyOR import GraphicalMethod
gm = GraphicalMethod(
c = [3, 5],
constraints = [(1, 0, '<=', 4),
(0, 2, '<=', 12),
(3, 2, '<=', 18)],
objective = 'max'
)
result = gm.solve()
gm.display()
gm.plot() # requires matplotlib
3. Simplex Method
from pyOR import SimplexMethod
sm = SimplexMethod(
c = [5, 4, 3],
A = [[6,4,2],[3,2,5],[5,6,5]],
b = [240, 270, 420],
objective = 'max'
)
result = sm.solve()
sm.display(show_tableaux=True)
4. Dual Simplex Method
from pyOR import DualSimplex
ds = DualSimplex(
c = [2, 3],
A = [[1,1],[1,0],[0,1]],
b = [4, 2, 3],
senses = ['<=','<=','<='],
objective= 'min'
)
ds.solve()
ds.display()
5. Big-M Method
from pyOR import BigMMethod
bm = BigMMethod(
c = [2, 3],
A = [[1,1],[1,0],[0,1]],
b = [4, 2, 3],
senses = ['<=','>=','>='],
objective= 'min'
)
bm.solve()
bm.display()
6–9. Transportation Problem
from pyOR import north_west_corner, least_cost_method, vogel_approximation, modi_method
cost = [[2, 3, 1], [5, 4, 8], [5, 6, 8]]
supply = [120, 80, 80]
demand = [150, 70, 60]
# Initial BFS methods
north_west_corner(cost, supply, demand)
least_cost_method(cost, supply, demand)
vogel_approximation(cost, supply, demand)
# Optimal solution using MODI
result = modi_method(cost, supply, demand, initial_method='vam')
print("Optimal Cost:", result['total_cost'])
10. Assignment Problem
from pyOR import AssignmentProblem
ap = AssignmentProblem(
cost_matrix = [[9,2,7,8],
[6,4,3,7],
[5,8,1,8],
[7,6,9,4]],
objective = 'min',
row_names = ['Worker A','Worker B','Worker C','Worker D'],
col_names = ['Job 1','Job 2','Job 3','Job 4']
)
ap.solve()
ap.display()
11. PERT / CPM
from pyOR import PERTCPMNetwork
# CPM
activities = [
{'name':'A','depends':[], 'duration':4},
{'name':'B','depends':[], 'duration':5},
{'name':'C','depends':['A'], 'duration':3},
{'name':'D','depends':['B'], 'duration':4},
{'name':'E','depends':['C','D'],'duration':6},
]
net = PERTCPMNetwork(activities)
net.solve()
net.display()
# PERT with probability
activities_pert = [
{'name':'A','depends':[],'optimistic':2,'most_likely':4,'pessimistic':6},
{'name':'B','depends':['A'],'optimistic':3,'most_likely':5,'pessimistic':9},
]
net2 = PERTCPMNetwork(activities_pert)
net2.solve()
net2.display(show_probability=15)
print(net2.completion_probability(15))
12. Curve Fitting
from pyOR import CurveFitter
cf = CurveFitter(x=[1,2,3,4,5], y=[2.1,3.9,6.1,8.1,10.1])
# Linear
cf.fit('linear')
cf.display()
cf.plot()
# Polynomial degree 2
cf.fit('polynomial', degree=2)
cf.display()
# Exponential, Power, Logarithmic, Reciprocal
for model in ['exponential', 'power', 'logarithmic', 'reciprocal']:
cf.fit(model)
print(f"{model}: R² = {cf.result['r_squared']:.4f}")
13. Cubic Spline
from pyOR import CubicSplineFitter
sf = CubicSplineFitter(
x=[0, 1, 2, 3, 4],
y=[0, 1, 0, 1, 0],
bc_type='natural'
)
sf.fit()
sf.display()
# Evaluate at a point
y_val = sf.evaluate(1.5)
dy = sf.derivative(1.5, order=1)
print(f"S(1.5) = {y_val}, S'(1.5) = {dy}")
sf.plot()
📐 Dependencies
| Package | Version |
|---|---|
| numpy | ≥ 1.21 |
| scipy | ≥ 1.7 |
| matplotlib | ≥ 3.4 (optional, for plots) |
🧪 Running Tests
pip install PyOR[dev]
pytest tests/ -v
📜 License
MIT © 2025 PyOR Contributors
Metadata
Release files for PyOR 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyor-1.1.2.tar.gz | 48.1 kB | Without provenance | Details for pyor-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyor-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for pyor-1.1.2-py3-none-any.whl |
Total release size: 104.1 kB
Release files / pyor-1.1.2.tar.gz
| Download URL | pyor-1.1.2.tar.gz |
|---|---|
| Size | 48.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17447768167cbfc8143435a927f23c621b7913d66b5c2e4d9d98092dd31c613a
|
|
BLAKE2b-256 checksum How to use checksums |
b63f7376c7db41d36a0c323c061569cb85ccfaf41bfcbe13255ee799ce81e2ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.2
|
Release files / pyor-1.1.2-py3-none-any.whl
| Download URL | pyor-1.1.2-py3-none-any.whl |
|---|---|
| Size | 56.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e196dad3353ccae2e9b2d49fd80d93934ba5a1c3cee6425fe8c57e8a09e9fc90
|
|
BLAKE2b-256 checksum How to use checksums |
b3028f0d1fd1ce23b271a67e54908dfcd8e05dc34c3d807307d58f2433d62bcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.2
|
Security for PyOR 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.