7 - 1 16 - 1 chapter 16: optimization in simulation powerpoint slides prepared by: alan olinsky...

35
16 - 1 7 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling with Spreadsheets, 2e S.G. Powell K.R. Baker © John Wiley and Sons, Inc.

Upload: flora-mcbride

Post on 01-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 17 - 1

Chapter 16: Optimization In Simulation

PowerPoint Slides Prepared By:Alan Olinsky Bryant University

Management Science: The Art of Modeling with Spreadsheets, 2e

S.G. Powell

K.R. Baker

© John Wiley and Sons, Inc.

Page 2: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 2

Introduction

We would like to marry the power of optimization to identify the best decision variables with the power of simulation to describe outcome distributions.

Unfortunately, the optimization approaches using Solver are all based on the premise that the objective function can be measured deterministically.

But in simulation models the objective function is the expected value or some other function of a random variable.

Solver cannot be used to optimize these models. However, there are a number of practical approaches to

optimizing simulation models.

Page 3: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 3

Grid Search

In a grid search, we select a series of values we wish to test for a decision variable, and we run the simulation at each of these values.

When our model is particularly simple, there is an efficient approach to grid search.

The trick is to replicate the model for each value of the decision variable we wish to test.

Page 4: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 4

Trend Chart

Crystal Ball provides a specialized chart called a trend chart, which can be used to depict the sensitivity of Forecast cells to decision variables or other inputs.

After the simulation run is finished, we select Analyze►Trend Charts.

The Crystal Ball trend chart is a handy way to display the sensitivity of an output variable to any input that ranges over multiple values.

It is a natural way to perform optimization in simple simulation models with a single decision variable, provided that the median outcome is a reasonable objective.

It also provides a convenient device for displaying the trade-off between the median outcome and the risks of extreme outcomes.

Page 5: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 5

Trend Chart with Uncertainty Bands

Page 6: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 6

Using CB Sensitivity

The CB Sensitivity tool can also be used for optimization.

It is particularly useful for models that are too complex for the replication approach, or when we want to vary two inputs (either decision variables or other parameters).

Page 7: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 7

CB Sensitivity Table

Page 8: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 8

Complex Optimization Problems

When the problem involves three or more decision variables, and possibly constraints as well, we turn to a sophisticated Crystal Ball tool called OptQuest, which optimizes the choice of decision variables when the objective function is based on simulation outcomes.

Page 9: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 9

OptQuest Concepts

Objective: Forecast cell to be maximized or minimized. OptQuest allows the user to optimize any one of various summary measures of the objective—for example, mean, standard deviation, or 10th percentile.

Decision variables: Spreadsheet parameters OptQuest uses to optimize the objective. These must be defined as Decision cells in Crystal Ball.

Constraint: OptQuest allows any number of linear constraints among the decision variables. Solutions that violate these constraints are not considered feasible and are not reported.

Requirement: A constraint on a summary measure of a Forecast. For example, we could require that the standard deviation not exceed a set limit. Requirements can be evaluated only after a simulation run; thus, OptQuest may report a solution that violates a requirement, but it will label the solution as infeasible.

Page 10: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 10

OptQuest Approach

OptQuest takes a heuristic approach to optimization, by which we mean that it searches intelligently for better and better solutions, but OptQuest cannot guarantee that it finds the global optimum.

As a consequence, we must take extra care to ensure that the results OptQuest gives us are sensible.

OptQuest uses three distinct heuristics in its search for optimal solutions: scatter search, tabu search, and neural networks.

Page 11: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 11

Scatter Search

Scatter search generates an initial population of candidate solutions and uses simulation to estimate the objective for each one.

It then creates the next generation of solutions by taking combinations of the previous solutions.

At each generation, the best solutions are saved and the worst discarded.

In this fashion, the general quality (by which we mean the value of the objective function) of the population of solutions improves over time.

Page 12: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 12

Tabu Search

Tabu search is superimposed on the scatter search to control and direct the generation of solutions.

Tabu search uses computer memory in various ways to ensure that the search does not reinvestigate solutions that have already been evaluated (such solutions are “tabu”) and to ensure that the population remains sufficiently diverse over time.

Page 13: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 13

Neural Networks

Finally, neural networks can be used (at the option of the user) to quickly screen out candidate solutions that are likely to result in poor values of the objective.

A neural network is a predictive model that, in this case, predicts the objective function value for a candidate solution based on all the past solutions that have been evaluated.

Using these heuristics, OptQuest can evaluate hundreds or thousands of candidates, depending on the time it is given and the complexity of the model, and it often finds optimal or near optimal solutions to quite complex problems.

Page 14: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 14

Setting up Spreadsheet for OptQuest

To set up the spreadsheet for OptQuest, we must define the decision variables, the constraints (if any), the objective function, and any requirements.

