ILOG CPLEX 11.0 User's Manual > Continuous Optimization > Solving Problems with a Quadratic Objective (QP) > Entering QPs > Examples for Entering QPs

ILOG CPLEX LP format requires the factor of 1/2 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 one-half 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, x[0], x[0]);
IloNumExpr x11 = model.prod(100, x[1], x[1]);
IloNumExpr x01 = model.prod(-200, 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 application better.

Finally, a Callable Library application 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 1/2 in any of these methods: if that objective function is evaluated with a solution of x1 = 1.000000 and x2 = 3.000000, the result to be expected is 200, not 400.