Skip to main content

PyOR — Python Operations Research Library

PyPI version Python License: MIT

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 · MatrixGame
15 Queueing theory M/M/1, M/M/k (Erlang-C vs simulation) — new pyOR.q_theory
16 Airport queue simulation & staffing optimisation — new pyOR.q_simul
17 Gradient descent, Newton, BFGS — new pyOR.gradient_methods
18 Multi-stage resource allocation (DP) — new pyOR.dynamic_programming · ResourceAllocationDP

New in 1.1.0 — printing the complete code

Each new module has demo() (runs the lab example) and code() (prints the module's complete source):

import pyOR
from pyOR import q_theory, q_simul, game_theory, gradient_methods, dynamic_programming

q_theory.demo()          # run the M/M/k experiment
q_theory.code()          # print the complete source code
pyOR.code("q_simul")     # same thing, by name
pyOR.list_modules()

🚀 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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyOR 1.1.1
File Size Uploaded Provenance Actions
pyor-1.1.1.tar.gz 43.2 kB Without provenance Details for pyor-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PyOR 1.1.1
File Interpreter ABI Platform Actions
pyor-1.1.1-py3-none-any.whl Python 3 none any Details for pyor-1.1.1-py3-none-any.whl

Total release size: 93.5 kB

Release files / pyor-1.1.1.tar.gz

Download URL pyor-1.1.1.tar.gz
Size 43.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f308239538c9a6a72ef7cc472ea82926e92b2c0e51357628e05a407dc565a36c
BLAKE2b-256 checksum
How to use checksums
762bee1687b68316afb5263e596d13c8edd71d5d16403a666bbf43c82f277d3f
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.1-py3-none-any.whl

Download URL pyor-1.1.1-py3-none-any.whl
Size 50.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fecdb55fcad28823fd4c87b9839367a1ff11f975d46bac50efa3ec281b47af88
BLAKE2b-256 checksum
How to use checksums
37b528d26f2b20dd8b5764c4ab2ddc0beeef9f465a3e8f9875742872293b7292
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.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page