Lecture 1: Basics of Math and Economics

advertisement
Lecture 7:
Linear Programming in Excel
AGEC 352
February 6, 2012
R. Keeney
Linear Programming on the
Computer

Two things to know:
◦ 1) Setting up the spreadsheet and directing
Solver to run
 This is what lab is for and we will learn this through
repetition
◦ 2) Understanding what happens between
starting Solver and it giving you a solution
 We are covering this in lecture
Computer algorithms

Step by step approach: often called a
routine or procedure

List of directions to be carried out and a
series of checks
◦ The checks indicate which direction is to be
done next
Simplex method as an algorithm
Step 1: Identify the pivot column
 Step 2: Identify the pivot cell
 Step 3: Convert the pivot cell to a value
of 1
 Step 4: Convert the remaining cells of the
pivot column to a value of 0

Step 1: Direction to the comp.
Initial Tableau
land
cash
stor
obj
C
1
50
100
-60
B
1
100
40
-90
s1
1
0
0
0
s2
0
1
0
0
s3
0
0
1
0
P
0
0
0
1
RHS
320
20000
19200
0
Ask the computer to search over the row
labeled ‘obj’ and find the most negative
value
 In Excel:

◦ Min function: = min(B17:F17)
◦ Small function: = small(B17:F17,1)
Step 2: Direction to the comp.
Initial Tableau
land
cash
stor
obj
C
1
50
100
-60
B
1
100
40
-90
s1
1
0
0
0
s2
0
1
0
0
s3
0
0
1
0
P
0
0
0
1
RHS
320
20000
19200
0
Working in the Beans column (In Excel
this is labeled as C)
 Have Excel calculate a column =RHS/B
 Have Excel identify the minimum value in
that column (min or small functions)

Step 3: Direction to the comp.
Initial Tableau
land
cash
stor
obj




C
1
50
100
-60
B
1
100
40
-90
s1
1
0
0
0
s2
0
1
0
0
s3
0
0
1
0
P
0
0
0
1
RHS
320
20000
19200
0
Working in the cash row
Have Excel recalculate the cash row by
dividing through by 100
=B15/$C$15
An absolute cell reference
◦ Copying to other cells will change the numerator
but not the denominator
Step 4: Direction to the comp.
Initial Tableau
C
land
1
cash
0.5
stor
100
obj
-60

B
1
1
40
-90
s1
1
0
0
0
s2
0
0.01
0
0
s3
0
0
1
0
P
0
0
0
1
RHS
0
200
0
0
Calculate a factor for each row
◦ E.g. Land factor = -1
◦ Old land row + {land factor x cash row} =
new land row
Run a check for negative values in the obj
row
 If statement: =if(condition, true, false)

The example is simplified
The steps discussed above would require
a considerable amount of user input
 Solver and other computer programs are
typically designed to take user input only
at the beginning and then return
completed output
 Spreadsheet does not have the capacity,
to do this efficiently, need a more robust
programming language

Excel LP Model Setup
*Decision variables are listed at the top of each column.
*First value underneath is the current value of the variable.
*Always set to zero before running Solver.
DECISION VARIABLES
Corn
Activity Levels
Profit per acre
Constraints
Land
Cash
Storage
Soybeans
0
0
60
90
0 <-Objective Cell Measuring Total Profits
LHS
1
50
100
1
100
40
Sign
0 <=
0 <=
0 <=
RHS
320
20000
19200
Excel LP Model Setup
*Every other row in the model is an equation and the cells
are equation coefficients.
*Place the objective equation directly under the decision
variables. Read as 60*Corn + 90*Soybeans =
*Objective Cell holds the value of the objective equation.
Corn
Activity Levels
Profit per acre
Constraints
Land
Cash
Storage
Soybeans
0
0
60
90
0 <-Objective Cell Measuring Total Profits
LHS
1
50
100
1
100
40
Sign
0 <=
0 <=
0 <=
RHS
320
20000
19200
Excel LP Model Setup
*Constraint equations work the same way as the objective
equation. We calculate their values in a column called LHS.
*E.g. Land constraint is 1*Corn + 1*Soybeans.
*RHS column is the upper limit for each resource.
Comparing the LHS to the RHS checks feasibility.
Corn
Activity Levels
Profit per acre
Constraints
Land
Cash
Storage
Soybeans
0
0
60
90
0 <-Objective Cell Measuring Total Profits
LHS
1
50
100
1
100
40
Sign
0 <=
0 <=
0 <=
RHS
320
20000
19200
Excel LP Model Setup
*More variables? Add more columns to the right of Soybeans.
*More constraints? Add more rows beneath Storage.
*The cells in orange below are the only ones that Solver
actually uses. It adjusts activity levels to maximize the objective
cell formula result while ensuring that no LHS value exceeds
the RHS value.
Corn
Activity Levels
Profit per acre
Constraints
Land
Cash
Storage
Soybeans
0
0
60
90
0 <-Objective Cell Measuring Total Prof
LHS
1
50
100
1
100
40
Sign
0 <=
0 <=
0 <=
RHS
320
20000
19200
Solver

Screen capture are from Excel 2010
Reference to
objective cell
Reference to decision
variables
Input the constraints
(i.e. LHS <= RHS)
Solver
Solving Method:
For linear programs,
we use Simplex LP.
(This is automatic
when you click
‘assume linear model’
in previous versions
of Excel.)
We’ll discuss Options
later.
Download