In this problem you will hack up an existing AMPL model of a diet problem. The problem is based on the little boxes of cereal in a Kellogg's Variety Pak.
1. Download the AMPL model in the file surreal.mod .
2. Solve the problem as it is given to you, and examine the answer:
ampl: model surreal.mod; ampl: solve; (AMPL and MINOS do their thing here...) ampl: display x; (AMPL will then display the answer.)
The objective value is given in calories.
Here is what you are expected to turn in: The minimum number of calories and the optimal solution found part 2.
3.
Next, drop the non-negativity constraints and solve the modified
problem. Report what you find. When you are done, make the
non-negativity constraint active again by removing the comment
indicator.
You can use AMPL's drop and restore commands
to temporarily drop and then restore the non-negativity constraint,
which is named Limit in surreal.mod.
You do this as follows;
ampl: drop Limit;
ampl: solve;
...
ampl: restore Limit;
These commands are discussed in detail on page 214 (2003 version or on
page 189 of the 1993 version) of the AMPL text.
Here is what you are expected to turn in: The results of the experiment in part 3.
4. As you will see, the optimal solution found in part 2 yields a rather limited and monotonous diet. In order to counteract this, we need to add constraints that will ensure a more varied diet. To this end, you should mathematically formulate and implement the following constraint(s):
Each cereal must constitute at least 10% of the total number of calories we consume.
Once you have added this constraint, resolve the problem and note the optimal objective value and new optimal solution. How does the new optimal objective value compare with that in the original problem in part 2? Explain.
Here is what you are expected to turn in: A mathematical formulation of the constraints you add in part 4, the new optimal objective value, and the new optimal solution. Also, a comparison of of the objective values in parts 2 and 4, and an explanation of what you find.
5. Continuing with the problem as modified in part 4, what happens to the LP if we require each cereal to constitute at least 15% of the total number of calories we consume? Explain. (Hint: there are 9 cereals.)
You can deduce the answer simply by thinking about it, but you should also make the change in the AMPL model and see what happens.
Here is what you are expected to turn in: The results of the experiment in part 5.
6. The implementation of the diet problem in the AMPL model surreal.mod is not particularly clever. In particular, the nutrients are all individual parameters, rather than a set, and as a consequence for every nutrient of interest there is a separate, explicit constraint rather than a cleverly indexed set of constraints. This makes it hard to add and delete nutrients.
Correct this deficiency along the lines of the diet problem in Sections 2.1--2.3 of the AMPL book. Among other things, you'll need to create a set of nutrients NUTR , and several indexed parameters, as follows:
set CEREALS;
set NUTR;
param Cal {CEREALS} >= 0; # Calories in each cereal
param Sugar {CEREALS} >= 0; # Sugar in each cereal
param nutr_req {NUTR} >= 0; # Amount of Daily Value (DV) required for
# each nutrient
param DV {CEREALS, NUTR} >= 0; # DV of each nutrient in each cereal
These declarations, and the declaration
var x {j in CEREALS} >= 0;
should be all you need to improve the code. You will also need to modify the data segment of the model. The result should be resemble the model in Section 2.1--2.3 of the AMPL book.
Another modification I want you to make is to eliminate the explicit non-negativity constraint Limit from the model and make the non-negativity constraints part of the variable declaration for x. See page 27 and pages 120-121 in the first edition of the AMPL book or page 31 and pages 130-131 in the second edition for examples of the syntax.
Finally, you should add some sanity checks to the declarations of
the parameters. In particular, add checks that insure the parameters
are non-negative.
Feel free to make any other improvements to the code that your
good taste leads you to think appropriate. My version is, by design,
rather messy, and there is much room for improvement.
Be sure to check that your modified version of surreal.mod
gives the same results as the original surreal.mod. It's
not an improved implementation if it gives bogus answers!
Here is what you are expected to turn in: Your tidied-up AMPL code (model and data) from part 6. Please submit this by e-mail!!