12.07.2015 Views

ILOG CPLEX 11.0 User's Manual

ILOG CPLEX 11.0 User's Manual

ILOG CPLEX 11.0 User's Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ilolpex1.cpp counterpart. Here the objective function is created and added to the modellike 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 [] thatamounts to a quadratic and optional linear term can be used for building QP objectivefunction. Note that, if the expressions of the objective or any constraint of the modelcontains IloPiecewiseLinear, then when a quadratic objective is specified the modelbecomes an MIQP problem. (Piecewise-linearity is not the only characteristic that renders amodel MIQP. See also, for example, the features in Logical Constraints in Optimization onpage 349, where automatic transformation with logical constraints can render a problemMIQP.)The complete program iloqpex1.cpp appears online in the standard distribution atyour<strong>CPLEX</strong>installation/examples/src.Example: QPex1.javaThis example is almost identical to LPex1.java using only the function populatebyrowto create the model. Also, this function differs only in the creation of the objective from itsLPex1.java counterpart. Here the objective function is created and added to the model likethis:// Q = 0.5 ( 33*x0*x0 + 22*x1*x1 + 11*x2*x2 - 12*x0*x1 - 23*x1*x2 )IloNumExpr x00 = model.prod( 33, x[0], x[0]);IloNumExpr x11 = model.prod( 22, x[1], x[1]);IloNumExpr x22 = model.prod( 11, x[2], x[2]);IloNumExpr x01 = model.prod(-12, x[0], x[1]);IloNumExpr x12 = model.prod(-23, x[1], x[2]);IloNumExpr Q = model.prod(0.5, model.sum(x00, x11, x22, x01, x12));double[] objvals = {1.0, 2.0, 3.0};model.add(model.maximize(model.diff(model.scalProd(x, objvals), Q)));A quadratic objective may be built with square, prod or sum methods. Note that inclusionof IloPiecewiseLinear will change the model from a QP to a MIQP.Example: qpex1.cThis example shows you how to optimize a QP with routines from the <strong>ILOG</strong> <strong>CPLEX</strong>Callable Library when the problem data is stored in a file. The example derives fromlpex1.c discussed in <strong>ILOG</strong> <strong>CPLEX</strong> 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 inlpex1.c, this example calls CPXqpopt to optimize this quadratic programming problem.<strong>ILOG</strong> <strong>CPLEX</strong> <strong>11.0</strong> — USER’ S MANUAL 237

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!