Simplex
A python package that solve linear programming problems using the simplex method.
Features:
- The Problem is input into the program by a file containing python expression.
- Solves both min and max problems(duh!).
- Uses the big M method to find a basic feasible solution when there are none available in the original program.
- Handles adding slack variables to convert the problem into standard form.
- Uses the lexicographic rule to prevent ending up in a loop due to degenerate extreme points.
- outputs in html.
Run Help to get a list of available commandline options.
./test.py --help [INSERT] 32mS 0↵ L3
usage: test.py [-h] [--equs EQUS] [--csv CSV] [--delim DELIM] [--slack SLACK] [--aux AUX] [--iter ITER] [--min] [--verbose] [--debug] [--out] [--numba]
options:
-h, --help show this help message and exit
--equs EQUS, -e EQUS the path to the file containing the equations
--csv CSV, -c CSV the path to the CSV file containing the problem
--delim DELIM, -l DELIM
the separator for the csv file
--slack SLACK, -s SLACK
slack variable base name, names are cretedby adding a number to the string
--aux AUX, -a AUX aux variable base name, names are cretedby adding a number to the string
--iter ITER, -i ITER maximum number of iterations
--min, -m determines whether its a minimization problem.if not, its a maximization problem
--verbose, -v whether to print output verbosely
--debug, -d whether to print debug info
--out, -o path to the output file
--numba, -n whether to print debug info]q
Example usage:
dsimplex -e ./tests/equ6.py -a xa -v -s z -m
The Equation File
dsimplex currently accepts two input formats:
Python Expressions
Each equation in the equations file should a valid python expression. There are a couple notes though:
- For conditions that end in equality you must use
==instead of=to make it a legal python expression. - Nothing will be evaluated so writing something like
4/5*x1is illegal. Use.8*x1instead. - You can use comments inside the equations file. They are the same format as the python comments.
- The cost equation is one without a binary comparison operator, e.g.
<=,<,>=,>. - The order of the equations in the equations file is not important. You can put them in in any order you want.
As an example:
# cyclic test
-0.75 * x4 + 20 * x5 - 0.5 * x6 + 6 * x7
x1 + 0.25 * x4 - 8 * x5 - x6 + 9 * x7 == 0
x2 + 0.5 * x4 - 12 * x5 - 0.5 * x6 + 3 * x7 == 0
x3 + x6 == 1
x1 >= 0
x2 >= 0
x3 >= 0
x4 >= 0
x5 >= 0
x6 >= 0
x7 >= 0
CSV
- The order of the equations is not important. It is also not important where the cost function is in the csv file as long as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x2,cond,rhs
1,-2,,
1,1,>=,2
-1,1,>=,1
,1,<=,3
1,,>=,0
,1,>=,0
x1,x2,x3,x4,x5,x6,x7,cond,rhs
,,,-0.75,20,-0.5,6,,
1,,,0.25,-8,-1,9,=,0
,1,,0.5,-12,-0.5,3,=,0
,,1,,,1,,=,1
1,,,,,,,>=,0
,1,,,,,,>=,0
,,1,,,,,>=,0
,,,1,,,,>=,0
,,,,1,,,>=,0
,,,,,1,,>=,0
,,,,,,1,>=,0
How to Get
You can get it from pypi:
pip3 install dsimplex
Or you can clone this repo and run it like that:
git clone https://github.com/terminaldweller/simplex && cd simplex && poetry install
Metadata
Release files for dsimplex 0.2.0
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 | |
|---|---|---|---|---|
| dsimplex-0.2.0.tar.gz | 28.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dsimplex-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 67.6 kB
Release files / dsimplex-0.2.0.tar.gz
| Download URL | dsimplex-0.2.0.tar.gz |
|---|---|
| Size | 28.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a91442dd22b9cadf1ad55f2dfd312bc37000f4b5abf9e0301174ac9b11fbce1
|
|
BLAKE2b-256 checksum How to use checksums |
29364232a06b0cf28fc6a68e5fcf5e6ec0f54c1ce2960cff4c035214f91c9cee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.6 Linux/5.18.17_1
|
Release files / dsimplex-0.2.0-py3-none-any.whl
| Download URL | dsimplex-0.2.0-py3-none-any.whl |
|---|---|
| Size | 39.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de009f964aaa86c80ac98ddc1160533ccf23baec3d2080d428b164dc44ee5b87
|
|
BLAKE2b-256 checksum How to use checksums |
14bc0e5e5a4313df122416e5c281c86433cfb2405e4448bbd17f9526fb32803c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.6 Linux/5.18.17_1
|
Security for dsimplex 0.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.