Gap controlled Simplex
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:
-
- 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.
-
- 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.
-
- 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.
-
- 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.
-
- 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, in the form of value (float/int) or vector.ub: known upper bound to the objective function, in the form of value (float/int) or vector.- Neither
lbnorubare mandatory, but at least one of them must be provided.
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]
Command-line usage
If the package is installed, you can run the solver from the command line using:
gsimplex --problem path/to/problem.mps --solver gsimplex --sense minimize
Available options:
--problem PATH- path to the MPS problem file to solve--sense {minimize,maximize}- optimization sense (default:minimize)--solver {psimplex,dsimplex,gsimplex,msimplex}- solver algorithm to use (default:dsimplex)--abs-tol FLOAT- absolute tolerance for feasibility and optimality checks--rel-tol FLOAT- relative tolerance for numerical comparisons--pivot-type {dantzig,bland}- pivot selection strategy for simplex iterations--abs-gap FLOAT- absolute gap threshold for gap-controlled solvers (gsimplexandmsimplex)--rel-gap FLOAT- relative gap threshold for gap-controlled solvers (gsimplexandmsimplex)--quiet- suppress detailed output
Example:
python -m gsimplex --problem example.mps --solver gsimplex --sense minimize \
--abs-tol 1e-8 --rel-tol 1e-10 --pivot-type bland --abs-gap 1e-8 --rel-gap 1e-10
This runs the selected solver with the specified tolerances and gap control settings. For non-gap solvers (psimplex and dsimplex), --abs-gap and --rel-gap are ignored.
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.
Metadata
Release files for gsimplex 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| gsimplex-0.1.4.tar.gz | 41.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gsimplex-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 89.7 kB
Release files / gsimplex-0.1.4.tar.gz
| Download URL | gsimplex-0.1.4.tar.gz |
|---|---|
| Size | 41.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a08fe538dab2644a85cf54d19ccc09b72c5010a65b9bdd49403fb058d73bc00f
|
|
BLAKE2b-256 checksum How to use checksums |
62b6cd3440661c5b1e0e1920db2d67c283e922e993a5128845d102a45d1343ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.
Transparency logRelease files / gsimplex-0.1.4-py3-none-any.whl
| Download URL | gsimplex-0.1.4-py3-none-any.whl |
|---|---|
| Size | 48.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
09a5d970b1925ee4e71592ed297c28f76c9e7094b2431bbbde97338955f10ccd
|
|
BLAKE2b-256 checksum How to use checksums |
9eceb87db3ccc8bc34410f38012b537d253f7858eda06ecc8a9c88b04c3d09a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.
Transparency logSecurity for gsimplex 0.1.4
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for gsimplex-0.1.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 22, 2026.
Transparency logA 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.