ILOG CPLEX 11.0 User's Manual > Continuous Optimization > Solving Problems with a Quadratic Objective (QP) > Examples: Creating a QP, Optimizing, Finding a Solution > Example: qpex1.c

This example shows you how to optimize a QP with routines from the ILOG CPLEX Callable Library when the problem data is stored in a file. The example derives from lpex1.c discussed in ILOG CPLEX Getting Started. The Concert forms of this example, iloqpex1.cpp and QPex1.java, are included online in the standard distribution.

Instead of calling CPXlpopt to find a solution as for the linear programming problem in lpex1.c, this example calls CPXqpopt to optimize this quadratic programming problem.

Like other applications based on the ILOG CPLEX Callable Library, this one begins with calls to CPXopenCPLEX to initialize the ILOG CPLEX environment and to CPXcreateprob to create the problem object. Before it ends, it frees the problem object with a call to CPXfreeprob, and it frees the environment with a call to CPXcloseCPLEX.

In the routine setproblemdata, there are parameters for qmatbeg, qmatcnt, qmatind, and qmatval to fill the quadratic coefficient matrix. The Callable Library routine CPXcopyquad copies this data into the problem object created by the Callable Library routine CPXcreateprob.

In this example, the problem is a maximization, so the objective sense is specified as CPX_MAX.

The off-diagonal terms in the matrix Q are one-half the value of the terms x1x2, and x2x3 as they appear in the algebraic form of the example.

Instead of calling CPXlpopt to find a solution as for the linear programming problem in lpex1.c, this example calls CPXqpopt to optimize this quadratic programming problem.