Handout on Spreadsheet Modeling

advertisement
[prefer-ex]
Handout on Spreadsheet Modeling
Spreadsheet is gaining popularity not only as a general office tool, but also as a modeling tool.
The flexibility and versatility of a spreadsheet to solve a variety of problem is the driving force
behind its popularity. There are a number of spreadsheet software available, including MS Excel
and Lotus 1-2-3. It is not our intent to teach our readers how to use a spreadsheet. Rather, we go
beyond that in providing some guidelines to build quality spreadsheet models. Hillier and
Lieberman (2009) suggest a four-step process:
(1) Plan the spreadsheet model. Visualize where one wants to finish and then doing some
calculations by hand to clarify the needed computations. Accordingly, a spreadsheet model is
designed with the "feel and look" that one desires. The objective is a clear, logical layout to the
overall model.
(2) Build the model. It is advisable to start by building a small, readily manageable version of
the model, mainly for experimentation.
(3) Test the model. One is advised to test the small version first to get all the logic straightened
out, before developing the full scale model.
(4) Analyze the model and its results. In this final step, one applies the model to evaluate
proposed solutions. For more complex models, one may even use an add-in Solver to accomplish
this step.
By itself, the four-step process is not sufficient. There are additional guidelines for building
"good" spreadsheet models. Here are some salient ones (Hillier and Lieberman 2009, Winston
and Albright 2007):
G Enter the data first, inasmuch as data really drives a spreadsheet.
G Organize and clearly identify the data.
G Enter each piece of data into one cell only.
G Separate data from formulas, instead of embedding data directly into a formula.
G Keep it simple by avoiding the use of powerful Excel functions when simpler functions are
available that are easier to interpret.
G Use range names for easy reference, instead of just leaving the range in the cell.
G Use relative and absolute references to simplify copying formulas, instead of re-entering the
formula at various places in the spreadsheet.
G For readability, use cell comments liberally, use text boxes for assumptions and explanation,
and use borders, shading, and colors to distinguish between cell types.
G Separate different parts of a model, possibly across multiple worksheets.
G When a Solver is used, the Solver uses a combination of the spreadsheet and the Solver
dialogue box to specify the model to be solved. Therefore, it is possible to include certain
elements of the model (such as the right-hand sides of the constraints in a linear program) in
the Solver dialogue box without displaying them in the spreadsheet. For effective model
1
dissemination, it is advisable to show the entire model on the spreadsheet.
To debug a spreadsheet model, check whether the output cells are giving correct results for
various values of the changing cells. Also check whether range names refer to the appropriate
cells, and whether formulas have been entered into output cells correctly. Toggle the worksheet
between viewing the results in the output cells and the formulas entered into those output cells.
Finally, other spreadsheet auditing tools can be used for additional debugging efforts.
Spreadsheets are appealing in part because it allows many models to be built without
requiring computer programming skill on the part of the user. However, programming skills can
be developed "on the job." The use of macros is an example. Beyond building a straightforward
spreadsheet model, decision support systems (DSSs) can be developed that builds upon
spreadsheets (Albright 2010). A computer language to facilitate this effort is Visual Basic for
Applications (VBA). For Microsoft users, VBA comes with MS Office, which make it accessible
to a vast audience of potential users. To work properly, one needs to enable macros in the front,
since VBA is really a macro to the Excel spreadsheet software. The end result of this effort is a
set of spreadsheet applications with front ends and back ends, where inputs are enter in the front
and where results are posted at the back.
For our discussions here, VBA works with Excel objects. A few typical Excel objects one
will recognize immediately include ranges, worksheets, workbooks, and charts. The goal is to
expose a spreadsheet’s object model and functionality to VBA, so that VBA can manipulate it
programmatically. As a result, a DSS is built, going well beyond what a single spreadsheet can
accomplish. In general, any application software package, such as Access, Word, or even a
non-Microsoft software package, can similarly expose its object model and functionality to VBA.
For more details, see CHAPTER 21 of Hillier & Lieberman (2005)1, entitled "The Art of
Modeling with Spreadsheets"
1
Hillier, F. S. & Lieberman, G. J. (2005) Introduction to operations research, Boston : McGraw-Hill
Higher Education (On Reserve under my name; Other Editions available for check out)
2
Class 3 - SIMPLE ORDERING THROUGH PARETO OPTIMALITY
Review
Step-by-step EXCEL demonstration of handling these preference structures:
a) Construct the payoff matrix (in which the payoffs represent gains)
b) Make a decision using the max-max rule
c) Make a decision using the max-min rule
d) Make a decision using the min-max regret rule
e) Make a decision using the max expected-value rule
Table 1 - EXCEL demo of Magnolia Inn Homework - Data
Table 2 - EXCEL demo of Magnolia Inn Homework - Payoff Matrix
When the payoffs are in terms of losses, they could be represented as negative
gains.
Pareto preference
The simplest case of decision making is simple ordering among alternatives,
where no preference structure is required. Examples include dominance and Pareto
preference.
Definition
An outcome y is Pareto optimal if and only if it is a non-dominated solution
(N-points) with respect to Pareto preference. Pareto preference is defined by y* ™ yi
if and only if y*$yi, or v*( y1*, y2*) $ vi( y1i, y2i), where y1*$ y1i and y2*$ y2i. A
Pareto optimal solution is also called an efficient, non-inferior, non-dominated, or
admissible solution.
Example
Figure 1 - Set of non-dominated solutions
3
Observations
1. The set of N-points, N, offers preference determination under conditions of
ignorance (about how to compare incommensurate attributes such as y1 and y2).
2. Regardless of the exact value of utility/value function definition, v( y1, y2), its
maximum will be an N-point.
3. It makes sense to explore Y and characterize its set of N before engaging in the
assessment of v. It is possible an alternative will emerge such as shown in
Figure 2 - Conflict-free solution
4. N can be useful in dealing with more complicated types of outcomes Y, such as
shown in
Figure 3 - Non-dominance on a discrete point set
and
Figure 4 - Non-dominance on a non-convex set
Pareto optimality is the condition under which one or more criteria achieve a
higher utility without compromising any other criteria.
Figure 5 - Pareto optimality example
4
5
6
[n-set]
Set of
o non-dominated
o do
ated so
solutions
ut o s
y2
v'
Legend
v
Set of N-points
y*
yi
Y
v"
y1
Conflict-free
Co
ct ee so
solution
ut o
Non-dominance on a discrete p
point set
y2
Legend
g
Non-dominated solutions
D i t d solutions
Dominated
l ti
y1
Non-dominance on a non-convex set
y2
Legend
N set
N-set
Y
y1
Pareto optimality
p
y example
p
y2
Legend
g
1.0
Non-dominated solutions
Dominated solutions
v1 = 0.5 y1 + 0.5 y2
v2 = 0.2 y1 + 0.8 y2
0.5
yj (0.5, 0.5)
yi (0.5, 0.25)
0.5
1.0
y1
Location Theory & Decision Analysis
(c) Springer
Linear Program Part 2 - Simplex Algorithm
Name: _______________
LINEAR PROGRAMMING MODULE
Part 2 - Solution Algorithm
THE SIMPLEX SOLUTION METHOD
It should be obvious to the reader by now that the graphical method for solving linear
programs is limited to models of 2 variables such as in Illustration 1). The models such
as Illustration 3), with 3 or more variables, are not easily graphed on two-dimensional
graph paper. Thus, an algebraic technique is needed to solve LPs with numerous
variables and equations. Also, such an algebraic technique is conducive to computer
solution. One algebraic technique for solving linear programs is called the simplex
algorithm. It was created by George Dantzig in 1947, and its theoretical foundation was
established in 1948 by Gale, Kuhn and Tucker in the working paper “Extremum
Problems with Inequalities as Subsidiary Conditions.” The interested reader is referred
to the classic volume, Linear Programming and Extensions, by George Dantzig,
Princeton University Press, 1963.
Illustration 9)
Consider the linear program:
Objective function: max Z = 10 X1 + 40 X2
Constraints:
+
X2
X1
2 X1 +
5 X2
X1 $ 0, X2 $ 0.
# 10
# 30
1) The simplex algorithm begins by moving all the terms on the right-hand side
of the objective function to the left: Z = 10 X1 + 40 X2 becomes
Z & 10 X1 & 40 X2 = 0
2) The inequalities of the constraint equations are changed into equalities by the
addition of the slack variables, X3 and X4. Slack variables represent resources that are
not used. For example, if we have 10 cars and our motor pool requires 6 cars, then we
have 4 cars not being used: a slack of 4 cars. Six is obviously less than10, but if we add
the slack of 4 to 6 we have the equality 6 + 4 = 10.
X1 + X2
# 10 becomes
X1 + X2 + X3 = 10
Page 1 of 9
Location Theory & Decision Analysis
(c) Springer
Linear Program Part 2 - Simplex Algorithm
and
# 30 becomes
2 X1 + 5 X2
2 X1 + 5 X2 + X4 = 30
3) The three adjusted equations are:
= 0
Z - 10 X1 - 40 X2
X1 + X2 + X3
= 10
2 X1 + 5 X2
+ X4 = 30
Note that the constants on the right-hand-side (RHS) of the equations are 0, 10, 30.
4) a - We make a chart, called the tableau, with Z, X1, X2, X3, X4 as variables and the
constants on the RHS of the columns.
b - We enter the coefficients of Z, X1, X2, X3, X4 and the RHS at appropriate places in
this tableau.
Z
X1
X2
X3
X4
RHS
objective function row
1
- 10
- 40
0
0
0
1st constraint row
0
1
1
1
0
10
2nd constraint row
0
2
5
0
1
30
5) We indicate the column in the tableau with the smallest number in the objective
function row.
Z
X1
X2
X3
X4
RHS
1
- 10
- 40
0
0
0
0
1
1
1
0
10
0
2
5
0
1
30
The column with -40 has the smallest value in the objective function row. The indicated
column, X2, is called the pivot column.
6) a - We pick only the positive numbers in the pivot column, i.e., no.’s bigger than 0.
b - We divide the corresponding RHS by these numbers.
Z
X1
X2
X3
X4
RHS
1
- 10
- 40
0
0
0
0
1
1
1
0
10
10 / 1 =10
0
2
5
0
1
30
30 / 5 = 6
Page 2 of 9
Location Theory & Decision Analysis
(c) Springer
Linear Program Part 2 - Simplex Algorithm
7) We indicate the row with the smallest RHS/X ratio. The row is called the pivot row.
30 / 5 = 6 is smaller than 10 / 1 = 10.
pivot row
Z
X1
X2
X3
X4
RHS
1
- 10
- 40
0
0
0
0
1
1
1
0
10
0
2
5
0
1
30
pivot
column
The number "5" common to both pivot row and pivot column is the pivot element.
8) We change the pivot element, 5, into 1 by multiplying the pivot row by 1/5.
Pivot row:
New pivot row:
(0
(0
2
2/5
5
1
0
0
1
1/5
30) × 1/5 =
6)
New tableau:
new pivot row
Z
X1
X2
X3
X4
RHS
1
- 10
- 40
0
0
0
0
1
1
1
0
10
0
2/5
1
0
1/5
6
9) We change the other entries, -40 and 1 in the objective-function row and 1st
constraint row respectively, in the pivot column to zeros by arithmetic procedures.
X2 (before)
&40
1
X2 (after)
0
0
Note: We always want to keep the pivot element at "1" and change all the other
numbers in the pivot column to “0.”
a - We multiply the new pivot row by 40:
(0 2/5 1 0 1/5 6) × 40 =
(0 16 40 0 8 240)
and add this to the objective-function row
(1 -10 -40 0 0 0)
and the sum is:
(1 6 0 0 8 240) 7 new objective function row
Page 3 of 9
Location Theory & Decision Analysis
(c) Springer
Linear Program Part 2 - Simplex Algorithm
New tableau:
new obj-fn row
new pivot row
Z
X1
X2
X3
X4
RHS
1
6
0
0
8
240
0
1
1
1
0
10
0
2/5
1
0
1/5
6
b - We multiply the new pivot row by -1:
(0 2/5 1 0 1/5 6) x (-1) =
(0 &2/5 &1 0 &1/5 &6)
and add this to the 1st constraint row:
(0 1 1 1 0 10)
and the sum is:
(0 3/5 0 1 &1/5 4),
New tableau:
Z
X1
X2
X3
X4
RHS
1
6
0
0
8
240
0
3/5
0
1
&1/5
4
0
2/5
1
0
1/5
6
pivot
column
The pivot column has zeros and one "1". In the addition or subtraction operations
between rows, we always want to keep the RHS nonnegative.
10) Are the entries in the objective-function row (the top row) zero or positive? Yes (the
next illustration deals with a "no" answer). We're at the end of the simplex algorithm if
the answer is "yes". The final and optimal tableau is:
Z
X1
X2
X3
X4
RHS
1
6
0
0
8
240
0
3/5
0
1
&1/5
4
0
2/5
1
0
1/5
6
The solution to the problem is read off the tableau as follows:
a - Pick all columns with zeros and one "1".
Page 4 of 9
Location Theory & Decision Analysis
(c) Springer
Linear Program Part 2 - Simplex Algorithm
b - The corresponding RHS on the same row of the "1" is the optimal answer of the
variable.
Z
X1
X2
X3
X4
RHS
1
6
0
0
8
240
0
3/5
0
1
&1/5
4
0
2/5
1
0
1/5
6
Z= 240, X2 = 6, X3 = 4 and all the other variables are equal to zero, X1= 0, X4 = 0.
The optimal answer:
Maximum value of Z = 240 at X1= 0, and X2 = 6. There is a slack of 4 for the 1st
constraint equation, i.e., 4 units of the limited resource represented by the 1st constraint
equation is not used.
NOTE: This specific procedure of the simplex algorithm works only for these conditions:
a - maximizing the objective function.
b - less-than-equal-to inequalities in all the constraint equations
c - nonnegativity
Illustration 10)
Consider:
max Z = 4 X1 + 3 X2 + 6 X3
subject to:
3 X1 + X2 + 3 X3 # 30
2 X1 + 2 X2 + 3 X3 # 40
X1 $ 0, X2 $ 0, X3 $ 0
1) Transform objective function:
Z & 4 X1 & 3 X2 & 6 X3 = 0
2) Add slack variable, X4, to the 1st constraint equation:
3 X1 + X2 + 3 X3 + X4 = 30
3) Add slack variable, X5, to the 2nd constraint equation:
2 X1 + 2 X2 + 3 X3 + X5 = 40
4) Write tableau. (Please fill in the blank entries in the following tableau.)
Page 5 of 9
Location Theory & Decision Analysis
(c) Springer
Linear Program Part 2 - Simplex Algorithm
Z
X1
X2
X3
X4
X5
RHS
1
&4
&3
&6
0
0
0
0
3
0
30
0
2
0
5) Pick pivot column, the column with the smallest numerical value in the objective
row. (Please fill in the blank entries in the following tableau.)
Z
X1
X2
X3
X4
X5
RHS
1
-4
-3
-6
0
0
0
0
3
3
0
30
0
2
3
0
6) Divide the numbers in the RHS column by the numbers in the X3 column, the
pivot column.
X3
RHS
-6
0
3
30 6 30 / 3 = 10
3
The (
(
)6(
)=(
)
) constraint equation has the smallest RHS/X3 ratio. This is the pivot row.
7)
pivot row
Z
X1
X2
X3
X4
X5
RHS
1
-4
-3
-6
0
0
0
0
3
1
3
1
0
30
0
2
2
3
0
1
40
pivot
column
The pivot element is 3.
8) Multiply the pivot row by (
) to change the pivot element into "1". (Please fill in the
blanks in square brackets below.)
pivot row
(0
3
1
3
1
0
Page 6 of 9
30) × (
)=
Location Theory & Decision Analysis
(c) Springer
(0
[
]
Linear Program Part 2 - Simplex Algorithm
[
]
1
[
]
0
[
])
9) New tableau:
Z
X1
X2
X3
X4
X5
RHS
1
-4
-3
-6
0
0
0
0
1
1/3
1
1/3
0
10
0
2
2
3
0
1
40
We want to change
X3 (old)
X3 (new)
-6
0
1
1
3
0
a) Multiply new pivot row by ( ) and add to objective function row to change -6 of the
pivot column to 0.
b) Multiply new pivot row by (
) and add to 2nd constraint equation row to change 3
of the pivot column to 0.
c) Do the arithmetic. (Please show the calculations.)
10) The new tableau after the arithmetic procedures of step 9 is:
Z
X1
X2
X3
X4
X5
RHS
1
2
-1
0
2
0
60
0
1
1/3
1
1/3
0
10
0
&1
1
0
&1
1
10
Are all the entries in the objective function row (top row) zero or positive? 'No". The
entry "&1" in the X2 column is not zero or positive. Therefore, X2 column is the new pivot
column. And again, we calculate the RHS/X2 ratios, except for the objective-function
row.
X2
RHS
-1
60
1/3
1
Page 7 of 9
10 6 10 / (1/3) = (
)
10 6 (
)
)=(
Location Theory & Decision Analysis
(c) Springer
Linear Program Part 2 - Simplex Algorithm
11) The ( ) constraint equation row has the smallest RHS/X2 ratio, thus
it becomes the new pivot row.
new pivot row
Z
X1
X2
X3
X4
X5
RHS
1
2
-1
0
2
0
60
0
1
1/3
1
1/3
0
10
0
&1
1
0
&1
1
10
new
pivot
column
The new pivot element is 1.
We want to change the X2 column as follows:
X2 (old)
X2 (new)
-1
0
1/3
0
1
1
Note: we always want to keep the pivot element at "1" and change all the other
numbers in the pivot column to “0.”
a) Multiply new pivot row by 1 and add to objective-function row to change -1 to 0.
b) Multiply new pivot row by (
) and add to 1st constraint-eqn row to change 1/3 to 0.
c) Do the arithmetic. (Please show the calculations.)
12) The new tableau after the arithmetic procedures of step 11:
Z
X1
X2
X3
X4
X5
RHS
1
1
0
0
1
1
70
0
4/3
0
1
2/3
&1/3
20/3
0
&1
1
0
&1
1
10
Are all the entries in the objective function row (top row) zero or positive? "Yes". We
have arrived at the final and optimal tableau.
Page 8 of 9
Location Theory & Decision Analysis
(c) Springer
Linear Program Part 2 - Simplex Algorithm
Z
X1
X2
X3
X4
X5
RHS
1
1
0
0
1
1
70
0
4/3
0
1
2/3
&1/3
20/3
0
&1
1
0
&1
1
10
The optimal answer:
Z = 70
X1 = (
X2 = (
)
)
X3 = (
)
X4 = (
)
X5 = (
)
Illustration 11)
Apply the simplex algorithm to the ice-cream plant illustration. (Please show all the
calculations in all the tableaux.)
X1 = number of quarts of chocolate produced
X2 = number of quarts of vanilla produced
max Z = 13 X1 + 10 X2
X1
+ X2 # 1,000
X1
# 600
X2 # 800
X1 $ 0, X2 $ 0.
(Plant capacity constraint)
(Chocolate sale constraint)
(Vanilla sale constraint)
CONCLUSION
In this simplex and the model formulation modules, we have studied various LP models
and the simplex solution algorithm. It can be seen that LPs are used frequently to
configure processes, programs, and plans. These examples are used for the sole
purpose of learning the basic techniques. The simplex algorithm illustrated in this
module is limited to LP models formulated in a particular format. In real life situations,
LP models usually assume many different forms, and they have hundreds and
thousands of variables and constraint equations. Thus, a more advanced
understanding of LP and computer programs are essential in solving these LP models.
Chapter 4 (entitled “Prescriptive Tools”) and Appendix 4 of this text (entitled
“Optimization Schemes”) will provide more depth in linear programming. Many available
software packages are quite efficient in handling LP models of large size. For
convenience, the author has included a software survey in both the conclusion chapter
and in the accompanying CD at the back of this book.
Page 9 of 9
Download