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.

Step 6Set up rowsGo to the comment Step 6 in Dietlesson.cs, and add the following lines to set up yourapplication to build the model by rows.internal static void BuildModelByRow(IModeler model,Data data,INumVar[] Buy,NumVarType type) {int nFoods = data.nFoods;int nNutrs = data.nNutrs;Those lines begin the static method to build a model by rows. The next steps in this tutorialshow you the heart of that method.Step 7Create the variables: build and populate by rowsGo to the comment Step 7 in Dietlesson.cs, and add the following lines to create a loopthat creates the variables of the problem with the bounds specified by the input data.for (int j = 0; j < nFoods; j++) {Buy[j] = model.NumVar(data.foodMin[j], data.foodMax[j], type);}Step 8Add objectiveGo to the comment Step 8 in Dietlesson.cs, and add this statement to add the objectiveto the model.model.AddMinimize(model.ScalProd(data.foodCost, Buy));The objective function indicates that you want to minimize the cost of the diet computed asthe sum of the amount of each food to buy Buy[i] times the unit price of that fooddata.foodCost[i].102 <strong>ILOG</strong> <strong>CPLEX</strong> <strong>11.0</strong> — USER’ S MANUAL

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

Saved successfully!

Ooh no, something went wrong!