Computer simulation

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
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
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
Computer Simulation of Coin-Flipping Game
A
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
B
C
D
E
F
Total
Heads
0
1
2
2
2
2
2
2
3
Total
Tails
1
1
1
2
3
4
5
6
6
G
Coin-Flipping Game
Required Difference
Cash At End of Game
3
$8
Summary of Game
Number of Flips
7
Winnings
$1
Flip
1
2
3
4
5
6
7
8
9
Random
Number
0.9016
0.0515
0.4396
0.6349
0.8241
0.7694
0.6820
0.9856
0.2223
Result
Tails
Heads
Heads
Tails
Tails
Tails
Tails
Tails
Heads
Stop?
Stop
NA
NA
12-5
Data Table for 14 Replications of Coin-Flipping Game
I
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
J
K
L
M
Data Table for Coin-Flipping Game
(14 Replications)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Number
of Flips
7
19
5
3
11
9
5
5
3
3
5
5
5
9
3
Winnings
$1
-$11
$3
$5
-$3
-$1
$3
$3
$5
$5
$3
$3
$3
-$1
5
Average
6.43
$1.57
Play
Select the
whole table
(J6:L20),
before
choosing
Table from
the Data
menu.
12-6
Data Table for 1000 Replications of Coin-Flipping Game
I
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1001
1002
1003
1004
1005
1006
1007
1008
J
K
L
M
Data Table for Coin-Flipping Game
(1000 Replications)
1
2
3
4
5
6
7
8
9
10
995
996
997
998
999
1000
Number
of Flips
5
3
9
9
5
5
9
5
7
5
11
5
7
7
7
17
19
Winnings
$3
$5
-$1
-$1
$3
$3
-$1
$3
$1
$3
-$3
$3
$1
$1
$1
-$9
-$11
Average
8.83
-$0.83
Play
12-7
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
Spreadsheet Model for Applying Simulation
A
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
B
C
D
E
F
Discrete Uniform
Minimum
40
Max imum
70
Freddie the Newsboy
Unit Sale Price
Unit Purchase Cos t
Unit Salvage Value
Order Quantity
Demand
Data
$2.50
$1.50
$0.50
Decision Variable
60
Simulation
55
Sales Revenue
Purchasing Cost
Salvage Value
$137.50
$90.00
$2.50
Profit
$50.00
13-9
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
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.
2.
3.
4.
5.
6.
Select the cell by clicking on it.
If the cell does not already contain a value, enter any number into the cell.
Click on the Define Assumption button.
Select a probability distribution from the Distribution Gallery.
Click OK to bring up the dialogue box for the selected distribution.
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
Crystal Ball Distribution Gallery
13-12
Crystal Ball Uniform Distribution Dialogue Box
13-13
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
Crystal Ball Define Forecast Dialogue Box
13-15
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
The Crystal Ball Run Preferences Dialogue Box
13-17
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
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
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
The Uniform Distribution
•
•
Fixed minimum and maximum value
All values equally likely
13-21
The Discrete Uniform Distribution
•
•
Fixed minimum and maximum value
All integer values equally likely
13-22
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
Yes-No Distribution
•
•
Describes whether an event occurs or not
Two possible outcomes: 1 (Yes) or 0 (No)
13-24
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