Skip to main content

Pure Python implementation of Gomory cutting plane method for Integer Linear Programming (ILP/MILP) - Educational solver with exact arithmetic

Project description

Gomory - Cutting Plane Method for Integer Linear Programming

PyPI version Python 3.8+ License: MIT

A pure Python implementation of the Gomory cutting plane method for solving Integer Linear Programming (ILP) problems. Designed for educational purposes with exact fractional arithmetic.

✨ Features

  • Pure Python - No external solver dependencies
  • Exact arithmetic - Uses fractions instead of floating-point numbers
  • Educational - Step-by-step display of simplex tableaux at each iteration
  • Complete traceability - Follow every step of the algorithm
  • Primal & Dual Simplex - Full implementation of both methods
  • Gomory cuts generation - Automatic cutting plane generation

🚀 Installation

pip install gomory

From GitHub (development)

git clone https://github.com/vleonel-junior/Gomory.git
cd Gomory
pip install -e .

📋 Quick Start

from gomory import Problem, GomorySolver

# Define an Integer Linear Programming problem
# max z = 6x₁ + 8x₂ + 7x₃
# subject to:
#   4x₁ + 6x₂ + 8x₃ ≤ 14
#   x₁ ≤ 1, x₂ ≤ 1, x₃ ≤ 1
#   xᵢ ∈ ℤ⁺ (integer variables)

problem = Problem(
    objective=[6, 8, 7],
    sense="max",
    constraints=[
        ([4, 6, 8], "<=", 14),
        ([1, 0, 0], "<=", 1),
        ([0, 1, 0], "<=", 1),
        ([0, 0, 1], "<=", 1),
    ],
    integer_vars=[0, 1, 2],  # indices of integer variables
    var_names=["x1", "x2", "x3"]
)

# Solve with verbose output
solver = GomorySolver(problem, verbose=True)
solution = solver.solve()

# Display solution
print(solution)

Expected Output

Optimal integer solution found!
x1 = 0, x2 = 1, x3 = 1
z* = 15

📚 How It Works

The Gomory cutting plane method solves Integer Linear Programs through:

1. LP Relaxation

First, solve the linear program without integrality constraints using the primal simplex method.

2. Gomory Cut Generation

If the solution is not integer, generate a Gomory cut from the row with the largest fractional part.

3. Dual Simplex

After adding the cut, the dual simplex method restores feasibility.

4. Iteration

Repeat until an integer solution is found.

🧪 Tests

pytest tests/

📁 Project Structure

gomory/
├── gomory/
│   ├── __init__.py          # Package exports
│   ├── fraction_utils.py    # Fraction utilities
│   ├── problem.py           # Problem modeling
│   ├── tableau.py           # Simplex tableau
│   ├── simplex.py           # Primal simplex
│   ├── dual_simplex.py      # Dual simplex
│   ├── gomory_cut.py        # Cut generation
│   ├── solver.py            # Main solver
│   └── display.py           # Formatted display
├── tests/                   # Unit tests
├── examples/                # Usage examples
└── pyproject.toml           # Package configuration

🔗 See Also

📄 License

MIT License

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

gomory-1.0.1.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

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

gomory-1.0.1-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file gomory-1.0.1.tar.gz.

File metadata

  • Download URL: gomory-1.0.1.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for gomory-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b31c923b15f5b632cbc985d67d5fd54032541fb3dd504525bfd01224d8775acf
MD5 28e6b4aab69e9ebfa42289c169c03ef9
BLAKE2b-256 e5be77ddb149c539235aae108ebaa1fd6e5da2eb7a1b1d1b707f1b9f10359a27

See more details on using hashes here.

File details

Details for the file gomory-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: gomory-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for gomory-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 04907000b71f9afe0fe0e98d07d97ff914b1aa74e4c878c231532af23dbc1892
MD5 0858e60da0824e244e298960394e11c0
BLAKE2b-256 fa2a8297ae20887a96fc46b224a9cfda840d9f9815cad72e391120e61d6b7b8f

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