Two-phase Simplex implementation in Python with numpy
- Identify unbounded solutions.
- Identify when there is no feasible solution.
- Edge cases with only equalities.
- Print the original problem without slack and artificial variable columns.
- Working with multiple equalities (gets processed but gets a different answer to linprog highs).
Needs numpy installed.
When running the scripts, it asks for the problem information. Exactly, the script will ask:
- If it is a maximization (write 1) or minimization problem (write 0).
- For
$c$ vector,$A$ matrix,$b$ vector,$A_{eq}$ matrix,$b_{eq}$ vector, from the following problem description: Maximize (or minimize) the$Z$ function of vector$x$ subject to
Notice that
Use the same format from the input_example/ directory
to write your problems in files, then redirect the file contents to the script.
First chmod +x two_phase_simplex.py if you want to run it as a program. Then
./two_phase_simplex < input_examples/min_example3.txt
will output
...
The optimal solution is:
x_1 = 0
x_2 = 0
x_3 = 0.19999999999999996
x_4 = 0.5999999999999999
With an optimal Z value of 12.999999999999996