Skip to main content

Implementation of simplex algorithm controlled by the primal-dual gap

Project description

Gap controlled Simplex

Test and publish package PyPI - Version PyPI - Python Version PyPI - Downloads License

gsimplex is a lightweight Python package that implements a simplex solver governed by the primal-dual gap. It integrates directly with pulp and uses numpy for its linear algebra routines. The current release supports continuous linear programming problems; mixed-integer support may be added in a future version.

Features

This package provides three main solver implementations in gsimplex.solvers:

  • PrimalSimplex

    • Standard primal simplex algorithm.
    • Parameters:
      • max_iterations: maximum number of simplex iterations (default configured by package).
      • abs_eps: absolute tolerance used for feasibility and optimality checks.
      • rel_eps: relative tolerance for numerical comparisons.
      • pivot_rule: pivot selection strategy, "dantzig" by default; "bland" to avoid cycling.
  • DualSimplex

    • Dual simplex algorithm for problems with a dual-feasible starting basis.
    • Parameters:
      • max_iterations: maximum number of simplex iterations.
      • abs_eps: absolute tolerance for primal/dual feasibility checking.
      • rel_eps: relative tolerance for numerical comparisons.
      • pivot_rule: pivot selection strategy, "dantzig" by default; "bland" to avoid cycling.
  • GapDoubleSimplex

    • Combined primal/dual gap-controlled solver.
    • Runs primal and dual simplex iterations together and stops when the primal-dual gap is small enough.
    • Parameters:
      • max_iterations: maximum total iterations before giving up.
      • abs_eps: absolute tolerance for feasibility and basis checks.
      • rel_eps: relative tolerance for numerical comparisons.
      • abs_gap: absolute gap threshold for early termination.
      • rel_gap: relative gap threshold for early termination.
      • pivot_rule: pivot selection strategy for both primal and dual steps.
  • MutualPrimalDualSimplex

    • Mutual Primal-Dual Simplex algorithm proposed by Balinsky and Gomory in 1963.
    • Parameters:
      • max_iterations: maximum number of simplex iterations (default configured by package).
      • abs_eps: absolute tolerance used for feasibility and optimality checks.
      • rel_eps: relative tolerance for numerical comparisons.
      • pivot_rule: pivot selection strategy, "dantzig" by default; "bland" to avoid cycling.
  • MutualPrimalDualSimplex

    • Variation of the previous algorithm with gap checks.
    • Parameters:
      • max_iterations: maximum number of simplex iterations (default configured by package).
      • abs_eps: absolute tolerance used for feasibility and optimality checks.
      • rel_eps: relative tolerance for numerical comparisons.
      • pivot_rule: pivot selection strategy, "dantzig" by default; "bland" to avoid cycling.
    • Additional parameters to solve():
      • lb: known lower bound to the objective function.
      • ub: known upper bound to the objective function.

Installation

Install from PyPI:

python -m pip install gsimplex

Install from source for local development:

git clone https://github.com/Richie314/GapControlledSimplex.git
cd GapControlledSimplex
python -m pip install -e .
python -m pip install -e .[dev]

Run the test suite with:

python -m pytest

Usage

from pulp import LpVariable, LpProblem, LpMaximize
from gsimplex.solvers import PrimalSimplex

x1 = LpVariable("x1", lowBound=0, upBound=1)
x2 = LpVariable("x2", lowBound=0, upBound=3)

problem = LpProblem("Problem", LpMaximize)
problem += x1 + x2
problem += x1 + x2 <= 2
problem += x1 <= 1
problem += x2 <= 3
problem += x1 >= 0
problem += x2 >= 0

solver = PrimalSimplex()
problem.solve(solver)

print("Optimal value:", problem.objective.value()) # 2.0
print("Solution:", [var.varValue for var in problem.variables()]) # [1.0, 1.0]

Generate a random LP problem

This package installs a command-line helper called gsimplex-generate-lp to create a feasible LP in MPS format.

gsimplex-generate-lp --variables 10 --constraints 20 --output example.mps
  • --variables, -n: number of decision variables
  • --constraints, -m: number of constraints
  • --output, -o: output MPS file path (default: generated_lp.mps)

Download benchmark problems

The package also contains a tool to download known hard academic problems from the web: gsimplex-download-benchmarks. It can download Plato, Netlib and MipLib benchmark sets into a local directory, so you can test the solver on real LP problems.

By default, benchmark files are saved under the benchmark/ directory in the current working directory. Plato files are stored in benchmark/plato/, Netlib files are stored in benchmark/netlib/ and MipLib files are stored in benchmark/miplib/.

A script is provided to download the desired benchmarks.

# Will download only Plato benchmarks
gsimplex-download-benchmarks --plato

# Will download only Netlib benchmarks
gsimplex-download-benchmarks --netlib

# Will download both Plato and MipLib benchmarks
gsimplex-download-benchmarks --plato --miplib

Change the destination directory

gsimplex-download-benchmarks --plato --dir benchmark

Quiet mode

gsimplex-download-benchmarks --plato --quiet

If you installed the package editable with pip install -e ., the command will be available immediately.

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

gsimplex-0.1.3.tar.gz (40.3 kB view details)

Uploaded Source

Built Distribution

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

gsimplex-0.1.3-py3-none-any.whl (47.1 kB view details)

Uploaded Python 3

File details

Details for the file gsimplex-0.1.3.tar.gz.

File metadata

  • Download URL: gsimplex-0.1.3.tar.gz
  • Upload date:
  • Size: 40.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gsimplex-0.1.3.tar.gz
Algorithm Hash digest
SHA256 633cc29b2ae2ee242e96d5ee30bc246e7233a648da38bcb097c9a320d673d2c4
MD5 e5d4b933a94c118e6cdd2679862d18d8
BLAKE2b-256 d38ff8ddc35e54f1f015b132cbe3b7879e6b35ecf8e88c7a08a5fac02a48e6e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for gsimplex-0.1.3.tar.gz:

Publisher: pypi.yml on Richie314/GapControlledSimplex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gsimplex-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: gsimplex-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 47.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gsimplex-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c74e3901a94cf81dc6558fed78896b1ef03b6d9e8db6b0da89eecd85687c30e2
MD5 b13af0f7c24c668f3f3da605c0ee2d12
BLAKE2b-256 0fa84f9b7a6f1e58c6a199aab965eeed48249fc8785228e80ccfe62e6623e902

See more details on using hashes here.

Provenance

The following attestation bundles were made for gsimplex-0.1.3-py3-none-any.whl:

Publisher: pypi.yml on Richie314/GapControlledSimplex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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