examples/stigler.mod
changeset 1 c445c931472f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/examples/stigler.mod	Mon Dec 06 13:09:21 2010 +0100
     1.3 @@ -0,0 +1,411 @@
     1.4 +/* STIGLER, original Stigler's 1939 diet problem */
     1.5 +
     1.6 +/* The Stigler Diet is an optimization problem named for George Stigler,
     1.7 +   a 1982 Nobel Laureate in economics, who posed the following problem:
     1.8 +   For a moderately active man weighing 154 pounds, how much of each of
     1.9 +   77 foods should be eaten on a daily basis so that the man's intake of
    1.10 +   nine nutrients will be at least equal to the recommended dietary
    1.11 +   allowances (RDSs) suggested by the National Research Council in 1943,
    1.12 +   with the cost of the diet being minimal?
    1.13 +
    1.14 +   The nutrient RDAs required to be met in Stigler's experiment were
    1.15 +   calories, protein, calcium, iron, vitamin A, thiamine, riboflavin,
    1.16 +   niacin, and ascorbic acid. The result was an annual budget allocated
    1.17 +   to foods such as evaporated milk, cabbage, dried navy beans, and beef
    1.18 +   liver at a cost of approximately $0.11 a day in 1939 U.S. dollars.
    1.19 +
    1.20 +   While the name "Stigler Diet" was applied after the experiment by
    1.21 +   outsiders, according to Stigler, "No one recommends these diets for
    1.22 +   anyone, let alone everyone." The Stigler diet has been much ridiculed
    1.23 +   for its lack of variety and palatability, however his methodology has
    1.24 +   received praise and is considered to be some of the earliest work in
    1.25 +   linear programming.
    1.26 +
    1.27 +   The Stigler diet question is a linear programming problem. Lacking
    1.28 +   any sophisticated method of solving such a problem, Stigler was
    1.29 +   forced to utilize heuristic methods in order to find a solution. The
    1.30 +   diet question originally asked in which quantities a 154 pound male
    1.31 +   would have to consume 77 different foods in order to fulfill the
    1.32 +   recommended intake of 9 different nutrients while keeping expense at
    1.33 +   a minimum. Through "trial and error, mathematical insight and
    1.34 +   agility," Stigler was able to eliminate 62 of the foods from the
    1.35 +   original 77 (these foods were removed based because they lacked
    1.36 +   nutrients in comparison to the remaining 15). From the reduced list,
    1.37 +   Stigler calculated the required amounts of each of the remaining 15
    1.38 +   foods to arrive at a cost-minimizing solution to his question.
    1.39 +   According to Stigler's calculations, the annual cost of his solution
    1.40 +   was $39.93 in 1939 dollars. When corrected for inflation using the
    1.41 +   consumer price index, the cost of the diet in 2005 dollars is
    1.42 +   $561.43. The specific combination of foods and quantities is as
    1.43 +   follows:
    1.44 +
    1.45 +   Stigler's 1939 Diet
    1.46 +
    1.47 +   Food             Annual Quantities Annual Cost
    1.48 +   ---------------- ----------------- -----------
    1.49 +   Wheat Flour           370 lb.         $13.33
    1.50 +   Evaporated Milk        57 cans          3.84
    1.51 +   Cabbage               111 lb.           4.11
    1.52 +   Spinach                23 lb.           1.85
    1.53 +   Dried Navy Beans      285 lb.          16.80
    1.54 +   ----------------------------------------------
    1.55 +   Total Annual Cost                     $39.93
    1.56 +
    1.57 +   The 9 nutrients that Stigler's diet took into consideration and their
    1.58 +   respective recommended daily amounts were:
    1.59 +
    1.60 +   Table of nutrients considered in Stigler's diet
    1.61 +
    1.62 +   Nutrient                  Daily Recommended Intake
    1.63 +   ------------------------- ------------------------
    1.64 +   Calories                       3,000 Calories
    1.65 +   Protein                           70 grams
    1.66 +   Calcium                           .8 grams
    1.67 +   Iron                              12 milligrams
    1.68 +   Vitamin A                      5,000 IU
    1.69 +   Thiamine (Vitamin B1)            1.8 milligrams
    1.70 +   Riboflavin (Vitamin B2)          2.7 milligrams
    1.71 +   Niacin                            18 milligrams
    1.72 +   Ascorbic Acid (Vitamin C)         75 milligrams
    1.73 +
    1.74 +   Seven years after Stigler made his initial estimates, the development
    1.75 +   of George Dantzig's Simplex algorithm made it possible to solve the
    1.76 +   problem without relying on heuristic methods. The exact value was
    1.77 +   determined to be $39.69 (using the original 1939 data). Dantzig's
    1.78 +   algorithm describes a method of traversing the vertices of a polytope
    1.79 +   of N+1 dimensions in order to find the optimal solution to a specific
    1.80 +   situation.
    1.81 +
    1.82 +   (From Wikipedia, the free encyclopedia.) */
    1.83 +
    1.84 +/* Translated from GAMS by Andrew Makhorin <mao@gnu.org>.
    1.85 +
    1.86 +   For the original GAMS model stigler1939.gms see [3].
    1.87 +
    1.88 +   References:
    1.89 +
    1.90 +   1. George J. Stigler, "The Cost of Subsistence," J. Farm Econ. 27,
    1.91 +      1945, pp. 303-14.
    1.92 +
    1.93 +   2. National Research Council, "Recommended Daily Allowances," Reprint
    1.94 +      and Circular Series No. 115, January, 1943.
    1.95 +
    1.96 +   3. Erwin Kalvelagen, "Model building with GAMS," Chapter 2, "Building
    1.97 +      linear programming models," pp. 128-34. */
    1.98 +
    1.99 +set C;
   1.100 +/* commodities */
   1.101 +
   1.102 +check card(C) = 77;
   1.103 +/* there must be 77 commodities */
   1.104 +
   1.105 +set N;
   1.106 +/* nutrients */
   1.107 +
   1.108 +param data{c in C, {"price", "weight"} union N};
   1.109 +/* nutritive values per dollar of expenditure */
   1.110 +
   1.111 +param allowance{n in N};
   1.112 +/* recommended daily allowance for a moderately active man */
   1.113 +
   1.114 +var x{c in C}, >= 0;
   1.115 +/* dollars of food to be purchased daily */
   1.116 +
   1.117 +s.t. nb{n in N}: sum{c in C} data[c,n] * x[c] >= allowance[n];
   1.118 +/* nutrient balance */
   1.119 +
   1.120 +minimize cost: sum{c in C} x[c];
   1.121 +/* total food bill */
   1.122 +
   1.123 +solve;
   1.124 +
   1.125 +param days := 365.25;
   1.126 +/* days in a year */
   1.127 +
   1.128 +param commodity{c in C}, symbolic;
   1.129 +
   1.130 +param unit{c in C}, symbolic;
   1.131 +
   1.132 +printf "\n";
   1.133 +printf "MINIMUM COST ANNUAL DIET\n";
   1.134 +printf "\n";
   1.135 +printf "        Commodity            Unit     Quantity     Cost   \n";
   1.136 +printf "------------------------- ---------- ---------- ----------\n";
   1.137 +printf{c in C: x[c] != 0} "%-25s %10s %10.2f   $%7.2f\n", commodity[c],
   1.138 +   unit[c], 100 * days * x[c] / data[c,"price"], days * x[c];
   1.139 +printf "                                         -----------------\n";
   1.140 +printf "                                         Total:   $%7.2f\n",
   1.141 +   days * sum{c in C} x[c];
   1.142 +printf "\n";
   1.143 +
   1.144 +data;
   1.145 +
   1.146 +param : C :    commodity                   unit :=
   1.147 +flour          "Wheat Flour (Enriched)"    "10 lb."
   1.148 +macaroni       "Macaroni"                  "1 lb."
   1.149 +cereal         "Wheat Cereal (Enriched)"   "28 oz."
   1.150 +cornflakes     "Corn Flakes"               "8 oz."
   1.151 +cornmeal       "Corn Meal"                 "1 lb."
   1.152 +grits          "Hominy Grits"              "24 oz."
   1.153 +rice           "Rice"                      "1 lb."
   1.154 +oats           "Rolled Oats"               "1 lb."
   1.155 +whitebread     "White Bread (Enriched)"    "1 lb."
   1.156 +wheatbread     "Whole Wheat Bread"         "1 lb."
   1.157 +ryebread       "Rye Bread"                 "1 lb."
   1.158 +poundcake      "Pound Cake"                "1 lb."
   1.159 +crackers       "Soda Crackers"             "1 lb."
   1.160 +milk           "Milk"                      "1 qt."
   1.161 +evapmild       "Evaporated Milk (can)"     "14.5 oz."
   1.162 +butter         "Butter"                    "1 lb."
   1.163 +margarine      "Oleomargarine"             "1 lb."
   1.164 +eggs           "Eggs"                      "1 doz."
   1.165 +cheese         "Cheese (Cheddar)"          "1 lb."
   1.166 +cream          "Cream"                     "1/2 pt."
   1.167 +peanutbutter   "Peanut Butter"             "1 lb."
   1.168 +mayonnaise     "Mayonnaise"                "1/2 pt."
   1.169 +crisco         "Crisco"                    "1 lb."
   1.170 +lard           "Lard"                      "1 lb."
   1.171 +sirloinsteak   "Sirloin Steak"             "1 lb."
   1.172 +roundsteak     "Round Steak"               "1 lb."
   1.173 +ribroast       "Rib Roast"                 "1 lb."
   1.174 +chuckroast     "Chuck Roast"               "1 lb."
   1.175 +plate          "Plate"                     "1 lb."
   1.176 +liver          "Liver (Beef)"              "1 lb."
   1.177 +lambleg        "Leg of Lamb"               "1 lb."
   1.178 +lambchops      "Lamb Chops (Rib)"          "1 lb."
   1.179 +porkchops      "Pork Chops"                "1 lb."
   1.180 +porkroast      "Pork Loin Roast"           "1 lb."
   1.181 +bacon          "Bacon"                     "1 lb."
   1.182 +ham            "Ham - smoked"              "1 lb."
   1.183 +saltpork       "Salt Pork"                 "1 lb."
   1.184 +chicken        "Roasting Chicken"          "1 lb."
   1.185 +veal           "Veal Cutlets"              "1 lb."
   1.186 +salmon         "Salmon, Pink (can)"        "16 oz."
   1.187 +apples         "Apples"                    "1 lb."
   1.188 +bananas        "Bananas"                   "1 lb."
   1.189 +lemons         "Lemons"                    "1 doz."
   1.190 +oranges        "Oranges"                   "1 doz."
   1.191 +greenbeans     "Green Beans"               "1 lb."
   1.192 +cabbage        "Cabbage"                   "1 lb."
   1.193 +carrots        "Carrots"                   "1 bunch"
   1.194 +celery         "Celery"                    "1 stalk"
   1.195 +lettuce        "Lettuce"                   "1 head"
   1.196 +onions         "Onions"                    "1 lb."
   1.197 +potatoes       "Potatoes"                  "15 lb."
   1.198 +spinach        "Spinach"                   "1 lb."
   1.199 +sweetpotato    "Sweet Potatoes"            "1 lb."
   1.200 +peaches        "Peaches (can)"             "No. 2 1/2"
   1.201 +pears          "Pears (can)"               "No. 2 1/2"
   1.202 +pineapple      "Pineapple (can)"           "No. 2 1/2"
   1.203 +asparagus      "Asparagus (can)"           "No. 2"
   1.204 +cannedgrbn     "Grean Beans (can)"         "No. 2"
   1.205 +porkbeans      "Pork and Beans (can)"      "16 oz."
   1.206 +corn           "Corn (can)"                "No. 2"
   1.207 +peas           "Peas (can)"                "No. 2"
   1.208 +tomatoes       "Tomatoes (can)"            "No. 2"
   1.209 +tomatosoup     "Tomato Soup (can)"         "10 1/2 oz."
   1.210 +driedpeach     "Peaches, Dried"            "1 lb."
   1.211 +prunes         "Prunes, Dried"             "1 lb."
   1.212 +raisins        "Raisins, Dried"            "15 oz."
   1.213 +driedpeas      "Peas, Dried"               "1 lb."
   1.214 +limabeans      "Lima Beans, Dried"         "1 lb."
   1.215 +navybeans      "Navy Beans, Dried"         "1 lb."
   1.216 +coffee         "Coffee"                    "1 lb."
   1.217 +tea            "Tea"                       "1/4 lb."
   1.218 +cocoa          "Cocoa"                     "8 oz."
   1.219 +chocolate      "Chocolate"                 "8 oz."
   1.220 +sugar          "Sugar"                     "10 lb."
   1.221 +cornsirup      "Corn Sirup"                "24 oz."
   1.222 +molasses       "Molasses"                  "18 oz."
   1.223 +stawberry      "Strawberry Preserve"       "1 lb."
   1.224 +;
   1.225 +
   1.226 +set N :=
   1.227 +calories       /* Calories, unit = 1000 */
   1.228 +protein        /* Protein, unit = grams */
   1.229 +calcium        /* Calcium, unit = grams */
   1.230 +iron           /* Iron, unit = milligrams */
   1.231 +vitaminA       /* Vitamin A, unit = 1000 International Units */
   1.232 +thiamine       /* Thiamine, Vit. B1, unit = milligrams */
   1.233 +riboflavin     /* Riboflavin, Vit. B2, unit = milligrams */
   1.234 +niacin         /* Niacin (Nicotinic Acid), unit = milligrams */
   1.235 +ascorbicAcid   /* Ascorbic Acid, Vit. C, unit = milligrams */
   1.236 +;
   1.237 +
   1.238 +param data
   1.239 +:             price   weight calories protein  calcium   iron :=
   1.240 +#            aug. 15  edible
   1.241 +#             1939    per $1
   1.242 +#           (cents)   (grams) (1000)  (grams)  (grams)   (mg.)
   1.243 +flour         36.0    12600    44.7     1411     2.0      365
   1.244 +macaroni      14.1     3217    11.6      418      .7       54
   1.245 +cereal        24.2     3280    11.8      377    14.4      175
   1.246 +cornflakes     7.1     3194    11.4      252      .1       56
   1.247 +cornmeal       4.6     9861    36.0      897     1.7       99
   1.248 +grits          8.5     8005    28.6      680      .8       80
   1.249 +rice           7.5     6048    21.2      460      .6       41
   1.250 +oats           7.1     6389    25.3      907     5.1      341
   1.251 +whitebread     7.9     5742    15.6      488     2.5      115
   1.252 +wheatbread     9.1     4985    12.2      484     2.7      125
   1.253 +ryebread       9.2     4930    12.4      439     1.1       82
   1.254 +poundcake     24.8     1829     8.0      130      .4       31
   1.255 +crackers      15.1     3004    12.5      288      .5       50
   1.256 +milk          11.0     8867     6.1      310    10.5       18
   1.257 +evapmild       6.7     6035     8.4      422    15.1        9
   1.258 +butter        20.8     1473    10.8        9      .2        3
   1.259 +margarine     16.1     2817    20.6       17      .6        6
   1.260 +eggs          32.6     1857     2.9      238     1.0       52
   1.261 +cheese        24.2     1874     7.4      448    16.4       19
   1.262 +cream         14.1     1689     3.5       49     1.7        3
   1.263 +peanutbutter  17.9     2534    15.7      661     1.0       48
   1.264 +mayonnaise    16.7     1198     8.6       18      .2        8
   1.265 +crisco        20.3     2234    20.1        0      .0        0
   1.266 +lard           9.8     4628    41.7        0      .0        0
   1.267 +sirloinsteak  39.6     1145     2.9      166      .1       34
   1.268 +roundsteak    36.4     1246     2.2      214      .1       32
   1.269 +ribroast      29.2     1553     3.4      213      .1       33
   1.270 +chuckroast    22.6     2007     3.6      309      .2       46
   1.271 +plate         14.6     3107     8.5      404      .2       62
   1.272 +liver         26.8     1692     2.2      333      .2      139
   1.273 +lambleg       27.6     1643     3.1      245      .1       20
   1.274 +lambchops     36.6     1239     3.3      140      .1       15
   1.275 +porkchops     30.7     1477     3.5      196      .2       80
   1.276 +porkroast     24.2     1874     4.4      249      .3       37
   1.277 +bacon         25.6     1772    10.4      152      .2       23
   1.278 +ham           27.4     1655     6.7      212      .2       31
   1.279 +saltpork      16.0     2835    18.8      164      .1       26
   1.280 +chicken       30.3     1497     1.8      184      .1       30
   1.281 +veal          42.3     1072     1.7      156      .1       24
   1.282 +salmon        13.0     3489     5.8      705     6.8       45
   1.283 +apples         4.4     9072     5.8       27      .5       36
   1.284 +bananas        6.1     4982     4.9       60      .4       30
   1.285 +lemons        26.0     2380     1.0       21      .5       14
   1.286 +oranges       30.9     4439     2.2       40     1.1       18
   1.287 +greenbeans     7.1     5750     2.4      138     3.7       80
   1.288 +cabbage        3.7     8949     2.6      125     4.0       36
   1.289 +carrots        4.7     6080     2.7       73     2.8       43
   1.290 +celery         7.3     3915      .9       51     3.0       23
   1.291 +lettuce        8.2     2247      .4       27     1.1       22
   1.292 +onions         3.6    11844     5.8      166     3.8       59
   1.293 +potatoes      34.0    16810    14.3      336     1.8      118
   1.294 +spinach        8.1     4592     1.1      106      .0      138
   1.295 +sweetpotato    5.1     7649     9.6      138     2.7       54
   1.296 +peaches       16.8     4894     3.7       20      .4       10
   1.297 +pears         20.4     4030     3.0        8      .3        8
   1.298 +pineapple     21.3     3993     2.4       16      .4        8
   1.299 +asparagus     27.7     1945      .4       33      .3       12
   1.300 +cannedgrbn    10.0     5386     1.0       54     2.0       65
   1.301 +porkbeans      7.1     6389     7.5      364     4.0      134
   1.302 +corn          10.4     5452     5.2      136      .2       16
   1.303 +peas          13.8     4109     2.3      136      .6       45
   1.304 +tomatoes       8.6     6263     1.3       63      .7       38
   1.305 +tomatosoup     7.6     3917     1.6       71      .6       43
   1.306 +driedpeach    15.7     2889     8.5       87     1.7      173
   1.307 +prunes         9.0     4284    12.8       99     2.5      154
   1.308 +raisins        9.4     4524    13.5      104     2.5      136
   1.309 +driedpeas      7.9     5742    20.0     1367     4.2      345
   1.310 +limabeans      8.9     5097    17.4     1055     3.7      459
   1.311 +navybeans      5.9     7688    26.9     1691    11.4      792
   1.312 +coffee        22.4     2025      .0        0      .0        0
   1.313 +tea           17.4      652      .0        0      .0        0
   1.314 +cocoa          8.6     2637     8.7      237     3.0       72
   1.315 +chocolate     16.2     1400     8.0       77     1.3       39
   1.316 +sugar         51.7     8773    34.9        0      .0        0
   1.317 +cornsirup     13.7     4996    14.7        0      .5       74
   1.318 +molasses      13.6     3752     9.0        0    10.3      244
   1.319 +stawberry     20.5     2213     6.4       11      .4        7
   1.320 +
   1.321 +:           vitaminA thiamine riboflavin  niacin  ascorbicAcid :=
   1.322 +#          (1000 IU)  (mg.)      (mg.)     (mg.)     (mg.)
   1.323 +flour           .0    55.4       33.3       441         0
   1.324 +macaroni        .0     3.2        1.9        68         0
   1.325 +cereal          .0    14.4        8.8       114         0
   1.326 +cornflakes      .0    13.5        2.3        68         0
   1.327 +cornmeal      30.9    17.4        7.9       106         0
   1.328 +grits           .0    10.6        1.6       110         0
   1.329 +rice            .0     2.0        4.8        60         0
   1.330 +oats            .0    37.1        8.9        64         0
   1.331 +whitebread      .0    13.8        8.5       126         0
   1.332 +wheatbread      .0    13.9        6.4       160         0
   1.333 +ryebread        .0     9.9        3.0        66         0
   1.334 +poundcake     18.9     2.8        3.0        17         0
   1.335 +crackers        .0      .0         .0         0         0
   1.336 +milk          16.8     4.0       16.0         7       177
   1.337 +evapmild      26.0     3.0       23.5        11        60
   1.338 +butter        44.2      .0         .2         2         0
   1.339 +margarine     55.8      .2         .0         0         0
   1.340 +eggs          18.6     2.8        6.5         1         0
   1.341 +cheese        28.1      .8       10.3         4         0
   1.342 +cream         16.9      .6        2.5         0        17
   1.343 +peanutbutter    .0     9.6        8.1       471         0
   1.344 +mayonnaise     2.7      .4         .5         0         0
   1.345 +crisco          .0      .0         .0         0         0
   1.346 +lard            .2      .0         .5         5         0
   1.347 +sirloinsteak    .2     2.1        2.9        69         0
   1.348 +roundsteak      .4     2.5        2.4        87         0
   1.349 +ribroast        .0      .0        2.0         0         0
   1.350 +chuckroast      .4     1.0        4.0       120         0
   1.351 +plate           .0      .9         .0         0         0
   1.352 +liver        169.2     6.4       50.8       316       525
   1.353 +lambleg         .0     2.8        3.0        86         0
   1.354 +lambchops       .0     1.7        2.7        54         0
   1.355 +porkchops       .0    17.4        2.7        60         0
   1.356 +porkroast       .0    18.2        3.6        79         0
   1.357 +bacon           .0     1.8        1.8        71         0
   1.358 +ham             .0     9.9        3.3        50         0
   1.359 +saltpork        .0     1.4        1.8         0         0
   1.360 +chicken         .1      .9        1.8        68        46
   1.361 +veal            .0     1.4        2.4        57         0
   1.362 +salmon         3.5     1.0        4.9       209         0
   1.363 +apples         7.3     3.6        2.7         5       544
   1.364 +bananas       17.4     2.5        3.5        28       498
   1.365 +lemons          .0      .5         .0         4       952
   1.366 +oranges       11.1     3.6        1.3        10      1993
   1.367 +greenbeans    69.0     4.3        5.8        37       862
   1.368 +cabbage        7.2     9.0        4.5        26      5369
   1.369 +carrots      188.5     6.1        4.3        89       608
   1.370 +celery          .9     1.4        1.4         9       313
   1.371 +lettuce      112.4     1.8        3.4        11       449
   1.372 +onions        16.6     4.7        5.9        21      1184
   1.373 +potatoes       6.7    29.4        7.1       198      2522
   1.374 +spinach      918.4     5.7       13.8        33      2755
   1.375 +sweetpotato  290.7     8.4        5.4        83      1912
   1.376 +peaches       21.5      .5        1.0        31       196
   1.377 +pears           .8      .8         .8         5        81
   1.378 +pineapple      2.0     2.8         .8         7       399
   1.379 +asparagus     16.3     1.4        2.1        17       272
   1.380 +cannedgrbn    53.9     1.6        4.3        32       431
   1.381 +porkbeans      3.5     8.3        7.7        56         0
   1.382 +corn          12.0     1.6        2.7        42       218
   1.383 +peas          34.9     4.9        2.5        37       370
   1.384 +tomatoes      53.2     3.4        2.5        36      1253
   1.385 +tomatosoup    57.9     3.5        2.4        67       862
   1.386 +driedpeach    86.8     1.2        4.3        55        57
   1.387 +prunes        85.7     3.9        4.3        65       257
   1.388 +raisins        4.5     6.3        1.4        24       136
   1.389 +driedpeas      2.9    28.7       18.4       162         0
   1.390 +limabeans      5.1    26.9       38.2        93         0
   1.391 +navybeans       .0    38.4       24.6       217         0
   1.392 +coffee          .0     4.0        5.1        50         0
   1.393 +tea             .0      .0        2.3        42         0
   1.394 +cocoa           .0     2.0       11.9        40         0
   1.395 +chocolate       .0      .9        3.4        14         0
   1.396 +sugar           .0      .0         .0         0         0
   1.397 +cornsirup       .0      .0         .0         5         0
   1.398 +molasses        .0     1.9        7.5       146         0
   1.399 +stawberry       .2      .2         .4         3         0
   1.400 +;
   1.401 +
   1.402 +param allowance :=
   1.403 +calories       3
   1.404 +protein       70
   1.405 +calcium         .8
   1.406 +iron          12
   1.407 +vitaminA       5
   1.408 +thiamine       1.8
   1.409 +riboflavin     2.7
   1.410 +niacin        18
   1.411 +ascorbicAcid  75
   1.412 +;
   1.413 +
   1.414 +end;