1 minimizing cost while meeting nutritional requirements – an example of linear programming is it...

15
1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from your favorite foods while minimizing costs? Prepared for SSAC by *Yu-Ju Kuo – Indiana University of Pennsylvania* © The Washington Center for Improving the Quality of Undergraduate Education. All rights reserved. *2007* Supporting Quantitative concepts and skills Linear Equations Linear Inequalities Multivariable function: inclined plane Level lines (contours) Excel Solver SSAC2007.QP141.YJK1.1 Core Quantitative Concept Linear Programming

Upload: belinda-knight

Post on 03-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

1

Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear

Programming

Is it mathematically possible to create a healthy diet from your favorite foods

while minimizing costs?

Prepared for SSAC by *Yu-Ju Kuo – Indiana University of Pennsylvania*

© The Washington Center for Improving the Quality of Undergraduate Education. All rights reserved. *2007*

Supporting Quantitative concepts and skillsLinear EquationsLinear Inequalities Multivariable function: inclined planeLevel lines (contours)Excel Solver

SSAC2007.QP141.YJK1.1

Core Quantitative ConceptLinear Programming

Page 2: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

2

Slides 4-6 Give background information about linear programming – systems of linear inequalities, the feasible set, and the location of the solution to a linear programming model.

Slides 7-8 Set up a simplified dietary model using two foods and two nutrition requirements.

Slides 9-11 Overview Excel Solver and demonstrate its use by solving a simplified dietary problem.

Slides 11 Poses “what-if questions” to explore the model of the simplified dietary problem.

Slides 12 Gives the End of Module Assignment, in which you consider a more realistic dietary problem.

Overview of Module

The “Dietary Problem” is important in our daily lives. The key issue is whether you get enough nutrition from your choice of foods, while at the same time paying the minimum cost or consuming the minimum calories. In this activity, we will set up the Dietary Problem as a linear programming model, discuss how the solution appears on a graph,

and then use Excel’s Solver feature to solve the problem.

Page 3: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

3

We will assume that your favorite foods are broccoli and carrots We will further assume that you eat only these two favorite foods.

Problem

Our approach: We let x = servings of broccoli and y = servings of carrots. A linear programming model includes two parts, a linear

objective function of x and y and a set of linear constraints on x and y. The set of pairs (x,y) that satisfy all constraints is called the feasible set. The objective function is the function which you would like to

minimize or maximize over the feasible set.

How many servings of broccoli and carrots should you eat each day to satisfy the nutrition requirements for

protein and iron – keeping in mind that you also want to minimize the cost of your food?

You will need numbers – the daily requirements for protein and iron; the amount of protein and iron per serving of broccoli and

carrots; the cost per serving of broccoli and carrots.

Definition: A linear function in two variables is defined as f(x,y)=ax+by+c, where a, b, and c are constants.

Page 4: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

4

Background information-Feasible Set

As background, we consider the values of x, y, that satisfy all of the following linear inequalities:

What is an inequality?

If x=1 and y=3, is (x,y) a solution to 2x y ≤ 3 ?

How do we find the solution set that satisfies 2x-y≤3 graphically?

Definition: The solution set to an inequality ax+by≤ c, where a, b, and c are constants, is the collection of all ordered pairs (x,y) such

that ax+by≤ c is true.

How many pairs of (x,y) satisfy 2x– y ≤ 3?

Step 1: Graph the equality.Step 2: Pick a point on one side of the line. Plug it into the inequality and verify whether the inequality is true.Step 3: If the point makes the inequality true, then the whole half-side in which the point is located is the solution set to the inequality. Otherwise, the other side of the line is the solution set.

Think carefully about Step 3 and explain why!!

The half-plane that contains arrows is the solution set of 2x – y ≤ 3.

0,0

10

15.0

32

yx

yx

yx

yx

Page 5: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

5

Background Information-Feasible Set

Now, repeat the same process for the rest of inequalities and then find the overlap of all the solution sets.

The solution

-4

-2

0

2

4

6

8

10

12

-5 0 5 10 15 20

y=.5x+1

y=-x+10

y=2x-3

This yellow area is the solution set of all five inequalities from the previous

slide. This set is the feasible set.

Next, we consider an expression 3x y. What point in the yellow area would give the minimum value for 3x y and what would be that minimum value be?

Refer to the red box of Slide 3. What do we call this expression 3xy?

What do we call the five inequalities?

We are looking for the minimum of 3xy over this yellow area; therefore, 3xy is the

objective function and the five inequalities from previous slide are our constraints.

Now we can write this example into the standard form of a linear programming model (LP): Minimize 3xy subject to (s.t.): 2xy ≤ 3, x + y ≤ 10,

.5xy ≤ 1, x≥0 , and y ≥0

