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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Creating a Model Row by RowYou walk into the store and compile a list of foods that are offered. For each food, you storethe price per unit and the amount they have in stock. For some foods that you particularlylike, you also set a minimum amount you would like to use in your diet. Then for each of thefoods you create a modeling variable to represent the quantity to be purchased for your diet.Now you get a medical book and look up which nutrients are known and relevant for you.For each nutrient, you note the minimum and maximum amount that should be found in yourdiet. Also, you go through the list of foods and decide how much a food item will contributefor each nutrient. This gives you one constraint per nutrient, which can naturally berepresented as a range constraintnutrmin[i] ≤ ∑ j (nutrper[i][j] * buy[j]) ≤ nutrmax[i]where i represents the index of the nutrient under consideration, nutrmin[i] andnutrmax[i] the minimum and maximum amount of nutrient i and nutrper[i][j] theamount of nutrient i in food j. Finally, you specify your objective function to minimize, likethis:cost = ∑ j (cost[j] * buy[j])This way to create the model is shown in function populatebyrow in example diet.c.Creating a Model Column by ColumnYou start with the medical book where you compile the list of nutrients that you want tomake sure are properly represented in your diet. For each of the nutrients, you create anempty constraint:nutrmin[i] ≤ ... ≤ nutrmax[i]where ... is left to be filled once you walk into your store. You also set up the objectivefunction to minimize the cost. Constraint i is referred to as rng[i] and the objective isreferred to as cost.Now you walk into the store and, for each food, you check its price and nutritional content.With this data you create a variable representing the amount you want to buy of the foodtype and install it in the objective function and constraints. That is you create the followingcolumn:cost(foodCost[j]) "+" "sum_i" (rng[i](nutrper[i][j]))where the notation "+" and "sum" indicates that you “add” the new variable j to theobjective cost and constraints rng[i]. The value in parentheses is the linear coefficientthat is used for the new variable.126 <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!