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 Row by Row |
Creating a Model Row by Row |
INDEX
![]() |
You walk into the store and compile a list of foods that are offered. For each food, you store the price per unit and the amount in stock. For some foods that you particularly like, you also set a minimum amount you would like to use in your diet. Then, for each of the foods, you create a modeling variable to represent the quantity to be purchased for your diet.
Now you get a nutrition book and look up which nutrients are known and relevant for you. For each nutrient, you note the minimum and maximum amounts that should be found in your diet. Also, you go through the list of foods and determine how much a food item will contribute for each nutrient. This gives you one constraint per nutrient, which can naturally be represented as a range constraint in pseudo-code like this:
where i
represents the number of the nutrient under consideration, nutrMin[i]
and nutrMax[i]
the minimum and maximum amount of nutrient i
and nutrPer[i][j]
the amount of nutrient i
in food j
.
Finally, you specify your objective function in pseudo-code like this:
The loop in the example combines those two ideas and looks like this:
This way of creating the model appears in the function buildModelByRow
, in the example ilodiet.cpp
.
Copyright © 1987-2007 ILOG S.A. All rights reserved. Legal terms. | PREVIOUS NEXT |