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.

Step 9Add nutritional constraintsGo to the comment Step 9 in Dietlesson.cs, and add the following lines to add theranged nutritional constraints to the model.}for (int i = 0; i < nNutrs; i++) {model.AddRange(data.nutrMin[i],model.ScalProd(data.nutrPerFood[i], Buy),data.nutrMax[i]);}Build by ColumnsAs noted in Build by Rows on page 101, the finished application is capable of building amodel by rows or by columns, according to an option entered through the command line bythe user. The next steps in this tutorial show you how to add a static method to yourapplication to build a model by columns.Step 10Set up columnsGo to the comment Step 10 in Dietlesson.cs, and add the following lines to set up yourapplication to build the problem by columns.internal static void BuildModelByColumn(IMPModeler model,Data data,INumVar[] Buy,NumVarType type) {int nFoods = data.nFoods;int nNutrs = data.nNutrs;Those lines begin a static method that the next steps will complete.Step 11Add empty objective function and constraintsGo to the comment Step 11 in Dietlesson.cs, and add the following lines to create emptycolumns that will hold the objective and ranged constraints of your problem.IObjective cost = model.AddMinimize();IRange[] constraint = new IRange[nNutrs];for (int i = 0; i < nNutrs; i++) {constraint[i] = model.AddRange(data.nutrMin[i], data.nutrMax[i]);}<strong>ILOG</strong> <strong>CPLEX</strong> <strong>11.0</strong> — USER’ S MANUAL 103

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

Saved successfully!

Ooh no, something went wrong!