Skip to main content

Python Operations Research — LP, Simplex, Transportation, Assignment, PERT/CPM, Curve Fitting & more

Project description

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

🚀 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyor-1.0.0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyor-1.0.0-py3-none-any.whl (38.0 kB view details)

Uploaded Python 3

File details

Details for the file pyor-1.0.0.tar.gz.

File metadata

  • Download URL: pyor-1.0.0.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc2

File hashes

Hashes for pyor-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b36e93dd5a72b08924ab88453981b946b8db283f272c912b6963630a1ca395c1
MD5 2962d3363b5bceb64abc8808cef03dff
BLAKE2b-256 bee7c419bde71f19d591391805e900c999b8b3583d4aef05203338b7617dd475

See more details on using hashes here.

File details

Details for the file pyor-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyor-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 38.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc2

File hashes

Hashes for pyor-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6cfe6fa8f0077b185f99b65172e97421a9d44c5494953d9333d7f4f5f2c8b55
MD5 2853510af6d5441a1c534e5d1c76949a
BLAKE2b-256 e6a84a4f77fc2bf3b1d2f17422a4b1fb2fac63a50189e8621cc009210cacfebd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page