Entering QPs

ILOG CPLEX supports two views of quadratic objective functions, a matrix view and an algebraic view.

In the matrix view, commonly found in textbook presentations of QP, the objective function is defined as 1/2 xTQx + cTx, where Q must be symmetric and positive semi-definite for a minimization problem, or negative semi-definite for a maximization problem. This view is supported by the MPS file format and the Callable Library routines, where the quadratic objective function information is specified by providing matrix Q. Thus, by definition, the factor of ½ must be considered when entering a model using the matrix view, as it will be implicitly assumed by the optimization routines. Similarly, symmetry of the Q matrix data is required; the MPS reader will return an error status code if the file contains unequal off-diagonal components, such as a nonzero value for one and zero (or omitted) for the other.

In the algebraic view, a quadratic objective function is specified as an expressions of the form:

  c1*x1 + ... + cn*xn + q11*x1*x1 + q12*x1*x2 + ... + qnn*xn*xn.

This view is supported by the LP format, when entering quadratic objective functions in the Interactive Optimizer, and by Concert Technology. Again, a quadratic objective function must be convex in the case of a minimization problem, or concave in the case of a maximization problem. When entering a quadratic objective with the algebraic view, neither symmetry considerations nor any implicit factors need to be considered, and indeed attempting to specify both of the off-diagonal elements for one of the quadratic terms may result in double the intended value of the coefficient.

Examples:

ILOG CPLEX LP format requires the factor of ½ to be explicitly specified in the file.

      Minimize
       obj: [ 100 x1 ^2 - 200 x1 * x2 + 100 x2 ^2 ] / 2

MPS format for this same objective function would contain the following.

  QMATRIX
      x1        x1                 100
      x1        x2                -100
      x2        x1                -100
      x2        x2                 100

A C++ Concert program having such an objective function might include the following.

model.add(IloMinimize(env, 0.5 * (100*x[0]*x[0] + 100*x[1]*x[1]

- 200*x[0]*x[1] ) ));

Or since the algebraic view is supported, the factor of ½ could be simplified as in the following equivalent expression

model.add(IloMinimize(env, (50*x[0]*x[0] + 50*x[1]*x[1]

- 100*x[0]*x[1] ) ));

:

A similar Java program using Concert might express it this way:

IloNumExpr x00 = model.prod(100, model.square(x[0]));

IloNumExpr x11 = model.prod(100, model.square(x[1]));

IloNumExpr x01 = model.prod(-200, model.prod(x[0], x[1]));

IloNumExpr Q = model.prod(0.5, model.sum(x00, x11, x01));

model.add(model.minimize(Q));

Again, the user could choose to simplify the above expression algebraically if that suits the purposes of the program better.

Finally, a Callable Library program in C might construct the quadratic objective function in a way similar to the following:

zqmatind[0] = 0; zqmatind[2] = 0;

zqmatval[0] = 100.0; zqmatval[2] = -100.0;

zqmatind[1] = 1; zqmatind[3] = 1;

zqmatval[1] =-100.0; zqmatval[3] = 100.0;

To re-emphasize the point about the factor of ½ in any of these methods, if the above objective function is evaluated with a solution of x1 = 1.000000 and x2 = 3.000000, the result to be expected is 200, not 400.


Previous Page: Identifying Convex Quadratic Programming Problems  Return to Top Next Page: Saving QP Problems