Linear Programming¶

linprog
(c, A, sense, b, l, u, solver)¶
Solves the linear programming problem:
where:
c
is the objective vector, always in the sense of minimizationA
is the constraint matrix, with rows \(a_i\) (viewed as columnoriented vectors)sense
is a vector of constraint sense characters'<'
,'='
, and'>'
b
is the righthand side vectorl
is the vector of lower bounds on the variablesu
is the vector of upper bounds on the variables, andsolver
specifies the desired solver, see choosing solvers.
A scalar is accepted for the b
, sense
, l
, and u
arguments, in which case its value is replicated. The values Inf
and Inf
are interpreted to mean that there is no corresponding lower or upper bound.
Note
Linear programming solvers extensively exploit the sparsity of the constraint matrix A
. While both dense and sparse matrices are accepted, for largescale problems sparse matrices should be provided if permitted by the problem structure.
A shortened version is defined as:
linprog(c, A, sense, b, solver) = linprog(c, A, sense, b, 0, Inf, solver)
The linprog
function returns an instance of the type:
type LinprogSolution
status
objval
sol
attrs
end
where status
is a termination status symbol, one of :Optimal
, :Infeasible
, :Unbounded
, :UserLimit
(iteration limit or timeout), :Error
(and maybe others).
If status
is :Optimal
, the other members have the following values:
objval
– optimal objective valuesol
– primal solution vectorattrs
– a dictionary that may contain other relevant attributes such as:redcost
– dual multipliers for active variable bounds (zero if inactive)lambda
– dual multipliers for active linear constraints (equalities are always active)
If status
is :Infeasible
, the attrs
member will contain an infeasibilityray
if available; similarly for :Unbounded
problems, attrs
will contain an unboundedray
if available.
For example, we can solve the twodimensional problem (see test/linprog.jl
):
by:
using MathProgBase, Clp
sol = linprog([1,0],[2 1],'<',1.5, ClpSolver())
if sol.status == :Optimal
println("Optimal objective value is $(sol.objval)")
println("Optimal solution vector is: [$(sol.sol[1]), $(sol.sol[2])]")
else
println("Error: solution status $(sol.status)")
end

linprog
(c, A, lb, ub, l, u, solver)
This variant allows one to specify twosided linear constraints (also known as range constraints) to solve the linear programming problem:
where:
c
is the objective vector, always in the sense of minimizationA
is the constraint matrixlb
is the vector of row lower boundsub
is the vector of row upper boundsl
is the vector of lower bounds on the variablesu
is the vector of upper bounds on the variables, andsolver
specifies the desired solver, see choosing solvers.
A scalar is accepted for the l
, u
, lb
, and ub
arguments, in which case its value is replicated. The values Inf
and Inf
are interpreted to mean that there is no corresponding lower or upper bound. Equality constraints are specified by setting the row lower and upper bounds to the same value.
A shortened version is defined as:
linprog(c, A, lb, ub, solver) = linprog(c, A, lb, ub, 0, Inf, solver)
Note
The function linprog
calls two independent functions for building and solving the linear programming problem, namely buildlp
and solvelp
.

buildlp
(c, A, sense, b, l, u, solver)¶
Builds the linear programming problem as defined in linprog
and accepts the following arguments:
c
is the objective vector, always in the sense of minimizationA
is the constraint matrixsense
is a vector of constraint sense characters'<'
,'='
, and'>'
b
is the righthand side vectorl
is the vector of lower bounds on the variablesu
is the vector of upper bounds on the variables, andsolver
specifies the desired solver, see choosing solvers.
A scalar is accepted for the b
, sense
, l
, and u
arguments, in which case its value is replicated. The values Inf
and Inf
are interpreted to mean that there is no corresponding lower or upper bound.

buildlp
(c, A, lb, ub, l, u, solver)
This variant of buildlp
allows to specify twosided linear constraints (also known as range constraints) similar to linprog
, and accepts the following arguments:
c
is the objective vector, always in the sense of minimizationA
is the constraint matrixlb
is the vector of row lower boundsub
is the vector of row upper boundsl
is the vector of lower bounds on the variablesu
is the vector of upper bounds on the variables, andsolver
specifies the desired solver, see choosing solvers.
A scalar is accepted for the l
, u
, lb
, and ub
arguments, in which case its value is replicated. The values Inf
and Inf
are interpreted to mean that there is no corresponding lower or upper bound. Equality constraints are specified by setting the row lower and upper bounds to the same value.
The buildlp
function returns an AbstractLinearQuadraticModel
that can be input to `solvelp`
in order to obtain a solution.

solvelp
(m)¶
Solves the linear programming problem as defined in linprog`
and accepts the following argument:
m
is anAbstractLinearQuadraticModel
(e.g., as returned bybuildlp
).
The solvelp
function returns an instance of the type:
type LinprogSolution
status
objval
sol
attrs
end