The Quadratic Programming Solver

Getting Started: QP Solver

Consider a small illustrative example. Suppose you want to minimize a two-variable quadratic function f left-parenthesis x 1 comma x 2 right-parenthesis on the nonnegative quadrant, subject to two constraints:

StartLayout 1st Row 1st Column min 2nd Column 2 x 1 3rd Column plus 4th Column 3 x 2 5th Column plus 6th Column x 1 squared 7th Column plus 8th Column 10 x 2 squared 9th Column plus 10th Column 2.5 x 1 x 2 2nd Row 1st Column subject to 2nd Column x 1 3rd Column minus 4th Column x 2 5th Column less-than-or-equal-to 6th Column 1 7th Column Blank 8th Column Blank 9th Column Blank 10th Column Blank 3rd Row 1st Column Blank 2nd Column x 1 3rd Column plus 4th Column 2 x 2 5th Column greater-than-or-equal-to 6th Column 100 7th Column Blank 8th Column Blank 9th Column Blank 10th Column Blank 4th Row 1st Column Blank 2nd Column x 1 3rd Column Blank 4th Column Blank 5th Column greater-than-or-equal-to 6th Column 0 7th Column Blank 8th Column Blank 9th Column Blank 10th Column Blank 5th Row 1st Column Blank 2nd Column Blank 3rd Column Blank 4th Column x 2 5th Column greater-than-or-equal-to 6th Column 0 7th Column Blank 8th Column Blank 9th Column Blank 10th Column Blank EndLayout

To use the OPTMODEL procedure, it is not necessary to fit this problem into the general QP formulation mentioned in the section Overview: QP Solver and to compute the corresponding parameters. However, since these parameters are closely related to the data set that is used by the OPTQP procedure and has a quadratic programming system (QPS) format, you can compute these parameters as follows. The linear objective function coefficients, vector of right-hand sides, and lower and upper bounds are identified immediately as

bold c equals StartBinomialOrMatrix 2 Choose 3 EndBinomialOrMatrix comma bold b equals StartBinomialOrMatrix 1 Choose 100 EndBinomialOrMatrix comma bold l equals StartBinomialOrMatrix 0 Choose 0 EndBinomialOrMatrix comma bold u equals StartBinomialOrMatrix plus normal infinity Choose plus normal infinity EndBinomialOrMatrix

Carefully construct the quadratic matrix bold upper Q. Observe that you can use symmetry to separate the main-diagonal and off-diagonal elements:

one-half bold x Superscript upper T Baseline bold upper Q bold x identical-to one-half sigma-summation Underscript i comma j equals 1 Overscript n Endscripts x Subscript i Baseline q Subscript i j Baseline x Subscript j Baseline equals one-half sigma-summation Underscript i equals 1 Overscript n Endscripts q Subscript i i Baseline x Subscript i Superscript 2 Baseline plus sigma-summation Underscript i greater-than j Endscripts x Subscript i Baseline q Subscript i j Baseline x Subscript j

The first expression

one-half sigma-summation Underscript i equals 1 Overscript n Endscripts q Subscript i i Baseline x Subscript i Superscript 2

sums the main-diagonal elements. Thus, in this case you have

q 11 equals 2 comma q 22 equals 20

Notice that the main-diagonal values are doubled in order to accommodate the 1/2 factor. Now the second term

sigma-summation Underscript i greater-than j Endscripts x Subscript i Baseline q Subscript i j Baseline x Subscript j

sums the off-diagonal elements in the strict lower triangular part of the matrix. The only off-diagonal (x Subscript i Baseline x Subscript j Baseline comma i not-equals j) term in the objective function is 2.5 x 1 x 2, so you have

q 21 equals 2.5

Notice that you do not need to specify the upper triangular part of the quadratic matrix.

Finally, the matrix of constraints is as follows:

bold upper A equals Start 2 By 2 Matrix 1st Row 1st Column 1 2nd Column negative 1 2nd Row 1st Column 1 2nd Column 2 EndMatrix

The following OPTMODEL program formulates the preceding problem in a manner that is very close to the mathematical specification of the given problem:

/* getting started */
proc optmodel;
   var x1 >= 0; /* declare nonnegative variable x1 */
   var x2 >= 0; /* declare nonnegative variable x2 */

   /* objective: quadratic function f(x1, x2) */
   minimize f =
       /* the linear objective function coefficients */
       2 * x1 + 3 * x2 +

       /* quadratic <x, Qx> */
       x1 * x1 + 2.5 * x1 * x2 + 10 * x2 * x2;

   /* subject to the following constraints */
   con r1: x1 - x2 <= 1;
   con r2: x1 + 2 * x2 >= 100;

   /* specify iterative interior point algorithm (QP)
    * in the SOLVE statement */
   solve with qp;

   /* print the optimal solution */
   print x1 x2;
   save qps qpsdata;
quit;

The "with qp" clause in the SOLVE statement invokes the QP solver to solve the problem. The output is shown in Figure 2.

Figure 2: Summaries and Optimal Solution

The OPTMODEL Procedure

Problem Summary
Objective SenseMinimization
Objective Functionf
Objective TypeQuadratic
  
Number of Variables2
Bounded Above0
Bounded Below2
Bounded Below and Above0
Free0
Fixed0
  
Number of Constraints2
Linear LE (<=)1
Linear EQ (=)0
Linear GE (>=)1
Linear Range0
  
Constraint Coefficients4
  
Hessian Diagonal Elements2
Hessian Elements Below Diagonal1

Solution Summary
SolverQP
AlgorithmInterior Point
Objective Functionf
Solution StatusOptimal
Objective Value15018.000046
  
Primal Infeasibility0
Dual Infeasibility0
Bound Infeasibility0
Duality Gap7.8497851E-9
Complementarity0
  
Iterations4
Presolve Time0.00
Solution Time0.04

x1x2
3433


In this example, the SAVE QPS statement is used to save the QP problem in the QPS-format data set qpsdata, shown in Figure 3. The data set is consistent with the parameters of general quadratic programming previously computed. Also, the data set can be used as input to the OPTQP procedure.

Figure 3: QPS-Format Data Set

ObsFIELD1FIELD2FIELD3FIELD4FIELD5FIELD6
1NAME qpsdata. .
2ROWS  . .
3Nf . .
4Lr1 . .
5Gr2 . .
6COLUMNS  . .
7 x1f2.0r11
8 x1r21.0 .
9 x2f3.0r1-1
10 x2r22.0 .
11RHS  . .
12 .RHS.r11.0 .
13 .RHS.r2100.0 .
14QSECTION  . .
15 x1x12.0 .
16 x1x22.5 .
17 x2x220.0 .
18ENDATA  . .


Last updated: January 26, 2024