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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

data and return an array of modeling variables as an instance of the class IloNumVarArray.At that point, Buy is assigned to an initialized handle containing all the modeling variablesand can be used afterwards.Building the Model by RowThe model is created by rows using the function buildModelByRow. It first gets theenvironment from the model object passed to it. Then the modeling variables Buy arecreated. Instead of calling the constructor for the variables individually for each variable,create the full array of variables, with the array of lower and upper bounds and the variabletype as parameter. In this array, variable Buy[i] is created such that it has lower boundfoodMin[i], upper bound foodMax[i], and type indicated by type.The statement:mod.add(IloMinimize(env, IloScalProd(Buy, foodCost)));creates the objective function and adds it to the model. The IloScalProd function createsthe expression ∑j (Buy[j] * foodCost[j]) which is then passed to the functionIloMinimize. That function creates and returns the actual IloObjective object, which isadded to the model with the call mod.add.The following loop creates the constraints of the problem one by one and adds them to themodel. First the expression ∑j (Buy[j] * nutrPer[i][j]) is created by building aConcert Technology expression. An expression variable expr of type IloExpr is created,and linear terms are added to it by using operator+= in a loop. The expression is used withthe overloaded operator

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

Saved successfully!

Ooh no, something went wrong!