The Simplex Method
createsimplexproblem
OperationsResearchModels.Simplex.createsimplexproblem — Functioncreatesimplexproblem(obj::Vector, amat::Matrix, rhs::Vector, dir::Vector, opttype::OptimizationType)::SimplexProblemDescription
This function creates a SimplexProblem object from the given parameters.
Arguments
obj::Vector: The objective function coefficients.amat::Matrix: The LHS of the constraints.rhs::Vector: The RHS of the constraints.dir::Vector: The directions of the constraints. Can be a vector of LE (<=), GE (>=), or EQ (==).opttype::OptimizationType: The type of the optimization. Can be Maximize or Minimize.
Returns
A SimplexProblem object.
Example
Suppose the linear programming problem is as follows:
Maximize: 1.0x1 + 2.0x2 + 3.0x3
Subject to:
1.0x1 + 2.0x2 + 3.0x3 <= 10.0
3.0x1 + 1.0x2 + 5.0x3 <= 15.0
x1, x2 >= 0The following code creates a SimplexProblem object for the above problem:
using OperationsResearchModels.Simplex
obj = Float64[1.0, 2.0, 3.0]
amat = Float64[1.0 2.0 3.0; 3.0 1.0 5.0]
rhs = Float64[10.0, 15.0]
dir = [LE, LE]
opttype = Maximize
s = createsimplexproblem(obj, amat, rhs, dir, opttype)
iters = simplexiterations(s)solve!
OperationsResearchModels.solve! — Methodsolve!(s::SimplexProblem)::SimplexProblemDescription
Solves the given SimplexProblem using the Simplex algorithm. The solve! function modifies the input SimplexProblem in place.
Arguments
s::SimplexProblem: The SimplexProblem to solve.
Returns
SimplexProblem: The solved SimplexProblem.
simplexiterations
OperationsResearchModels.Simplex.simplexiterations — Functionsimplexiterations(s::SimplexProblem)::Vector{SimplexProblem}Description
This function performs the Simplex iterations on the given SimplexProblem and returns the history of SimplexProblem states.
Arguments
s::SimplexProblem: The SimplexProblem to iterate.
Returns
Vector{SimplexProblem}: The history of SimplexProblem states (by iterations).
Gauss Jordan steps for matrix inversion
OperationsResearchModels.Simplex.gaussjordan — Functiongaussjordan(A::Matrix; verbose::Bool = true)::MatrixDescription
Attaches an Identity matrix to the right of the given matrix A and applies the Gauss-Jordan elimination method to find the inverse of the given matrix.
Arguments
A::Matrix: The matrix to find the inverse.verbose::Bool: If true, the intermediate steps are displayed. Default is true.
Returns
The inverse of the given matrix.
Example
A = [1.0 2.0 3.0; 4.0 5.0 6.0; 7.0 8.0 10.0]
invA = gaussjordan(A, verbose = false)
# 3×3 Matrix{Float64}:
# -0.666667 -1.33333 1.0
# -0.666667 3.66667 -2.0
# 1.0 -2.0 1.0