Skip to main content

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)

# Other available methods: 'NWCR' (North-West Corner Rule), 'LCM' (Least Cost Method)

Visualization Examples

The graphical method provides interactive Plotly visualizations for both 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
  • Plotly
  • SciPy

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for OTTools 0.1.3

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

Source distribution (sdist)

Source distribution for OTTools 0.1.3
File Size Uploaded Provenance Actions
ottools-0.1.3.tar.gz 11.5 kB Without provenance Details for ottools-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for OTTools 0.1.3
File Interpreter ABI Platform Actions
ottools-0.1.3-py3-none-any.whl Python 3 none any Details for ottools-0.1.3-py3-none-any.whl

Total release size: 23.8 kB

Release files / ottools-0.1.3.tar.gz

Download URL ottools-0.1.3.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
43727ae0f2c417713a25896f8e5926c7693ad893bd8ee14d6d3c98b6f4c3b234
BLAKE2b-256 checksum
How to use checksums
43898b5d92968714552ecd9fd22d4b73d7f57efe043767b2abe221252809c72c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.5

Release files / ottools-0.1.3-py3-none-any.whl

Download URL ottools-0.1.3-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16eeb56cf14ef316a5066d74a192c1f323f2d79a0079d6e8942516978b13c4bf
BLAKE2b-256 checksum
How to use checksums
26d5b7bbd549fa54fded38c0be0a796c8dc6798dcb14bdaae51c4e450a122db6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.5

Security for OTTools 0.1.3

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