Linear Programming¶
-
linprog(c, A, sense, b, l, u, solver)¶
Solves the linear programming problem:
where:
cis the objective vector, always in the sense of minimizationAis the constraint matrix, with rows \(a_i\) (viewed as column-oriented vectors)senseis a vector of constraint sense characters'<','=', and'>'bis the right-hand side vectorlis the vector of lower bounds on the variablesuis the vector of upper bounds on the variables, andsolverspecifies 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 large-scale 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 two-dimensional 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 two-sided linear constraints (also known as range constraints) to solve the linear programming problem:
where:
cis the objective vector, always in the sense of minimizationAis the constraint matrixlbis the vector of row lower boundsubis the vector of row upper boundslis the vector of lower bounds on the variablesuis the vector of upper bounds on the variables, andsolverspecifies 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:
cis the objective vector, always in the sense of minimizationAis the constraint matrixsenseis a vector of constraint sense characters'<','=', and'>'bis the right-hand side vectorlis the vector of lower bounds on the variablesuis the vector of upper bounds on the variables, andsolverspecifies 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 two-sided linear constraints (also known as range constraints) similar to linprog, and accepts the following arguments:
cis the objective vector, always in the sense of minimizationAis the constraint matrixlbis the vector of row lower boundsubis the vector of row upper boundslis the vector of lower bounds on the variablesuis the vector of upper bounds on the variables, andsolverspecifies 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:
mis anAbstractLinearQuadraticModel(e.g., as returned bybuildlp).
The solvelp function returns an instance of the type:
type LinprogSolution
status
objval
sol
attrs
end