Computer Simulation

25
Computer Simulation

description

Computer Simulation. The Essence of Computer Simulation. A stochastic system is a system that evolves over time according to one or more probability distributions. - PowerPoint PPT Presentation

Transcript of Computer Simulation

Page 1: Computer Simulation

Computer Simulation

Page 2: Computer Simulation

The Essence of Computer Simulation

• A stochastic system is a system that evolves over time according to one or more probability distributions.

• Computer simulation imitates the operation of such a system by using the corresponding probability distributions to randomly generate the various events that occur in the system.

• Rather than literally operating a physical system, the computer just records the occurrences of the simulated events and the resulting performance of the system.

• Computer simulation is typically used when the stochastic system ivolved is too complex to be analyzed satisfactorily by analytical models.

12-2

Page 3: Computer Simulation

Example 1: A Coin-Flipping Game

• Rules of the game:1. Each play of the game involves repeatedly flipping an unbiased coin until the

difference between the number of heads and tails tossed is three.2. To play the game, you are required to pay $1 for each flip of the coin. You are not

allowed to quit during the play of a game.3. You receive $8 at the end of each play of the game.

• Examples:

HHH 3 flips You win $5

THTTT 5 flips You win $3

THHTHTHTTTT 11 flips You lose $3

12-3

Page 4: Computer Simulation

Computer Simulation of Coin-Flipping Game

• A computer cannot flip coins. Instead it generates a sequence of random numbers.

• A number is a random number between 0 and 1 if it has been generated in such a way that every possible number within the interval has an equal chance of occurring.

• An easy way to generate random numbers is to use the RAND() function in Excel.

• To simulate the flip of a coin, let half the possible random numbers correspond to heads and the other half to tails.– 0.0000 to 0.4999 correspond to heads.– 0.5000 to 0.9999 correspond to tails.

12-4

Page 5: Computer Simulation

Computer Simulation of Coin-Flipping Game

123456789101112131415161718192021

A B C D E F GCoin-Flipping Game

Required Difference 3Cash At End of Game $8

Summary of GameNumber of Flips 7

Winnings $1

Random Total TotalFlip Number Result Heads Tails Stop?1 0.9016 Tails 0 12 0.0515 Heads 1 13 0.4396 Heads 2 14 0.6349 Tails 2 25 0.8241 Tails 2 36 0.7694 Tails 2 47 0.6820 Tails 2 5 Stop8 0.9856 Tails 2 6 NA9 0.2223 Heads 3 6 NA

12-5

Page 6: Computer Simulation

Data Table for 14 Replications of Coin-Flipping Game

12345678910111213141516171819202122

I J K L MData Table for Coin-Flipping Game(14 Replications)

NumberPlay of Flips Winnings

7 $11 19 -$112 5 $33 3 $54 11 -$35 9 -$16 5 $37 5 $38 3 $59 3 $5

10 5 $311 5 $312 5 $313 9 -$114 3 5

Average 6.43 $1.57

Select the whole table (J6:L20), before choosing Table from the Data menu.

12-6

Page 7: Computer Simulation

Data Table for 1000 Replications of Coin-Flipping Game

12345678910111213141516

10011002100310041005100610071008

I J K L MData Table for Coin-Flipping Game(1000 Replications)

NumberPlay of Flips Winnings

5 $31 3 $52 9 -$13 9 -$14 5 $35 5 $36 9 -$17 5 $38 7 $19 5 $3

10 11 -$3995 5 $3996 7 $1997 7 $1998 7 $1999 17 -$91000 19 -$11

Average 8.83 -$0.83

12-7

Page 8: Computer Simulation

Freddie the Newsboy

• Freddie runs a newsstand in a prominent downtown location of a major city.

• Freddie sells a variety of newspapers and magazines. The most expensive of the newspapers is the Financial Journal.

• Cost data for the Financial Journal:– Freddie pays $1.50 per copy delivered.– Freddie charges $2.50 per copy.– Freddie’s refund is $0.50 per unsold copy.

• Sales data for the Financial Journal:– Freddie sells anywhere between 40 and 70 copies a day.– The frequency of the numbers between 40 and 70 are roughly equal.

13-8

Page 9: Computer Simulation

Spreadsheet Model for Applying Simulation

123456789

101112131415161718

A B C D E F

Freddie the Newsboy

DataUnit Sale Price $2.50

Unit Purchase Cost $1.50Unit Salvage Value $0.50

Decision VariableOrder Quantity 60

