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 12Create variablesGo to the comment Step 12 in Dietlesson.cs, and add the following lines to create eachof the variables.for (int j = 0; j < nFoods; j++) {Column col = model.Column(cost, data.foodCost[j]);for (int i = 0; i < nNutrs; i++) {col = col.And(model.Column(constraint[i],data.nutrPerFood[i][j]));}Buy[j] = model.NumVar(col, data.foodMin[j], data.foodMax[j], type);}}For each food j, a column object col is first created to represent how the new variable forthat food is to be added to the objective function and constraints. Then that column object isused to construct the variable Buy[j] that represents the amount of food j to be purchasedfor the diet. At this time, the new variable will be installed in the objective function andconstraints as defined by the column object col.SolveAfter you have added lines to your application to build a model, you are ready for the nextsteps: adding lines for solving and displaying the solution.Step 13SolveGo to the comment Step 13 in Dietlesson.cs, and add this statement to solve theproblem.if ( cplex.Solve() ) {104 <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!