Lab Handout 2: Solving Linear Programming Problems in MS Excel

advertisement
Lab Handout 2: Solving Linear Programming Problems in MS Excel
The objective of this week’s assignment is to become familiar with the procedure for setting
up and solving Linear Programming (LP) problems in MS Excel. In Part I of the assignment you are
given a complete spreadsheet ready for Solver implementation. In Part II you are asked to create the
spreadsheet and generate the solution. Just like in lab 1 there is a blackboard discussion section
available. Remember to reply to the sign-in thread when you start working on the lab.
Part I: Learning to use Solver for LP
Checking to see if Solver is installed
Open the spreadsheet provided at the link with this handout. We first need to check your
computer’s installation of MS Excel to see if Solver has been activated. To do this click on the ‘Data’
tab at the top of the Excel screen. If Solver is installed it will appear at the right of the screen as part
of the ‘Analysis’ group of tools. If Solver does not appear there, we will need to add it to your
installation of MS Excel.
Installing Solver into Excel (only required if it is not present)
To install Solver complete the following steps:
1) Click on the Office button at the top left of the Excel program screen.
2) Click on Excel Options at the bottom of the Office button box that appears.
3) Choose Add-Ins in the left hand side of the Excel Options page
4) Highlight ‘Analysis ToolPak’ in the Add-ins list, then click the ‘Go…’ button at the
bottom of the page
5) In the Add-Ins choices that appear, click the box next to ‘Solver Add-in’ and click OK
Setting up the problem in MS Excel
The setup of a linear program in a spreadsheet is very similar to the algebraic form we have been
using as well as the tableau setup that we saw in lecture on 2/7/2011. Each variable of the problem
will have its own column. The first cell in that column will initially be zero but will change as we try
different values for the variable in search of its optimal setting. We call this the ‘Activity Level.’
Directly beneath the ‘Activity Level’ we will place the objective equation coefficient for the variable.
This completes the objective equation part of the problem and allows us to start writing the
constraints. The algebraic form of the problem is given below. Note that this is the same problem
that we applied the Simplex method to in lecture on 2/7/2011.
max P  60C  90 B
s.t.
land : C  B  320
cash : 50C  100 B  20,000
storage : 100C  40 B  19,200
non  neg : C  0; B  0
In the above linear program C = acres of corn planted and B = acres of soybean planted. P is the
total net profit earned and represents the objective criterion of the decision maker. The constraint
coefficients (numbers in front of the variables) indicate the usage of a particular resource per acre of
crop planted. The RHS (right hand side of the constraints) represents the fixed limits of resources
available to the decision maker.
MS Excel does not have a mechanism for writing equations directly as you would see in many
computer programming environments. Instead, it has a large list of formulas that combines the
values of other cells into a new numerical value in a new cell. As such, equations in Excel must be
setup so that a cell calculates the LHS (left hand side) of an equation or inequality while a different
cell calculates the RHS (right hand side) of an equation. We will go through the Excel setup of the
farm problem to demonstrate.
A screenshot of the part I spreadsheet depicting the farm problem is given above and you should
save and open a copy of the spreadsheet in order to follow along. This will allow you to look at the
formulas input into any cells directly.
First note that the variables are labeled at the top of the columns and their values (activity levels) are
directly below in cells B3 and C3. The coefficients for these variables in the objective equation are
given in B4 and C4. To the right of those coefficients, we calculate the objective variable of profits.
Open the formula in this cell (D4) and you will see that we use the sumproduct formula. The
sumproduct formula takes two rows of data and first multiplies the column elements then adds the
products from each column. In the case of the objective cell the sumproduct formula will return the
same solution as entering the formula as =B3*B4 + C3*C4.
Moving to row 6 of the spreadsheet we have a row of headings for the constraint inequalities. In
column A, each of the constraints is named for the resource the inequality will track. In columns B
and C, we input the coefficients for Corn and Soybean usage of the different resources. Columns D
through F represent the equation or inequality section. Here we calculate the LHS of the inequality
using the sumproduct formula in column D, indicate the sign that determines the relationship
between LHS and RHS in column E, and input the fixed RHS value for each resource in column F.
Note again how the sumproduct formula is used to multiply the constraint coefficients by the
activity levels in the LHS cell formulas. For the land constraint, the sumproduct formula used is
equivalent to inputting the formula =B3*B7 + C3*C7. One way to look at this is the LHS column
keeping track of usage of resources by the different activity combinations we might try and the RHS
giving the upper limits that determine feasibility. Also note that we are note entering non-negativity
constraints into the problem, we will see why in a moment.
Solving the LP in MS Excel
We are now ready to solve this linear program using the Solver tool. With the spreadsheet open,
click on the Data tab and then click on Solver in the Analysis group. The figure below shows the
Solver Parameters box that should appear.
The first thing we need to do is input the objective variable into Solver. This goes in the ‘Set Target
Cell’ box at the top of the Solver Parameters box. You can click the red arrow to the right of the
input field and Solver will take you to the spreadsheet you are working in and allow you to highlight
the cell you want as the objective cell rather than having to type it in.
The objective cell we need referenced in ‘Set target cell’ is D4.
The next line in the Solve Parameters box allows you to choose whether you want to find a
maximum, minimum, or target value. We want the Max button clicked here. We will only use the
‘Value of’ box for input if we are trying to target an exact predefined value of profits.
The next area of the Solver Parameters box is labeled ‘By Changing Cells.’ This is where the decision
variables of the problem are input, meaning these are the cells that Solver is allowed to change as it
searches for the maximum profit combination. You can again use the red arrow at the right of the
input field to switch to the spreadsheet and highlight the cells for variables (we labeled them activity
levels).
The ‘By Changing Cells’ with our variable values are found in B3 and C3. This can be typed
in as B3,C3 or B3:C3. If you use the red arrow to highlight these cells it will be the latter
version with the colon separation and will also add dollar signs to the cell references. Don’t
worry about the dollar signs for now.
The last field of the Solve Parameters box is titled ‘Subject to Constraints’ and is the location where
we define the feasible space of the problem. To activate this field you will need to click the ‘Add’
button to the right of the field. Once you click on this the ‘Add Constraint’ box should appear. The
cell reference on the left is where we input the LHS cell for each constraint. Recall that the formulas
in these cells keep track of usage when corn and soybean levels change. The middle field asks for the
sign between LHS and RHS. This box is a drop-down that lets you choose among several options
defining the constraint types. The right-hand field of the ‘Add Constraint’ box is the RHS value we
entered into our spreadsheet. You can input both the LHS and RHS values in the ‘Add Constraint’
box using the red arrow mechanism.
When you have input the first constraint for land, you can click on ‘Add’ at the bottom of the ‘Add
Constraint’ box and input the next constraint. After you have entered the last constraint from the
spreadsheet, click OK.
When you complete the constraint entry, your ‘Solver Parameters’ box should look like the
screenshot below.
We are almost ready to solve this problem. The final step is to deal with the non-negativity of the
problem. Click on the ‘Options’ button on the right hand side of the ‘Solver Parameters’ box and
you will see the following ‘Solver Options’ screen.
We will discuss what these different things mean in lecture, but for now click on ‘Assume linear
model’, ‘Assume Non-negative’, and ‘Use Automatic Scaling.’ When you have check marks in each
of these three boxes click OK and return to the Solver Parameters box.
Click Solve in the Solve Parameters box.
When Solver completes it will give you several options on dealing with the solution. For now, just
ignore all of that and click on OK.
Your spreadsheet should now look like the screen capture below. This completes part I of the lab
and you can now move to the class discussion board to participate in the lab discussion questions.
Part II: Creating your own spreadsheet LP and solving it
Our problem in part II is still a farm planting problem where we seek to maximize profits. We will
now consider three different crop: corn, wheat, and oats. The table on the next page gives all of the
data needed to generate the linear program for this farm. Note in the data that the farm has 500
acres of land but only 400 of those acres are suitable for row crops (here corn). Additionally, the
farm has a direct constraint on the amount of wheat that it can produce through a government
program that directs the maximum planting of wheat. This is reflected in the ‘wheat allotment’
constraint. Finally, the labor resource of the farm is split up into four month blocks reflecting the
different requirements and limits by season.
Using the model that was given to you in part I of this week’s lab as a template, create a spreadsheet
model using the data below that maximizes profits from crop planting subject to the resource
constraints. Save the solved spreadsheet in sheet 2 of the Excel workbook you are maintaining for
submission at midterm (i.e. the same Excel workbook that you saved part I of lab 1 in). The
homework questions are due in the next Monday lecture meeting.
Table II.1 Data for part II LP
Resource
Total land
Rowcrop land
Wheat allotment
Jan. to Apr. labor
May to Aug. labor
Sep. to Dec. labor
Total Available
500 ac
400 ac
120 ac
1600 hrs
2000 hrs
1600 hrs
Corn Use
1
1
0
5
1
3
Wheat Use
1
0
1
1
2
3
Oats Use
1
0
0
1
2
3
Dollars
45
32
20
Profit per acre
Homework Questions:
1) What is the significance of separating the labor into different seasons versus using a single
constraint that tracks all 5200 available labor hours for the year?
2) What are the optimal activity levels for this problem?
3) What is the maximum profit that can be earned?
4) What constraints bind in this problem (i.e. they have the RHS and LHS cells equal)?
5) What would the farmer do if they had one more acre of total land available? (Hint: set the
RHS value to 501 and resolve the model, then examine the changes in the solution)
6) If land was available to rent how much could the farmer pay to rent the 501st acre?
7) What would the farmer do if the wheat program that dictates the allotment were eliminated?
(Hint: set the RHS of total land back to 500 then set the RHS of the wheat allotment
constraint to 500 and resolve the model. Compare the differences to the initial solution).
8) Compare your optimal solution to a situation where a farmer produces only corn in terms of
resource use. (Hint: find the most limiting resource for corn and set the corn activity level to
the maximum allowed by that resource while setting wheat and oats to zero).
Download