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)

# 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.

Metadata

Release files for OTTools 0.1.2

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.2
File Size Uploaded
ottools-0.1.2.tar.gz 10.7 kB Details

Built distribution (wheel)

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

Total release size: 21.6 kB

Release files / ottools-0.1.2.tar.gz

Download URL ottools-0.1.2.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
fe09dde99559cda56746325343d46b0e10c5ae7bd3d38b4c6dc0741890af727e
BLAKE2b-256 checksum
How to use checksums
c8540017b27ccbcd7ddbdbc019ec0a387f4fcffc88a3fa8638bd43e269e51b1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

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

Download URL ottools-0.1.2-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78fb012a74f05f618921ab78ea14087f4a3a32942c8cd02734bd355bec970aed
BLAKE2b-256 checksum
How to use checksums
102b624cb4a2f4143cd7fbbbe124f47d05b3a009c39afb33d4f95e9e1b0bf246
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.0

2 release files

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