Reference

Solver

class simplex.solver.SimplexSolver(obj_func: List[float], coeffs: List[List[float]], constraints: List[float])[source]

Solves a Linear Programming problem using Dantzig’s Simplex Method by manipulating the Tableau class.

Methods

solve(max_iterations=100, use_blands_rule=False)

(solves problem, yielding)

a`Solution` object

solve(max_iterations=100, use_blands_rule=False, print_tableau=True)[source]

Solves Linear Programming Problem. Returns Solution instance`.

Parameters
max_iterationsint

number of times to pivot before resorting to Bland’s rule

use_blands_rulebool

whether to use Bland’s Rule for anti-cycling

print_tableaubool

whether to print the tableau at every iteration

class simplex.solver.Solution(state: str, obj_value: float, basis: List[int], solution: List[float])[source]

Converts Tableau parameters into a human-readable solution.

Tableau

class simplex.tableau.Tableau(obj_func: List[float], coeffs: List[List[float]], constraints: List[float])[source]

Simplex Tableau contains and performs basic operations such as pivoting on the problem data.

There is one primary use case for this class, which is employed by the Solver class:

  1. Intialize Tableau (see __init__()) with program data in standard form.

  2. Open Tableau as a Context Manager and operate on it using the pivot() method.

  3. The pivot method will raise an exception once a termination point has been reached (optimality, unboundedness, or infeasibility).

  4. Extract Tableau data by directly accessing its attributes (see below).

Attributes
obj_valuefloat

Returns the objective value.

solutionList[float]

Returns the solution vector.

basisList[float]

Returns indices of basis vector.

Methods

pivot(use_blands_rule=False)

determines entering and departing variables and pivots tableau.

_pivot_around(r: int, c: int) → None[source]

Pivots tableau object given a row and column.

Parameters
rindex of departing variable
cindex of entering variable

Notes

Indices are relative to the tableau; they are not the constraint or variable indices.

add_artificial_variables()[source]

Inserts artificial columns in tableau and calculates new reduced costs.

property basis

Returns indices of basis vector.

Looks for each basic vector in the tableau, and stores index in the basis. -1 is stored in the absence of a corresponding basis column.

drop_artificial_variables()[source]

Removes artificial variables that have been driven out of the basis.

Returns
Function does not return anything.
Raises
InfeasibleProblem

if artificial variable is in basis with positive value

property obj_value

Returns the objective value.

pivot(use_blands_rule=False)[source]

Calculates departing and entering variables and calls _pivot_around(). Raises exception upon termination condition.

Raises
ReachedOptimality

If optimality conditions have been reached.

InfeasibleProblem

If problem is feasible and unable to pivot.

UnboundedProblem

If problem is unbounded.

property solution

Returns the solution vector.