The Linear Programming Solver

Example 8.1: Diet Problem

Consider the problem of diet optimization. There are six different foods: bread, milk, cheese, potato, fish, and yogurt. The cost and nutrition values per unit are displayed in Table 8.2.

Table 8.2: Cost and Nutrition Values
  Bread Milk Cheese Potato Fish Yogurt
Cost2.03.58.01.511.01.0
Protein, g4.08.07.01.38.09.2
Fat, g1.05.09.00.17.01.0
Carbohydrates, g15.011.70.422.60.017.0
Calories9012010697130180

The following SAS code creates the data set fooddata of Table 8.2:

 data fooddata;
 infile datalines;
 input    name $  cost  prot  fat  carb  cal;
 datalines;                      
          Bread   2     4     1    15    90
          Milk    3.5   8     5    11.7  120
          Cheese  8     7     9    0.4   106
          Potato  1.5   1.3   0.1  22.6  97
          Fish    11    8     7    0     130
          Yogurt  1     9.2   1    17    180
 ;
 run;
 

The objective is to find a minimum-cost diet that contains at least 300 calories, not more than 10 grams of protein, not less than 10 grams of carbohydrates, and not less than 8 grams of fat. In addition, the diet should contain at least 0.5 unit of fish and no more than 1 unit of milk.

You can model the problem and solve it by using PROC OPTMODEL as follows:

    proc optmodel;
       /* declare index set */
       set<str> FOOD;
       
       /* declare variables */
       var diet{FOOD} >= 0;
       
       /* objective function */
       num cost{FOOD};
       min f=sum{i in FOOD}cost[i]*diet[i];
       
       /* constraints */
       num prot{FOOD};
       num fat{FOOD};
       num carb{FOOD}; 
       num cal{FOOD};
       num min_cal, max_prot, min_carb, min_fat;
       con cal_con: sum{i in FOOD}cal[i]*diet[i] >= 300;
       con prot_con: sum{i in FOOD}prot[i]*diet[i] <= 10;
       con carb_con: sum{i in FOOD}carb[i]*diet[i] >= 10;
       con fat_con: sum{i in FOOD}fat[i]*diet[i] >= 8;
       
       /* read parameters */
       read data fooddata into FOOD=[name] cost prot fat carb cal;
       
       /* bounds on variables */
       diet['Fish'].lb = 0.5;
       diet['Milk'].ub = 1.0;
       
       /* solve and print the optimal solution */
       solve with lp/printfreq=1; /* print each iteration to log */
       print diet;
 

The optimal solution and the optimal objective value are displayed in Output 8.1.1.

Output 8.1.1: Optimal Solution to the Diet Problem
The OPTMODEL Procedure

Solution Summary
Solver Dual Simplex
Objective Function f
Solution Status Optimal
Objective Value 12.081337881
Iterations 4
   
Primal Infeasibility 0
Dual Infeasibility 0
Bound Infeasibility 0

[1] diet
Bread 0.000000
Cheese 0.449499
Fish 0.500000
Milk 0.053599
Potato 1.865168
Yogurt 0.000000



Previous Page | Next Page | Top of Page