Uncertain parameters (Assumption cells), outputs (Forecast cells), and decision variables (Decision cells) are all defined before opening the OptQuest program; the remaining inputs are defined within OptQuest itself.

Page 15: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 15

The Decision Variable Window in Crystal Ball

Page 16: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 16

Random Numbers

It is also important to set the random number seed (in Crystal Ball, check Use same sequence of random numbers under Run►Run Preferences►Sampling) so that the same random outcomes are used on every OptQuest run.

This reduces the variance between runs and makes the search for an optimum more efficient.

Page 17: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 17

Running OptQuest

We open OptQuest by choosing Run►OptQuest. (It is a good idea to have only one spreadsheet open in Crystal Ball when running OptQuest.)

Within OptQuest, we click on the New button, and OptQuest opens the OptQuest Wizard.

This Wizard brings up four windows in turn: Decision Variable Selection, Constraints, Forecast Selection, and Options.

We can edit the default information in these windows, or click OK to accept them as given.

We can also return to any of these windows by making a selection from the OptQuest Tools menu or its Window menu.

Page 18: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 18

Decision Variable Selection, Constraints, and Forecast

Selection Windows

Page 19: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 19

OptQuest Windows

When OptQuest begins a run, it opens a Status and Solutions window. This window shows the values of the Decision cells and the Forecast cells for the

current run, the best run so far, and a number of previous runs. Two other useful windows can be opened from the OptQuest menu: the Performance

Graph and the Current Decision Variables bar graph. The Performance Graph shows the value of the objective for the best alternative

found so far during the search. This graph shows the best value of the objective generally increasing (for

maximization) or decreasing (for minimization) as the search progresses. In most cases, it changes quickly early in the run, as improvements are being found

frequently, and then it changes more slowly as better solutions become harder to find.

It is a good idea to watch this graph during an OptQuest run, as it gives a good overall indication of how the search is progressing.

The Current Decision Variables window, which shows the values of the decision cells being tested on the current run, may also be helpful by providing a visual sense of which combinations of decision variables are being tested.

Page 20: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 20

OptQuest Results

Page 21: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 21

OptQuest Solution Analysis

Page 22: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 22

Rules of Thumb for Running OptQuest

Experiment with different values of the decision variables to make sure the objective function responds to each decision variable in the way we expect.

Start the search for an optimal solution with a small number of trials in Crystal Ball, a coarse grid for the Decision variables, and a short OptQuest run time. (Seldom can the optimal solution be identified reliably in a single run of OptQuest.)

Page 23: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 23

Rules of Thumb for Running OptQuest

Refine the search for the optimal solution by increasing the number of trials in Crystal Ball, refining the grid for the Decision variables, or increasing the OptQuest run time.

Use OptQuest’s Solution Analysis procedure to examine the best 5 or 10 percent of all the solutions.

Limit the number of decision variables by the use of decision rules that relate decision variables to other variables in the model.

Page 24: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 24

Searching for an Optimal Solution

In the initial runs it is useful to set the number of trials in Crystal Ball to a small value so that OptQuest has time to examine a reasonably large number of solutions. (If the number of trials is too small and the simulation error is too high, OptQuest could settle on a solution that appears optimal only because simulation error leads to a high value of the objective.)

Likewise, it is good practice to set wide limits on the range for the Decision variables (so as not to miss the true optimal value), but also to define the Decision variables as discrete with a large step size.

This specification gives OptQuest fewer alternatives to examine. Finally, initial OptQuest runs should be fairly short (say 2-5 minutes) so that bugs are found quickly and the learning process is efficient.

Often, a near-optimal solution can be identified even in these early OptQuest runs.

In later runs, we can always refine the search if more accuracy is needed.

Page 25: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 25

Crystal Ball Tip: Rules of Thumb for OptQuest

Using CB Sensitivity, check that the objective function is concave in each Decision variable.

For initial testing: set the number of trials in Crystal Ball to a small value define the Decision variables as discrete with a small number of allowable values set a short OptQuest run length

In subsequent testing: increase the number of trials in Crystal Ball increase the number of allowable values for discrete Decision variables and/or convert

them to continuous variables increase the OptQuest run length

Use Solution Analysis to determine whether the top solutions are consistent, suggesting that a true optimal solution has been identified.

Reduce the number of decision variables by parameterization.

Page 26: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 26

Embedded-Decision Problems

Their main characteristics are the following: At the first stage, there is a need to make a set of

long-term decisions in the face of uncertainty. In the second stage, the uncertainty is resolved, that

is, the uncertain factors become known. At the third stage, there is a need to make short-

term decisions, given the outcomes of the uncertain factors and the constraints imposed by the long-term decisions.

Page 27: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 27

Embedded Optimization: Using Solver within Crystal Ball

