Skip to main content

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

Metadata

Release files for gomory 1.0.1

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

Source distribution (sdist)

Source distribution for gomory 1.0.1
File Size Uploaded
gomory-1.0.1.tar.gz 25.7 kB Details

Built distribution (wheel)

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

Total release size: 50.9 kB

Release files / gomory-1.0.1.tar.gz

Download URL gomory-1.0.1.tar.gz
Size 25.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b31c923b15f5b632cbc985d67d5fd54032541fb3dd504525bfd01224d8775acf
BLAKE2b-256 checksum
How to use checksums
e5be77ddb149c539235aae108ebaa1fd6e5da2eb7a1b1d1b707f1b9f10359a27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / gomory-1.0.1-py3-none-any.whl

Download URL gomory-1.0.1-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04907000b71f9afe0fe0e98d07d97ff914b1aa74e4c878c231532af23dbc1892
BLAKE2b-256 checksum
How to use checksums
fa2a8297ae20887a96fc46b224a9cfda840d9f9815cad72e391120e61d6b7b8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

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