ILOG CPLEX 10.2 User's Manual > Languages and APIs > ILOG Concert Technology for C++ Users > Example: Optimizing the Diet Problem in C++ > Creating a Model Column by Column

You start with the nutrition book where you compile the list of nutrients that you want to make sure are properly represented in your diet. For each of the nutrients, you create an empty constraint:

nutrMin[i] ... nutrMax[i]

where ... is left to be filled once you walk into the store. Also, you set up the objective function to minimize the cost. Constraint i is referred to as range[i] and to the objective as cost.

Now you walk into the store and, for each food, you check the price and nutritional content. With this data you create a variable representing the amount you want to buy of the food type and install the variable in the objective function and constraints. That is, you create the following column in pseudo code, like this:

cost(foodCost[j]) "+" "sum_i" (range[i](nutrPer[i][j])) 

where the notation + and sum indicate in pseudo code that you add the new variable j to the objective cost and constraints range[i]. The value in parentheses is the linear coefficient that is used for the new variable. This notation is similar to the syntax actually used in Concert Technology, as demonstrated in the function buildModelByColumn, in the example ilodiet.cpp.

   for (j = 0; j < n; j++) {
      IloNumColumn col = cost(foodCost[j]);
      for (i = 0; i < m; i++) {
         col += range[i](nutrPer[i][j]);
      }
      Buy.add(IloNumVar(col, foodMin[j], foodMax[j], type));
      col.end();
   }