A Python package for Linear Programming and Transportation Problems
Project description
Linear Programming Solver
A Python library for solving linear programming problems using various methods including graphical solutions, simplex method, and transportation problems.
Features
-
Linear Programming Solutions:
- Graphical Method (2D and 3D visualization)
- Simplex Method
- Big M Method for problems with ≥ and = constraints
- Integer Programming using Branch and Bound
-
Transportation Problem Solutions:
- North-West Corner Rule (NWCR)
- Vogel's Approximation Method (VAM)
- Least Cost Method (LCM)
- Modified Distribution Method (MODI)
Installation
pip install OTTools
Usage
Linear Programming
Graphical Method (2-Variable)
from OTTools import graphical_method
# Maximize Z = 3x₁ + 2x₂
# Subject to:
# 2x₁ + x₂ ≤ 8
# x₁ + 2x₂ ≤ 6
# x₁, x₂ ≥ 0
c = [3, 2] # Coefficients of objective function
A = [[2, 1], [1, 2]] # Coefficients of constraints
b = [8, 6] # Right-hand side values
graphical_method(c, A, b) # Visualizes the solution
Simplex Method
from OTTools import simplex_method
# Maximize Z = 3x₁ + 2x₂
# Subject to:
# 2x₁ + x₂ ≤ 8
# x₁ + 2x₂ ≤ 6
# x₁, x₂ ≥ 0
c = [3, 2]
A = [[2, 1], [1, 2]]
b = [8, 6]
optimal_value, solution = simplex_method(c, A, b)
print(f"Optimal value: {optimal_value}")
print(f"Solution: {solution}")
Big M Method (for mixed constraints)
from OTTools import big_m_method
# Maximize Z = 2x₁ + 3x₂
# Subject to:
# x₁ + x₂ ≤ 6
# x₁ + 2x₂ ≥ 8
# x₁ + x₂ = 5
# x₁, x₂ ≥ 0
c = [2, 3]
A = [[1, 1], [1, 2], [1, 1]]
b = [6, 8, 5]
constraint_types = ['<=', '>=', '=']
optimal_value, solution = big_m_method(c, A, b, constraint_types, Min=False)
print(f"Optimal value: {optimal_value}")
print(f"Solution: {solution}")
Big M Method (Minimization Example)
from OTTools import big_m_method
# Minimize Z = 4x₁ + 2x₂
# Subject to:
# 3x₁ + x₂ ≥ 15
# x₁ + 2x₂ ≤ 20
# x₁ + x₂ = 10
# x₁, x₂ ≥ 0
c = [4, 2]
A = [[3, 1], [1, 2], [1, 1]]
b = [15, 20, 10]
constraint_types = ['>=', '<=', '=']
# Set Min=True for minimization
optimal_value, solution = big_m_method(c, A, b, constraint_types, Min=True)
print(f"Minimum value: {optimal_value}")
print(f"Solution: x₁ = {solution[0]}, x₂ = {solution[1]}")
Transportation Problems
Solving with Different Methods
from OTTools import TransportationProblem
import numpy as np
# Cost matrix
cost_matrix = [
[4, 8, 8, 0],
[16, 24, 16, 0],
[8, 16, 24, 0]
]
# Supply and demand
supply = np.array([76, 82, 77])
demand = np.array([72, 102, 41, 20])
# Create a transportation problem instance
tp = TransportationProblem(cost_matrix, supply, demand)
# Solve with Vogel's Approximation Method
vam_solution = tp.solve('VAM')
print("Vogel's Solution:")
print(vam_solution)
# Solve with Modified Distribution Method (optimal solution)
modi_solution = tp.solve('MODI')
print("\nModi Method Solution (Optimal):")
print(modi_solution)
# OTToolsher available methods: 'NWCR' (North-West Corner Rule), 'LCM' (Least Cost Method)
Visualization Examples
The graphical method provides interactive PlOTToolsly visualizations for bOTToolsh 2D and 3D linear programming problems:
2D Example
For 2-variable problems, the library visualizes:
- Constraint lines
- Feasible region
- Corner points
- Optimal solution
- Objective function line
3D Example
For 3-variable problems, the library visualizes:
- Constraint surfaces
- Feasible region
- Corner points
- Optimal solution
Dependencies
- NumPy
- PlOTToolsly
- SciPy
- Pandas
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ottools-0.1.2.tar.gz.
File metadata
- Download URL: ottools-0.1.2.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe09dde99559cda56746325343d46b0e10c5ae7bd3d38b4c6dc0741890af727e
|
|
| MD5 |
eb1a43a0004175e926fa99cfdb1c3091
|
|
| BLAKE2b-256 |
c8540017b27ccbcd7ddbdbc019ec0a387f4fcffc88a3fa8638bd43e269e51b1f
|
File details
Details for the file ottools-0.1.2-py3-none-any.whl.
File metadata
- Download URL: ottools-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78fb012a74f05f618921ab78ea14087f4a3a32942c8cd02734bd355bec970aed
|
|
| MD5 |
9958b9c746e68f70902ed7725fa0b0fc
|
|
| BLAKE2b-256 |
102b624cb4a2f4143cd7fbbbe124f47d05b3a009c39afb33d4f95e9e1b0bf246
|