We set up a simulation using Crystal Ball, and we then optimize by embedding a macro that will run Solver within Crystal Ball.

We then call on OptQuest to search for the optimal solutions.

Page 28: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 28

Creating a Macro to Embed Solver

Optimization within a Crystal Ball simulation requires the use of an Excel macro to invoke Solver.

A macro is simply a stored series of Excel commands that can be executed automatically, without user intervention.

Excel has the capability of recording the commands entered by a user at the keyboard, so the simplest way to create a macro is to set up the macro recorder and click through the sequence of commands.

Page 29: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 29

Creating a Macro to Embed Solver

The first step is to build a deterministic spreadsheet, treating both decision variables and random inputs as fixed numbers.

Next, we reserve a separate part of the spreadsheet for generating the random inputs. (The separation is necessary because we do not want the random inputs to change within a Solver run.)

Then, we invoke Solver and define the objective function, decision variables, and constraints in our short term model.

We must actually run Solver once for the overall process to work properly.

Finally, we create the random inputs in their reserved location (using Crystal Ball distribution functions or the Distribution Gallery), copy their values into the appropriate cells in the model, and execute Solver.

At this point, we are ready to record the macro.

Page 30: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 30

Crystal Ball Tip: Macro for Embedding Solver in Crystal Ball

Start the macro recorder: Tools►Macros►Record New Macro. Give the macro a name such as EmbedSolver, assign a shortcut key to it, and

save it in This Workbook. Click on OK, and the Stop Recording Macro button appears on the spreadsheet. Highlight the random inputs. Choose Edit►Copy. Highlight the range where the random inputs are needed. Choose Edit►Paste Special. Select Paste►Values. Click on OK. Choose Tools►Solver►Solve. When Solver finishes, click on OK. Select the objective function cell. Click on the Stop Recording icon in the Macro Recording window.

Page 31: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 31

Crystal Ball Tip: Macro for Embedding Solver in Crystal Ball

Two additional changes are required to the macro as recorded. To edit the macro choose Tools►Macro►Macros. With the macro name highlighted, choose Edit. This step opens

the Visual Basic Editor. First, make sure Solver is linked to the macro by checking

Solver.xla under Tools►References. Second, find the macro in the Project Explorer window on the left

of the Visual Basic Editor under VBA Projects (Plant.xls)/Modules.

Change SolverSOLVE to SolverSOLVE (True) where it appears in the macro itself. (This command turns off the Solver completion message so that the Crystal Ball run is not interrupted when Solver finishes execution.)

Page 32: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 32

Macro and Function for Embedding Solver in Crystal Ball

MacroPublic Sub EmbedSolver() Range("C17:G17").Select Selection.Copy Range("C13:G13").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False SolverOk SetCell:="$B$15", MaxMinVal:=1, ValueOf:=0, ByChange:="$C$9:$G$11", _ Engine:=2, EngineDesc:="Standard Simplex LP" SolverSolve (True) Range("B15").SelectEnd SubFunctionPublic Function CBAfterTrial(aTrial As Long) As Integer Call EmbedSolverEnd Function

Page 33: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 33

Summary

Simulation is primarily a way to describe the range of uncertainty in the results of a model.

Simulation models with one or two variables can be optimized using a variety of techniques.

Grid search is the general name for a procedure in which we evaluate the objective over a range of values of the decision variables.

Grid search can be automated using the Crystal Ball Sensitivity tool. To optimize simulation models with three or more decision variables

requires the use of OptQuest. OptQuest is a sophisticated add-in to Crystal Ball that uses heuristic

search procedures to find the optimal values of decision variables. OptQuest can also deal with the complications of constraints on the

decision variables and requirements on the outcome distribution.

Page 34: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 34

Summary

Because OptQuest uses a heuristic search procedure, we cannot be guaranteed of finding the optimal solution.

However, we provide rules of thumb for using OptQuest that substantially improve the quality of its solutions.

Embedded-decision problems are ones in which decisions and random outcomes alternate.

In these problems, we first make strategic decisions for the long-run, then learn about the value of random factors, and finally, make tactical decisions within the constraints imposed by our strategic decisions.

These problems can be handled by combining the capabilities of Solver and Crystal Ball.

Solver is used to determine the optimal tactical decisions given the values of the uncertain factors.

Crystal Ball is used to simulate the uncertain factors and to optimize the strategic decisions (using OptQuest).

Page 35: 7 - 1 16 - 1 Chapter 16: Optimization In Simulation PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling

16 - 35

Copyright 2008 John Wiley & Sons, Inc.

All rights reserved. Reproduction or translation of this work beyond that permitted in section 117 of the 1976 United States Copyright Act without express permission of the copyright owner is unlawful. Request for further information should be addressed to the Permissions Department, John Wiley & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages caused by the use of these programs or from the use of the information herein.