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]

🆕 What's new in 1.1.0

New modules: game_theory, q_theory, q_simul, unconstrained_opt, dynamic_programming.


🗂️ 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) GameTheory — pyOR.game_theory
15 Queueing Theory (analytical) QueueModel, erlang_b, erlang_c, min_servers, optimal_servers — pyOR.q_theory
16 Queue Simulation (M/M/c, airport counters) MMcSimulation, AirportSimulation — pyOR.q_simul
17 Unconstrained Optimisation (GD, Newton, BFGS) UnconstrainedOptimizer — pyOR.unconstrained_opt
18 Dynamic Programming (resource allocation) ResourceAllocation — pyOR.dynamic_programming

🚀 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()

14. Game Theory

from pyOR import GameTheory

g = GameTheory([[3, -1], [-2, 4]])
g.solve()                 # auto: saddle -> 2x2 formula -> graphical -> LP
g.display()               # p=(0.6, 0.4), q=(0.5, 0.5), value = 1

g = GameTheory([[1, 3, 11], [8, 5, 2]])
g.solve(method='graphical'); g.plot()

GameTheory([[3,-1,-3],[-2,4,-1],[-5,-6,2]]).solve(method='lp')

15. Queueing Theory

from pyOR import QueueModel, optimal_servers, min_servers

QueueModel('M/M/1', lam=8, mu=10).display()          # Wq = 0.4, Lq = 3.2
QueueModel('M/M/c', lam=24, mu=10, c=3).solve()      # Erlang-C
QueueModel('M/M/c/K', lam=12, mu=10, c=2, K=10).solve()['p_block']
QueueModel('M/G/1', lam=8, mu=10, service_var=0.01).solve()

min_servers(24, 10, max_Wq=0.05)                      # smallest c meeting a target
optimal_servers(24, 10, cost_server=50, cost_wait=10)['best_c']

16. Queue Simulation

from pyOR import MMcSimulation, AirportSimulation

MMcSimulation(lam=8, mu=10, c=1).display()           # simulation vs theory
MMcSimulation.compare([("M/M/1", 8, 10, 1), ("M/M/2", 16, 10, 2)])
MMcSimulation.plot_utilisation()

ap = AirportSimulation(lam=1.0, svc_mean=4.0, cap=25, patience=12)
ap.optimise(k_values=range(2, 11), reps=20,
            cost_counter=160, cost_wait=0.5, cost_lost=30)
ap.display(); ap.plot()                               # blocking, balking, reneging

17. Unconstrained Optimisation

from pyOR import UnconstrainedOptimizer, rosenbrock

f, grad, hess, x0 = rosenbrock()
opt = UnconstrainedOptimizer(f, x0, grad=grad, hess=hess)
opt.compare()                 # gradient descent vs Newton vs BFGS
opt.plot_convergence()

# gradient / Hessian optional (finite differences are used)
UnconstrainedOptimizer(lambda x: (x[0]-3)**2 + (x[1]+1)**2, [0, 0]).solve('bfgs')

18. Dynamic Programming — Resource Allocation

from pyOR import ResourceAllocation

r = [[0,5,9,12,14,15,15],
     [0,4,8,11,13,14,14],
     [0,6,10,13,15,16,16],
     [0,3,7,10,12,13,13]]
ra = ResourceAllocation(r)            # 6 units, 4 activities
ra.solve(); ra.display()              # allocation [2, 2, 2, 0], return 27
ra.sensitivity()                      # optimal value for every budget
ra.brute_force()                      # verification
ra.plot_value(); ra.plot_policy()

📐 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.0

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.0
File Size Uploaded Provenance Actions
pyor-1.1.0.tar.gz 50.6 kB Without provenance Details for pyor-1.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 109.9 kB

Release files / pyor-1.1.0.tar.gz

Download URL pyor-1.1.0.tar.gz
Size 50.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bb1423f65b5c11243ca0739b0888a796edcb0744e751fa3e857775f8544a393c
BLAKE2b-256 checksum
How to use checksums
8d04199a5a1b69bba2e351299990938153fe0da79064d73d24186eff526d0794
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.0-py3-none-any.whl

Download URL pyor-1.1.0-py3-none-any.whl
Size 59.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4330bc0928ecda001a1510c66d9b1f442736ab78d53d5a7ca8a5295c837d0ba4
BLAKE2b-256 checksum
How to use checksums
69323ff9aa0b3fa80958d851a31abb0bbae380dc51e89fad20e85cbdad4be38d
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.0

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