Simulation Minimum MaximumDemand 55 Discrete Uniform 40 70

Sales Revenue $137.50Purchasing Cost $90.00

Salvage Value $2.50

Profit $50.00

13-9

Page 10: Computer Simulation

Application of Crystal Ball

• Four steps must be taken to use Crystal Ball on a spreadsheet model:

1. Define the random input cells.

2. Define the output cells to forecast.

3. Set the run preferences.

4. Run the simulation.

13-10

Page 11: Computer Simulation

Step 1: Define the Random Input Cells

• A random input cell is an input cell that has a random value.

• An assumed probability distribution must be entered into the cell rather than a single number.

• Crystal Ball refers to each such random input cell as an assumption cell.

• Procedure to define an assumption cell:1. Select the cell by clicking on it.2. If the cell does not already contain a value, enter any number into the cell.3. Click on the Define Assumption button.4. Select a probability distribution from the Distribution Gallery.5. Click OK to bring up the dialogue box for the selected distribution.6. Use the dialogue box to enter parameters for the distribution (preferably referring to

cells on the spreadsheet that contain these parameters).7. Click on OK.

13-11

Page 12: Computer Simulation

Crystal Ball Distribution Gallery

13-12

Page 13: Computer Simulation

Crystal Ball Uniform Distribution Dialogue Box

13-13

Page 14: Computer Simulation

Step 2: Define the Output Cells to Forecast

• Crystal Ball refers to the output of a computer simulation as a forecast, since it is forecasting the underlying probability distribution when it is in operation.

• Each output cell that is being used to forecast a measure of performance is referred to as a forecast cell.

• Procedure for defining a forecast cell:1. Select the cell.2. Click on the Define Forecast button on the Crystal Ball tab or toolbar, which brings

up the Define Forecast dialogue box.3. This dialogue box can be used to define a name and (optionally) units for the

forecast cell.4. Click on OK.

13-14

Page 15: Computer Simulation

Crystal Ball Define Forecast Dialogue Box

13-15

Page 16: Computer Simulation

Step 3: Set the Run Preferences

• Setting run preferences refers to such things as choosing the number of trials to run and deciding on other options regarding how to perform the simulation.

• This step begins by clicking on the Run Preferences button on the Crystal Ball tab or toolbar.

• The Run Preferences dialogue box has five tabs to set various types of options.

• The Trials tab allows you to specify the maximum number of trials to run for the computer simulation.

13-16

Page 17: Computer Simulation

The Crystal Ball Run Preferences Dialogue Box

13-17

Page 18: Computer Simulation

Step #4: Run the Simulation

• To begin running the simulation, click on the Start Simulation button.

• Once started, a forecast window displays the results of the computer simulation as it runs.

• The following can be obtained by choosing the corresponding option under the View menu in the forecast window display:– Frequency chart– Statistics table– Percentiles table– Cumulative chart– Reverse cumulative chart

13-18

Page 19: Computer Simulation

Choosing the Right Distribution

• A continuous distribution is used if any values are possible, including both integer and fractional numbers, over the entire range of possible values.

• A discrete distribution is used if only certain specific values (e.g., only some integer values) are possible.

• However, if the only possible values are integer numbers over a relatively broad range, a continuous distribution may be used as an approximation by rounding any fractional value to the nearest integer.

13-19

Page 20: Computer Simulation

A Popular Central-Tendency Distribution: Normal

• Some value most likely (the mean)• Values close to mean more likely• Symmetric (as likely above as below mean)• Extreme values possible, but rare

13-20

Page 21: Computer Simulation

The Uniform Distribution

• Fixed minimum and maximum value• All values equally likely

13-21

Page 22: Computer Simulation

The Discrete Uniform Distribution

• Fixed minimum and maximum value• All integer values equally likely

13-22

Page 23: Computer Simulation

A Distribution for Random Events: Exponential

• Widely used to describe time between random events (e.g., time between arrivals)• Events are independent• Rate = average number of events per unit time (e.g., arrivals per hour)

13-23

Page 24: Computer Simulation

Yes-No Distribution

• Describes whether an event occurs or not• Two possible outcomes: 1 (Yes) or 0 (No)

13-24

Page 25: Computer Simulation

Distribution for Number of Times an Event Occurs: Binomial

• Describes number of times an event occurs in a fixed number of trials (e.g., number of heads in 10 flips of a coin)

• For each trial, only two outcomes are possible• Trials independent• Probability remains the same for each trial

13-25