Simplex2P

scalation.optimization.linear_opt.Simplex2P
class Simplex2P(a: MatrixD, b: VectorD, c: VectorD) extends MinimizerLP

The Simplex2P class solves Linear Programming (LP) problems using a tableau based Simplex Algorithm. Given a constraint matrix a, limit/RHS vector b and cost vector c, find values for the solution/decision vector x that minimize the objective function f(x), while satisfying all of the constraints, i.e.,

minimize f(x) = c x subject to a x <= b, x >= 0

In case of a_i x >= b_i, use -b_i as an indicator of a ">=" constraint. The program will flip such negative b_i back to positive as well as use a surplus and artificial variable instead of the usual slack variable, i.e., a_i x <= b_i => a_i x + s_i = b_i // use slack variable s_i with coefficient 1 a_i x >= b_i => a_i x + s_i = b_i // use surplus variable s_i with coefficient -1 For each '>=' constraint, an artificial variable is introduced and put into the initial basis. These artificial variables must be removed from the basis during Phase I of the Two-Phase Simplex Algorithm. After this, or if there are no artificial variables, Phase II is used to find an optimal value for x and the optimum value for f.

Creates an MM-by-nn simplex tableau with -- [0..M-1, 0..N-1] = a (constraint matrix) -- [0..M-1, N..M+N-1] = s (slack/surplus variable matrix) -- [0..M-1, M+N..nn-2] = r (artificial variable matrix) -- [0..M-1, nn-1] = b (limit/RHS vector) -- [M, 0..nn-2] = c (cost vector)

Value parameters

a

the M-by-N constraint matrix

b

the M-length limit/RHS vector (input b_i negative for surplus)

c

the N-length cost vector

Attributes

Graph
Supertypes
trait MinimizerLP
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def dual: VectorD

Return the dual solution vector y (cost row (M) under the slack columns).

Return the dual solution vector y (cost row (M) under the slack columns).

Attributes

def entering(): Int

Find the best variable x_l to enter the basis. Determine the index of entering variable corresponding to column l (e.g., using Dantiz's Rule or Bland's Rule). Return -1 to indicate no such column. t(M).argmaxPos (jj) // use Dantiz's rule (index of max positive, cycling possible) t(M).firstPos (jj) // use Bland's rule (index of first positive, FPE possible)

Find the best variable x_l to enter the basis. Determine the index of entering variable corresponding to column l (e.g., using Dantiz's Rule or Bland's Rule). Return -1 to indicate no such column. t(M).argmaxPos (jj) // use Dantiz's rule (index of max positive, cycling possible) t(M).firstPos (jj) // use Bland's rule (index of first positive, FPE possible)

Attributes

def infeasible: Boolean

Determine whether the current solution (x = primal) is still primal feasible.

Determine whether the current solution (x = primal) is still primal feasible.

Attributes

def initBasis(): Unit

Initialize the basis to the slack and artificial variables. Perform row operations to make cost row (t(M)) zero in artificial var columns. If b(i) is negative have a surplus and artificial variable, otherwise, just a slack variable.

Initialize the basis to the slack and artificial variables. Perform row operations to make cost row (t(M)) zero in artificial var columns. If b(i) is negative have a surplus and artificial variable, otherwise, just a slack variable.

Attributes

def leaving(l: Int): Int

Find the best variable x_k to leave the basis given that x_l is entering. Determine the index of the leaving variable corresponding to row k using the Min-Ratio Rule. Return -1 to indicate no such row.

Find the best variable x_k to leave the basis given that x_l is entering. Determine the index of the leaving variable corresponding to row k using the Min-Ratio Rule. Return -1 to indicate no such row.

Value parameters

l

the entering variable (column)

Attributes

def objF(x: VectorD): Double

Return the value of the objective function f(x) = c x.

Return the value of the objective function f(x) = c x.

Attributes

def pivot(k: Int, l: Int): Unit

Pivot on entry (k, l) using Gauss-Jordan elimination to replace variable x_k with x_l in the basis.

Pivot on entry (k, l) using Gauss-Jordan elimination to replace variable x_k with x_l in the basis.

Value parameters

k

the leaving variable (row)

l

the entering variable (column)

Attributes

Return the primal solution vector x (only the basic variables are non-zero).

Return the primal solution vector x (only the basic variables are non-zero).

Attributes

def removeArtificials(): Unit

Remove the artificial variables and reset the cost row (M) in the tableau.

Remove the artificial variables and reset the cost row (M) in the tableau.

Attributes

def showTableau(iter: Int): Unit

Show the current tableau.

Show the current tableau.

Value parameters

iter

the number of iterations do far

Attributes

def solve(): VectorD

Solve the LP minimization problem using two phases if necessary. Note: phase I is always minimization. Two phases are necessary if the number of artificial variables R > 0.

Solve the LP minimization problem using two phases if necessary. Note: phase I is always minimization. Two phases are necessary if the number of artificial variables R > 0.

Attributes

def solve_1(): VectorD

Run the simplex algorithm starting from an initial BFS and iteratively find a non-basic variable to replace a variable in the current basis so long as the objective function improves. Runs a single phase and return the optimal vector x.

Run the simplex algorithm starting from an initial BFS and iteratively find a non-basic variable to replace a variable in the current basis so long as the objective function improves. Runs a single phase and return the optimal vector x.

Attributes

override def toString: String

Convert the current tableau and basis to a string suitable for display.

Convert the current tableau and basis to a string suitable for display.

Attributes

Definition Classes
Any

Inherited methods

def check(x: VectorD, y: VectorD, f: Double): Boolean

Determine whether the current solution is correct.

Determine whether the current solution is correct.

Value parameters

f

the minimum value of the objective function

x

the primal solution vector x

y

the dual solution vector y

Attributes

Inherited from:
MinimizerLP

Concrete fields

Inherited fields

protected val EPSILON: Double

Attributes

Inherited from:
MinimizerLP