Definition: A solution of a minimization LP is a point in the feasible set that achieves the

minimum of the objective function. Note: The dashed lines on the boundary of the

feasible set are also part of the feasible set.

Page 6: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

6

Background Information-Solution of Linear Programming

Similar to the graph from the previous slide, the yellow region here is the feasible set from the five constraints. The set of parallel lines show contours of the objective function, z = 3x y.

Carefully look at the above graph. The objective function is an inclined plane. Look at the contours on the plane: Which direction is z decreasing? Where in the feasible set does the

lowest value of z occur? Note the color spectrum.

Theorem: If the feasible set of a

LP is not empty, then at least one corner point of the feasible set is a

solution of the LP.

If a LP has only one solution, where would it be?

Is it possible to have more than one solution for a LP?

Is it possible to have no solution for a LP?

The feasible set

Answers

Page 7: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

7

Simplified Dietary Model

Now, we can set up a LP to minimize the cost of our two foods subject to two nutrition requirements? To begin, we will start by introducing the data set.

ID Foods Price/Serving Serving Size Calories Protein(g) Vit_C (IU) Calcium(mg) Iron(mg)

1 Frozen Broccoli 0.16 10 Oz Pkg 73.8 8 160.2 159 2.3

2 Carrots,Raw 0.07 1/2 Cup Shredded 23.7 0.6 5.1 14.9 0.3

3 Celery, Raw 0.04 1 Stalk 6.4 0.3 2.8 16 0.2

4 Frozen Corn 0.18 1/2 Cup 72.2 2.5 5.2 3.3 0.3

Leave the slide

show mode, then

double click the

Excel icon to obtain

the table.

8

8 grams of protein in one serving (10 oz) of frozen broccoli

0.3

0.3 milligrams of Iron in one serving (1/2 cup) of raw carrots

IU

IU: international unit, a unit of measurement

for the amount of a substance. Assumptions:1. Eat only broccoli and carrots.

2. All nutrition in food consumed is completely absorbed 3. Protein requirement per day is at least 45 g per day.Iron requirement per day is no more than 24 mg per day.

Define:x: # of servings of broccoli per dayy : # of servings of carrots per day

What is the cost for two servings of broccoli?

0.16x+0.07y

What is the cost for x servings of broccoli?

What is the total cost of broccoli and carrots per day?

Microsoft Office Excel Worksheet

Page 8: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

8

Simplified Dietary Model

What is the objective function?

Minimize 0.16x+0.07y

Now, let us consider the protein requirement : at least 45 grams per day.Since there are 8 grams of protein per serving and you consume x servings of

broccoli per day, you absorb 8x grams of protein from broccoli.

Since you need at least 45 g of protein per day, that means the total amount of protein per day should be greater than or equal to 45 g, i.e., 8x+0.6y≥45

How many grams of protein will come from carrots?

Write the inequality associated with the iron requirement, no more than 24 mg per day.

2.3x+0.3y≤ 24

The complete linear programming model will look as follows:Minimize 0.16x+0.07ys.t. 8x+0.6y≥45 2.3x+0.3y≤24, x,y, ≥0

Why should x and y be greater than or equal to 0?

0.16 is the price per serving for broccoli.0.07 is the price per serving for carrots.

Page 9: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

9

Step 1: a) In Column B, enter the ID of your choice of foods.b) Use Cells D50 and D51 for the variables (# of servings for broccoli and carrot).c) Use the LOOKUP command to find the names(C50:C51), prices(E50:E51), and nutrition (F50:I51) of the foods (using the ID entered in Column B).

Excel Solver

In this portion, we will introduce the Excel solver through the following steps:Step 1: Extract data for foods, such as names, price per serving, nutrition contents.Step 2: Build objective function and constraints.Step 3: Enter necessary information for the Solver.Step 4: Run the Solver and interpret the result.

If you have not used Excel Solver or are not familiar with LOOKUP or SUMPRODUCT command, please click here for help.

Excel Preview

= cell with a number in it

= cell with a formula in it

=LOOKUP(B51,$B$3:$B$42,$F$3:$F$42)

Page 10: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

10

Excel Solver

Step 2: a) Recall: Objective function = (Price per serving for broccoli )times( # of serving for broccoli)+ (Price per serving for carrots) times ( # of serving for carrots). b) Prices per servings are in E50 and E51, # of servings are in D50 and D51, thus the objective function is D50*E50+D51*E51.c) To extend the problem later on, we could also use SUMPRODUCT.d) Similarly, look at the left hand side of constraints and rewrite them using SUMPRODUCT and enter them into D62 and D63. Note: D59, D62, and D63 will be 0 after you enter the formula since the initial values for variables are zeros. The solutions will be returned to those cells after the solver is run.e) Insert appropriate inequality symbols for E62 and E63. Enter the right hand side of constraints into F62 and F63.

Step 3: a) Click Tools and find solver, then you will see the following pop-up.b) Use “ADD” to add constraints.c) Click Solve to continue.

