> Languages and APIs > ILOG Concert Technology for C#.NET Users > Model > Build by Rows |
Build by Rows |
INDEX PREVIOUS NEXT |
The finished application is capable of building a model by rows or by columns, according to an option entered through the command line by the user. The next steps in this tutorial show you how to add a static method to your application. This method builds a model by rows.
Step 6 - | Set up rows |
Go to the comment Step 6 in Dietlesson.cs
, and add the following lines to set up your application 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 tutorial show you the heart of that method.
Step 7 - | Create the variables: build and populate by rows |
Go to the comment Step 7 in Dietlesson.cs
, and add the following lines to create a loop that 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 8 - | Add objective |
Go to the comment Step 8 in Dietlesson.cs
, and add this statement to add the objective to the model.
model.AddMinimize(model.ScalProd(data.foodCost, Buy)); |
The objective function indicates that you want to minimize the cost of the diet computed as the sum of the amount of each food to buy Buy[i]
times the unit price of that food data.foodCost[i]
.
Step 9 - | Add nutritional constraints |
Go to the comment Step 9 in Dietlesson.cs
, and add the following lines to add the ranged 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]); } } |
Copyright © 1987-2003 ILOG, S.A. All rights reserved. Legal terms. | PREVIOUS NEXT |