ILOG CPLEX 11.0 User's Manual > Languages and APIs > ILOG Concert Technology for .NET Users > Model > Build by Columns

As noted in Build by Rows, 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 to build a model by columns.

Step 10   -  

Set up columns

Go to the comment Step 10 in Dietlesson.cs, and add the following lines to set up your application 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 11   -  

Add empty objective function and constraints

Go to the comment Step 11 in Dietlesson.cs, and add the following lines to create empty columns 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]);
      }

Step 12   -  

Create variables

Go to the comment Step 12 in Dietlesson.cs, and add the following lines to create each of 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 for that food is to be added to the objective function and constraints. Then that column object is used to construct the variable Buy[j] that represents the amount of food j to be purchased for the diet. At this time, the new variable will be installed in the objective function and constraints as defined by the column object col.