Step 3:d) If the Solver found a solution, Click OK to continue.

Carefully read this part of pop-up window before you continue.

=SUMPRODUCT(D50:D51, E50:E51)

Page 11: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

11

Excel Solver-What if questions.

Step 3: e) Solution is as follows

1. Write your answer in a complete sentence in the context of the problem.

2. Explain why D63 is 12.9375.

3. Choose Poached Eggs and Regular butter and run the solver (Step 3) again. a) Explain what happens in the result.b) What would be a better way to set up nutrition constraints for iron such that there is always a certain amount of iron consumed?

4. Choose Oatmeal Cookies and Chocolate Chip cookies. Use the original iron requirement (no more than 24 mg per day) and run the solver again. a) What does it say in the Solver Result pop-up?b) Use the background information for feasible set discussed earlier to graph the feasible set of two nutrition constraints. Explain what happens to the solver.

Solution

Minimum cost

Page 12: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

12

End of Module Assignment

1. Expand your Excel sheet so that it will work for any six choices of food and four nutrition requirements (Protein, Iron, Vitamin C, Calcium). a) It is recommended to set up nutrition constraints that are suitable for your individual case.b) Test your spreadsheet with your six choices of food.

2. A company produces two products, A and B. Both products use one raw material with the maximum daily availability 240 lb. The usage rates of the raw material are 2 lb per unit of A and 4 lb per unit of B. Each unit of A and B require 4 hours and 6 hours, respectively. The unit prices for A and B are $20 and $50, respectively.a) Write the linear programming model to maximize the revenue of these two products.b) Use Excel Solver to find the number of units for A and B to achieve the maximum revenue.

Optional: In Excel Solver’s Step 1, combine IF and LOOKUP to build a formula such that Excel checks whether the food ID is entered before using LOOKUP to extract data.

Page 13: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

13

Get Ready for Excel Solver

= cell with a number in it

= cell with a formula in it

In this portion, we will introduce important commands for this module: LOOKUP, SUMPRODUCT.

Step1: Open a new Excel worksheet and enter the information as below.

Click on Tools and check whether Solver is on the list. If it is listed, skip the Step 0. If Solver is not listed, please follow Step 0 to add-in the solver.

Step 0: a) Click Tools, then Add-in. b) Check the box next to Solver Add-in, then click OK. c) Click in a open worksheet and check again whether Solver is listed under Tools.

Page 14: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

14

Get Ready for Excel Solver

Step 3: Consider 9 servings of frozen broccoli and 5 servings of frozen corn, how much is the total cost? Mathematically, Total cost= (# of servings of broccoli) times(broccoli’s cost per serving)+(# of serving of corn) times (corn’s cost per serving).Thus, the total cost is the sum of the product of # of servings and cost per serving. Command format: SUMPRODUCT(array1, arrray2)

Step 2: Now we would like to extract the names and the prices of foods. For example, Excel should look for the ID given in B10 from the ID list (B3:B7), then return the name of the food associated with the ID in B10 from the Name list (C3:C7). Enter the formulas for C10, C11, E10, and E11. Command Format: LOOKUP(lookup_value,lookup_vector,result_vector)

Return

=LOOKUP(B11, $B$3:$B$7, $D$3:$D$7) =SUMPRODCUT(D10:D11, E10:E11)

Array 1Array 2

Page 15: 1 Minimizing Cost while Meeting Nutritional Requirements – An Example of Linear Programming Is it mathematically possible to create a healthy diet from

15

Answers to Questions on Slide 6

If a LP has only one solution, where would it be?

Is it possible to have more than one solution for a LP?

Is it possible to have no solution for a LP?

It would be at a corner point of the feasible set. Assume that none of

constrains is parallel to the contours of the objective function. For a minimization LP, this corner point will be the last point

where the decreasing contour lines intersect w/ the feasible set. On the

other hand, for a maximization LP, the corner point will be the last point where the increasing contour lines intersect

with the feasible set.

Yes, it is possible. If one of the boundary lines of the feasible set coincides with one of the decreasing contours, there will be infinite solutions for a minimization LP. On the other hand, if one of the boundary lines of the feasible set coincides with one of the increasing contours, there will be

infinite solutions for a maximization LP. Note that in the graph below, there are infinite solutions for the minimization LP, but there is a unique solution for the maximization LP.

Yes, it is possible. When the feasible set is empty, there will be no solution. Study figure in Slide 5.

Return