Quadratic Programming¶
-
quadprog(c, Q, A, sense, b, l, u, solver)¶
Solves the quadratic programming problem:
where:
cis the objective vector, always in the sense of minimizationQis the Hessian matrix of the objectiveAis 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
Quadratic programming solvers extensively exploit the sparsity of the Hessian matrix Q and 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.
The quadprog function returns an instance of the type:
type QuadprogSolution
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 (not currently used).
Analogous shortened and range-constraint versions are available as well.
We can solve the three-dimensional QP (see test/quadprog.jl):
by:
using MathProgBase, Ipopt
sol = quadprog([0., 0., 0.],[2. 1. 0.; 1. 2. 1.; 0. 1. 2.],[1. 2. 3.; 1. 1. 0.],'>',[4., 1.],-Inf,Inf, IpoptSolver())
if sol.status == :Optimal
println("Optimal objective value is $(sol.objval)")
println("Optimal solution vector is: [$(sol.sol[1]), $(sol.sol[2]), $(sol.sol[3])]")
else
println("Error: solution status $(sol.status)")
end