Example: iloqpex1.cpp
Demonstrates the solution of a quadratic program in the C++ API.
This example is almost identical to ilolpex1.cpp with
only function populatebyrow to create the
model. Also, this function differs only in the creation of the objective
from its ilolpex1.cpp counterpart. Here
the objective function is created and added to the model like this:
model.add(IloMaximize(env, x[0] + 2 * x[1] + 3 * x[2]
- 0.5 * (33*x[0]*x[0] + 22*x[1]*x[1] + 11*x[2]*x[2]
- 12*x[0]*x[1] - 23*x[1]*x[2]) ));
In general, any expression built of basic operations + , - , * , /
constant, and brackets [] that amounts to a quadratic and optional
linear term can be used for building a QP objective function. If the
expressions of the objective or any constraint of the model contains IloPiecewiseLinear,
then when a quadratic objective is specified the model becomes an
MIQP problem. (Piecewise-linearity is not the only characteristic
that renders a model MIQP. See also, for example, the features in Logical constraints in optimization, where automatic transformation with logical
constraints can render a problem MIQP.)
The complete program iloqpex1.cpp appears
online in the standard distribution at yourCPLEXinstallation/examples/src .