Metadata-Version: 2.4
Name: PyOR
Version: 1.0.0
Summary: Python Operations Research — LP, Simplex, Transportation, Assignment, PERT/CPM, Curve Fitting & more
Author: PyOR Contributors
License: MIT License
        
        Copyright (c) 2025 PyOR Contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/PyOR-dev/PyOR
Project-URL: Documentation, https://github.com/PyOR-dev/PyOR#readme
Project-URL: Issues, https://github.com/PyOR-dev/PyOR/issues
Keywords: operations research,linear programming,simplex,transportation,assignment,PERT,CPM,curve fitting,spline,optimization
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Education
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.21
Requires-Dist: scipy>=1.7
Provides-Extra: plot
Requires-Dist: matplotlib>=3.4; extra == "plot"
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: matplotlib>=3.4; extra == "dev"
Requires-Dist: twine; extra == "dev"
Requires-Dist: build; extra == "dev"
Dynamic: license-file
Dynamic: requires-python

# PyOR — Python Operations Research Library

[![PyPI version](https://img.shields.io/pypi/v/PyOR.svg)](https://pypi.org/project/PyOR/)
[![Python](https://img.shields.io/pypi/pyversions/PyOR.svg)](https://pypi.org/project/PyOR/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

**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

```bash
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

```python
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

```python
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

```python
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

```python
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

```python
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

```python
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

```python
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

```python
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

```python
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

```python
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

```bash
pip install PyOR[dev]
pytest tests/ -v
```

---

## 📜 License

MIT © 2025 PyOR Contributors
