Professional Documents
Culture Documents
Chap 15
Chap 15
COMPUTER SIMULATION:
THE GENERAL
METHODOLOGY
In all the examples throughout this book, it has been possible to obtain solutions through mathematical techniques. When dealing with some real-world problems, however, the resulting model may
be so complex or large that it is not possible or practical to develop a solution methodology based
on mathematical analysis. Alternatively, to apply an existing mathematical technique may require
additional assumptions that are not applicable or realistic.
In such cases, an alternative approach is to use the management science technique of computer
simulation. As the term indicates, with this technique you design and build a computer model
that mimics the actual problem scenario. You then use the model to learn how the system behaves
asking managerial What happens if ...? questions. For example, you might build a computer
model to simulate:
1. The daily operation of a bank or hospital, to understand the impact of adding more tellers
or nurses.
2. The operation of a harbor or airport, to understand the flow of trac and its associated
congestion.
3. The production process in a manufacturing plant, to identify bottlenecks in the production
line.
4. The trac flow on a freeway or in a complicated communication system, to determine
whether expansion is necessary.
To illustrate the basic concepts used in designing a computer simulation model, two elementary
examples are presented in Section 15.1. Then, the advantages and disadvantages of this technique
are discussed.
15.1
In this section two examples illustrate the basic steps involved in building a simulation model.
1
Chapter 15
Lottery
Row 1
Card
Row 2
Row 3
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
Figure 15.1: Instant Lottery Card for the New York Lottery Commission
15.1.1
Probability
winning $1
of
+ $5
Probability
winning $5
of
It is now necessary to determine the probability of winning each of $1 and $5. Observe that there
is an even chance of scratching either value in each row, and recall the rules of the game, so
Probability of winning $1
1/8.
Chapter 15
Similarly,
Probability of winning $5
1/8.
Probability
winning $1
= $1
(1/8)
of
+ $5
Probability
winning $5
+ $5
(1/8)
of
= $0.75.
In other words, by charging $0.75 the Commission can expect to break even in the long run.
In this problem it is possible to obtain the desired result directly by mathematical analysis.
However, this example is also used to illustrate how the methodology of computer simulation is
applied to obtain a similar result.
The idea of simulation is to mimic the actual situation in which a large number of people are
expected to play the new lottery game. Three dierent ways to do so are now described.
Physical Simulation
You might simulate the game physically as follows. Print a large number of cards (say, 100), have
someone scratch the boxes on each card, tabulate the payo for each card ($0, $1, or $5), and use
the payos from all the cards to compute the average payo. This process provides an estimate of
the expected payo and that can be used as the basis for making decision. To obtain an accurate
estimate would require printing a large number of cards just for this experiment, but this is both
costly and time consuming. The next alternative avoids some of these problems.
Simulation by Analogy
Rather than simulate this game physically, you might simulate the game by analogy. For example,
consider the analogy between scratching a box in one row of the card and flipping a coin. The value
of the box scratched in each row is either $1 or $5, with equal probability. Similarly, the value of
a coin flip is either heads or tails, with equal probability. Here, heads by analogy is $1 and
tails by analogy is $5. You can simulate the lottery results by following these steps a large number
of times (say, 100):
1. Flip a coin three times, once to determine the outcome for each row.
2. Record the associated payo for the outcome in (1): $1 if all three flips are heads, $5 if
all three flips are tails, and $0 otherwise.
Chapter 15
Head
Tail
-
0.0
0.5
1.0
Figure 15.2: Simulating the Flip of a Coin Using a Uniform 0 1 Random Number
Adding up the payos of these 100 trials and dividing by 100 provides an estimate of the expected
payo for the game.
This approach has eliminated the need to print the 100 cards, but it requires significant manual
eort to flip the coins, tabulate the results, and perform the final computations. The repetitive
nature of these tasks makes them ideally suited for the computer.
Simulation by Computer
How can you use a computer to flip the coin, tabulate the results, and perform the needed
computations? The answer is to write a computer program in which the flipping of the coin is
accomplished using random numbers to represent the result of the flip. For instance, all computer
languages include the capability of generating a random number uniformly distributed between 0
and 1 (see Appendix B). You can then associate a value between 0.0 and 0.5 as corresponding to
the outcome of a head and a value exceeding 0.5 and less than or equal to 1.0 corresponding
to a tail, as shown in Figure 15.2. Because the random numbers are uniformly distributed, the
outcome of a head and a tail is equally likely.
With this capability, the computer simulation consists of repeating the following steps a large
number of times (say, 100):
1. Generate three uniformly-distributed random numbers between 0 and 1 corresponding to
the outcomes of the three coin flips.
2. Record the payo of $1 if all three numbers are less than or equal to 0.5 (all three heads),
$5 if all three numbers are greater than 0.5 (all three tails), and $0 otherwise.
Finally, the computer can be programmed to add up these 100 payos and divide the total by 100
to obtain an estimate of the expected payo.
Normally, you would write a computer program to generate the random numbers in this simulation. For illustration purposes, however, the random numbers in the table in Appendix D are used
instead. These random numbers were generated by a computer.
To begin the simulaion, arbitrarily start with any number in the table and choose successive
numbers, by row, as needed. For example, to simulate one trial of the new lottery card, choose any
three consecutive numbers in a row of the table say, row 2 leading to the following results:
Chapter 15
Table 15.1: The Results of Simulating the First 5 Cards for the Problem of the New York Lottery
Commission
Row 1
Random H/
$
Trial number T Amt.
1
2
3
4
5
0.995255
0.894206
0.937265
0.524444
0.287153
T
T
T
T
H
$5
$5
$5
$5
$1
Row 2
Random H/
$
number T Amt.
0.577849
0.332668
0.520743
0.540955
0.639474
T
H
T
T
T
$5
$1
$5
$5
$5
Row 3
Random H/
$
number T Amt. Payo
0.980588
0.355729
0.449925
0.802009
0.535043
T
H
H
T
T
$5
$1
$1
$5
$5
5.00
0.00
0.00
5.00
0.00
Outcomes
Flip number Random number Flip result $ Amount
1
2
3
0.995255
0.577849
0.980588
Tails
Tails
Tails
5
5
5
This trial corresponds to scratching a $5 value in each of the three rows and therefore results in
a payo of $5. For the second trial, use the next three random numbers in row 2 of the table in
Appendix D:
Outcomes
Flip number Random number Flip result $ Amount
1
2
3
0.894205
0.332668
0.355729
Tails
Heads
Heads
5
1
1
This trial corresponds to scratching a $5 value in the first row of the card and a $1 value in the
second and third rows, resulting in a payo of $0.
The first 5 trials thus obtained are shown in Table 15.1. Continuing this process for a total
of 100 trials results in a total payo of $82.00, which provides an estimate of the expected payo
of 82/100 = $0.82 per card. Observe that this value is higher than the actual expected payo of
$0.75 obtained using probability theory. To obtain a more accurate estimate of the expected payo,
you will need to perform many more trials than the 100 performed in this example. The details of
determining how many more trials are necessary is discussed in Chapter 16.
Observe that the approach of computer simulation has overcome the drawbacks of the previous
two methods by eliminating the cost associated with printing the cards in the physical simulation
and the time and manual eort needed to flip the coins and tabulate the results in the simulation
by analogy. Moreover, once the computer program is written and tested, it is a simple matter
to perform the experiment 100,000 times instead of 100 times to obtain a better estimate of the
expected payo.
15.1.2
Chapter 15
Example 15.2 The Computer Simulation of the Problem of First-Run Videos, Inc.
First-Run Videos, Inc., is a company that purchases first-run videos for $25 a copy, rents them
for $3 per day, and after one month sells them to another store for $5 a copy. Based on historical
data, the company has estimated the following probabilities of daily demand for each movie:
Number of copies
Probability
0
1
2
3
4
0.15
0.25
0.45
0.10
0.05
As manager of First-Run Videos, Inc., you want to decide how many copies of each new movie to
order: 0, 1, 2, 3, or 4.
It is again possible to apply probability theory to obtain the desired answer. The optimal decision
is the one that results in the largest expected profit over the life of the video, which is one month
(30 days). To illustrate, suppose that 3 copies are ordered. In this case:
Expected profit
In computing the expected revenue on a given day, keep in mind that there are only three copies of
the tape available for rental. A fourth demand for a particular movie during any one day cannot be
met and thus generates no additional income. Therefore, the expected daily revenue is computed as
follows:
Expected revenue per day
Therefore,
$0
$3
$6
$9
$9
Probability
Probability
Probability
Probability
Probability
of
of
of
of
of
0
1
2
3
4
requests
requests
requests
requests
requests
(0 0.15) + (3 0.25) +
(6 0.45) + (9 0.10) + (9 0.05)
$4.80.
+
+
+
+
Chapter 15
Table 15.2: Expected Profits for the Problem of First-Run Videos, Inc.
Number of Purchase
Expected revenue
Resale
Net
copies
cost ($) ($/day) ($/month) value ($) profit ($)
0
1
2
3
4
Expected profit
0
25
50
75
100
0.00
2.55
4.35
4.80
4.95
0.00
76.50
130.50
144.00
148.50
0
5
10
15
20
$60
($4.80 30)
$60
0.00
56.50
90.50
84.00
68.50
$84.
In other words, purchasing three copies of the video is expected to result in a profit of $84 at the end
of the month. The results of performing similar computations for ordering 0, 1, 2, 3 and 4 tapes are
given in Table 15.2. You can see that ordering two copies of the video is optimal because it results
in the largest profit, $90.50.
For this problem, it has again been possible to obtain the desired results by direct mathematical
analysis. The methodology of computer simulation is now used to achieve a similar result. So
suppose you decide to order two copies of the tape at a cost of $50.
To estimate the expected revenues using simulation, it is necessary to mimic the process of customers requesting copies of the video tape over a 30-day period and then perform the computations
to determine the associated revenues and, ultimately, the total profit. In particular, the following
steps are performed for each of the 30 days in the month:
1. Generate the daily demand, that is, the number of requests for this tape on the given day
according to the probability distribution given in the problem description.
2. Compute the associated rental revenue based on the fact that you have two copies of the
tape available.
Subsequently, the total expected profit is computed by:
Total expected profit
To obtain the total rental revenue, as described in steps (1) and (2) above, it is necessary to
generate the daily demand according to the following table:
Chapter 15
Demand
?
0
4
-
0.15
0.40
0.85
0.95 1
Uniform
Random
Number
Figure 15.3: Generating the Daily Demand Using a Uniform 0 1 Random Number
Number of copies
Probability
0
1
2
3
4
0.15
0.25
0.45
0.10
0.05
Once again, uniformly-distributed random numbers between 0 and 1 can be used to do so. The idea
is to use the capability of the computer language to generate such a random number and use its
value to determine an associated daily demand in such a way that there is a 15% chance that the
resulting demand is 0, a 25% chance that it is 1, and so on. This can be accomplished as shown
in Figure 15.3. That is, generate a uniform random number between 0 and 1 and determine the
associated daily demand according to the following table:
Range of uniform
number
Associated
daily demand
0
1
2
3
4
0.00
0.15
0.40
0.85
0.95
0.15
0.40
0.85
0.95
1.00
For example, if the uniform random number generated is 0.333, the corresponding daily demand is
1 because the value of 0.333 falls in the range of 0.15 0.40.
Normally, you would write a computer program to generate these random numbers. For illustration purposes, however, uniform random numbers from the table in Appendix D are used instead.
For example, to simulate the first day, choose any number in the table, say the value of 0.856269 in
row 16 and column 2. This random number corresponds to a daily demand of 3 copies. Since only
2 copies of the tape are available for rental, the associated revenue is:
Chapter 15
Table 15.3: Simulating 10 Days of Demand for the Problem of First-Run Videos, Inc.
Uniform
random
Day number Demand
1
2
3
4
5
6
7
8
9
10
0.856269
0.201616
0.091010
0.990284
0.926374
0.090610
0.519490
0.988134
0.516041
0.629143
3
1
0
4
3
0
2
4
2
2
Revenue
6
3
0
6
6
0
6
6
6
6
10
Chapter 15
Table 15.4: Profits for the Simulation Results of the Problem of First-Run Videos, Inc.
Number of Purchase
Revenue
Resale Profit
copies
cost ($) ($/month) value ($)
($)
0
1
2
3
4
0.00
25.00
50.00
75.00
100.00
0.00
78.00
135.00
159.00
165.00
0.00
5.00
10.00
15.00
20.00
0.00
58.00
95.00
99.00
85.00
most. Observe that the conclusion to order 3 copies based on the result of this one simulation is
dierent from the analytical results in Table 15.2 in which it is optimal to order only 2 copies. This is
because the simulation methodology provides only an estimate. To obtain more accurate estimates,
you will need to repeat this 30-day simulation many more times, as you will learn in Chapter 16.
15.2
From the examples presented in Sections 15.1.1 and 15.1.2, you can identify the following disadvantages of using a computer simulation:
1. The numerical results obtained are based on the specific set of random numbers used in the
simulation, the values of which correspond to only one of many possible outcomes. Thus, the
final values reported in a simulation are only estimates of the true values you are looking for.
For instance, the computer simulation of the New York Lottery Commission in Example 15.1
resulted in overestimating the expected payo per card. As another example, the simulation
of the problem of First-Run Videos, Inc., in Example 15.2 indicated that 3 copies of the
video tape should be purchased but the mathematical analysis showed that it is best to buy
only 2 copies.
Making wrong decisions based on the results of a simulation may have serious financial
consequences. For example, if the simulation in Example 15.1 underestimates the expected
payo of a lottery card, the New York Lottery Commission may not charge enough for that
card and might loose significant amounts of money.
2. To obtain more accurate estimates and to minimize the likelihood of making a wrong decision, you should (a) use a large number of trials in each simulation and/or (b) repeat the
entire simulation a large number of times. For instance, in Example 15.1, you might have
the computer simulate 10,000 cards instead of 100; in Example 15.2, you might simulate
the profit from one month twenty dierent times rather than just once. In these examples
that can easily be done with a reasonable amount of computational eort. For more complex problems, however, a large number of repetitions can require significant amounts of
computer time.
3. Each simulation requires its own special design to mimic the actual scenario under investigation and its own associated computer program. Although it is possible to learn and use
specialized software packages, development eort in designing and programming real-world
simulations is extremely time consuming.
Chapter 15
11
As a result of these disadvantages, you should attempt to solve your problem using analytical
techniques whenever possible. Doing so requires less eort and results in exact answers rather than
estimates. Therefore, the problems in Example 15.1 and 15.2 should be solved analytically rather
than with a computer simulation. Nonetheless, in spite of the disadvantages, computer simulation
is one of the more commonly used techniques because it oers the following advantages:
1. Simulation allows you to analyze large, complex problems for which analytical results are
not available. In fact, most real-world problems fit in this category. Consider the problem
of First-Run Videos, Inc., in Example 15.2. Analytical results were obtained assuming that
the demand distribution is the same on each day and that each tape is returned after one
day. However, a more realistic scenario is one in which the demand distribution depends on
the day of the week. Friday and Saturday would have higher demands. Also, a rented tape
may be returned after one, two, or even three days. Even if the return distribution were
known, obtaining analytical results in this case would be quite dicult. Simulation provides
a practical alternative.
2. As with any form of simulation, computer simulation allows the problem solver to experiment
with many dierent policies and scenarios without actually changing or experimenting with
the actual existing system. For example, with computer simulation you can study the impact
of adding a new work station to a production line without having to set up the work station
physically.
3. Computer simulation allows you compress time. For example, you can study the long-range
impact of a policy for a bank for an entire year in a computer simulation lasting just a few
minutes. The alternative of actually implementing the policy and observing its results over
a year may not be practical.
4. Some analytical techniques require a sophisticated mathematical background both to use
and to understand. A computer-simulation may require little or no complex mathematics
and so may be intuitively more understandable. As a result, it may be easier to convince
others in the organization that your proposal or policy is sound when it is backed up by a
simulation model rather than by an analytical model. For this reason, computer simulation
may be used even though the problem can be analyzed using mathematical techniques.
In Section 15.1 you learned the basic concepts of how a computer simulation is used to obtain
estimates of certain values on which a decision is based. In Section 15.3, the details of the steps
involved in designing a simulation are presented.
15.3
Designing and implementing a computer simulation depends on the system being modeled and also
on the specific computer language or package you have available. However, certain general steps are
performed in each simulation, as described in this section.
15.3.1
The design of a simulation model depends on classifying the system as one of two types:
1. A discrete-event system, in which the state of the system changes only at certain points in
time. For example, in modeling the operation of a bank, the state of the system is described
by the number of customers in line and which of the tellers are currently busy. The state of
this system changes only at those points in time when either (a) a new customer arrives or
(b) a customer finishes being served and leaves the bank.
12
Chapter 15
2. A continuous system, in which the state of the system changes continuously over time,
that is, at each moment in time. For example, in simulating the flight of the space shuttle,
the state of the system is described by its position, speed, accelaration, and so on. These
characteristics are changing constantly at each moment in time.
Before designing the details of a computer simulation, it is critical to have a clear understanding of
the objectives of the study in the form of specific numerical outputs. For instance, in Example 15.1,
the objective is to determine a price for the new lottery card which creates the need to obtain an
output value of the expected payo of the card. Examples of possible outputs for other simulations
are:
1. To evaluate the performance of a bank: (a) the average time a customer spends waiting in
line, (b) the fraction of time the tellers are busy serving customers, and (c) the average and
maximum length of the waiting line.
2. To evaluate an inventory policy: (a) the average inventory level over a period of time, (b)
the number of times and the amount by which you are unable to meet the demand, and (c)
the total associated cost.
3. To evaluate the anticipated cash flow of a business based on future probabilistic sales: (a)
the expected net-present value of the cash flow and (b) the expected rate of return.
Having identified the outputs, the next step is to identify the inputs. These are the numerical
values that, once determined, allow you to start the simulation and to calculate all the desired
outputs. These inputs fall into three general categories.
Chapter 15
13
1. Initial conditions that is, initial values that express the state of the system at the
beginning of the simulation. For example, in simulating the daily operation of a bank,
the initial conditions correspond to opening the bank in the morning when there are no
customers and all the tellers are available. In simulating the monthly operation of a steel
plant, the initial conditions might include such items as the amount of iron ore in inventory,
the initial work-in-process inventory, the amount of finished steel in inventory, and the
number of furnaces in operation at the beginning of the month.
2. Deterministic data that is, known values that are needed to perform the calculations
that yield the outputs. For example, in simulating the daily operation of a bank, one
deterministic data value is the number of tellers available and the number of hours each
works. For the simulation of steel production, these deterministic values might include the
cost of producing steel, the selling price, the number of shifts and the number of workers on
each shift, and so on. In addition, deterministic data for both of these problems include the
length of the simulation. In the case of the bank a terminating system the length of the
simulation is one eight-hour day. For the steel production a nonterminating system you
must determine an appropriate length of the simulation.
3. Probabilistic data that is, quantities whose values are uncertain but needed to obtain
the outputs of the simulation. In simulating the daily operation of a bank, the arrival times
of the customers and the amount of time needed to serve each of them are two probabilistic
data values. In simulating the steel plant, the demands for the finished goods as well as the
amount of time needed at each stage in the production process might constitute probabilistic
data. Although the specific values of these probabilistic data are uncertain, their general
behavior must be known through a probability distribution or a density function depending,
respectively, on whether the value is discrete or continuous (see Appendix B).
To illustrate the design of a simulation for the problem of First-Run Videos, Inc., recall that the
desired output is the expected 30-day profit associated with purchasing a given number of copies of
a video tape. To obtain this value requires the following inputs:
1. Initial conditions stating that all the purchased tapes are in the store and available for rental
at the beginning of the simulation.
2. The deterministic data consisting of:
(a) The number of copies purchased.
(b) The purchase price of a new tape.
(c) The rental cost per day for each tape.
(d) The sales price after 30 days.
(e) The length of the simulation 30 days.
3. Probabilistic data consisting of the number of tapes demanded on each of the 30 days in the
month.
In this example, the initial conditions that all purchased tapes are available for rent every day
makes the process of initialization straightforward. However, in many simulations defining the initial
condition is not so trivial. Furthermore, the choice of the initial conditions can aect the output
values of the simulation. One commonly used approach is to choose what you consider to be likely
or reasonable starting conditions, and then to run the simulation for a long enough period of time
so that the eect of the initial conditions is not significant.
14
Chapter 15
15.3.3
Once you have identified the outputs and the inputs needed to compute them, the actual simulation
consists of the following two steps:
Step 1. Generating Random Numbers: Obtain the probabilistic inputs for the model by generating
random numbers according to the associated known distributions.
Step 2. Bookkeeping: Design a systematic method for storing and processing all the input values
and for performing the computations needed to obtain the output values.
For First-Run Videos, recall that the desired output is the expected 30-day profit associated with a
given number of purchased tapes, say 2. The inputs for that simulation are:
(i) 2 copies purchased.
(ii) A purchase price of $25 per tape.
(iii) A rental revenue of $3 per day.
(iv) The daily demands whose distribution is:
Number of copies
0
1
2
3
4
Probability
0.15
0.25
0.45
0.10
0.05
Copies purchased 3
if demand > copies purchased
(c) Computing the total rental revenue as the sum of the revenue for each of the 30 days.
Chapter 15
15
The bookkeeping scheme depends on the specific system being modeled. Once the probabilistic
inputs are generated, the scheme is usually straightforward. As you have seen in Examples 15.1 and
15.2, it is necessary to use random numbers to compute the probabilistic inputs for a simulation.
Some insight into how this is done in general is given in Section 15.3.4.
15.3.4
In the examples in Section 15.1, you saw how random numbers between 0 and 1 are used to obtain
values for random variables that have a known discrete probability distribution in which the random
variable of interest can assume one of a finite number of dierent values. In some applications,
however, the random variables are continuous, that is, they can assume any real value according
to a continuous probability distribution. For example, in simulating the operation of a bank, the
amount of time a teller spends with a customer is such a random variable which might follow an
exponential distribution (see Appendix B) defined by the density function:
f (t) = et
where (1/) is the average time of service (that is, is the average number of customers served per
unit of time). In this section you will learn how to generate random numbers having an exponential
distribution with a known value of as well as any other type of probability distribution.
Generating Uniform 0-1 Random Numbers
One of the most commonly used methods to generate random numbers following a known distribution relies on using uniformly-distributed random numbers between 0 and 1. As discussed in
Appendix B and illustrated in Figure 15.4, such numbers have the following density function, f (x),
and cumulative distribution function, F (x):
f (x) =
1,
F (x) = x.
The computer languages used for developing simulations all have a built-in capability for generating a sequence of random numbers between 0 and 1 in which:
1. The approach is based on numerical methods.
2. The specific sequence depends on a user-supplied initial value called the seed. For a particular seed, the sequence is then determined. Each time that same seed is used, the same
sequence of random numbers is generated.
3. The generated numbers satisfy the following properties: (a) they are uniformly distributed
between 0 and 1 and (b) successive numbers are statistically independent of each other. As
a result, even though the seed determines the precise sequence of numbers, collectively these
numbers obey the desired statistical properties of 0 1 random numbers. They are therefore
called pseudo-random numbers.
To use pseudo-random-number generators in a computer simulation, you need supply only an initial
arbitrary integer number as a seed. Then, each time the pseudo-random-number generator is used,
the next 0 1 random number in the sequence is provided.
16
Chapter 15
f (x)
6
2.0
1.0
-
0.0
0.0
1.0
Figure 15.4 (a): Density Function f (x)
F (x)
6
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
1.0 p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
0.5
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
p
0.0
0.0
0.5
1.0
Chapter 15
17
18
Chapter 15
Figure 15.5: Density Function and Cumulative Distribution Function for Random Numbers With
an Exponential Distribution
Chapter 15
19
Figure 15.6: Generating a Random Number Using a Cumulative Distribution Function and a Uniform 0 1 Random Number
1 et = U, or
et = 1 U.
For the specific example involving the bank teller, in which = 12 and a uniform random
number of, say, U = 0.3329 is generated, the amount of time needed to serve one particular
customer is:
t =
=
=
=
(1/) ln (1 U )
(1/12) ln (1 0.3329)
(1/12) (0.4048)
0.3373 of an hour.
20
Chapter 15
As a second example, suppose you need to generate the demand D for milk that follows a normal
distribution with a mean of 750 gallons per day and a standard deviation of 100 gallons. To do so
for a normally-distributed random variable having a mean of and a standard deviation of :
1. Generate a uniform 0 1 random number say, U .
2. Use this value of U to find a value of t for which
F (t) = Prob(D t) = U.
That is, find the value of t for which the area under the normal distribution to the left of
t in Figure 15.7 is U . To do so, use the standard normal table in Appendix E to find the
associated z-value; then compute t, as follows:
t
z = , so
t = + ( z).
For the specific milk example in which U = 0.1515, = 750, and = 100, the z-value from
Appendix E is about -1.03, and so:
t =
+ ( z)
15.4
In this section, you will see an example of how the simulation methodology is used to analyze a
more challenging decision problem. Consider the problem faced by the Regional Transit Authority
of Cleveland.
15.4.1
PROBLEM DESCRIPTION
The Regional Transit Authority (RTA) has bus service from various suburbs to downtown. The
management has received a number of complaints that customers at one of the suburban stops are
having to wait too long during the morning rush hours of 7 to 9 AM. The riders are also complaining
that there are not enough seats in the shelter for all the passengers to wait in the winter months. To
respond to these complaints, the management is considering increasing the frequency on that route
from the current service of every 20 minutes to every 15 minutes. As manager of operations, you
have been asked to investigate the impact of this policy on customer service by measuring:
1. The average amount of time a customer has to wait for a bus.
Chapter 15
21
As discussed in Section 15.3.1, before designing the details of a computer simulation, it is critical to
have a clear understanding of the objectives of the study in the form of specific numerical outputs. For
the problem of the RTA, the appropriate outputs are the three described in the problem description
in Section 15.4.1.
The next step is to identify the inputs for this simulation whose values, once determined, allow
you to calculate these outputs. Recall, from Section 15.3, that the inputs fall into the following three
categories:
1. The initial conditions which, in this case, are the number of customers already at the stop at
the time corresponding to the beginning of the simulation and the time when the next bus is
22
Chapter 15
scheduled to arrive. These values should represent the most likely starting conditions at the
beginning of the rush-hour period being simulated and should be estimated based on your
experience. For the purposes of illustration, assume that you are starting the simulation at
a point in time when a bus has just left. In this case, there is no one waiting at the stop
and the next bus is scheduled to arrive in 15 minutes. If the simulation is performed for a
long enough period of time, the eect of these initial conditions on the output should be
minimal.
2. The deterministic data consisting of the length of time over which to perform this simulation.
In this case, suppose you decide to simulate the bus stop for one hour.
3. The probabilistic data that are generated when needed, consisting of:
(a) The arrivals of the customers whose interarrival times are assumed to follow an exponential distribution with a mean rate of = 0.5 per minute.
(b) The arrival time of each bus. The buses are scheduled to arrive every 15 minutes.
However, they might be late by an amount of time that follows a normal distribution
with a mean of = 4 minutes and a standard deviation of = 1 minute.
With these outputs and inputs, the actual simulation consists of generating appropriate random
numbers and an associated bookkeeping scheme, both of which are described below.
15.4.3
As discussed above, there are two probabilistic inputs, each of which needs to be generated using
random numbers according to their underlying probability distributions.
Generating Arriving Customers
One of the probabilistic inputs for this simulation is the arrival of customers at the stop, whose
interarrival times follow an exponential distribution with a mean of = 0.5 per minute. Recall,
from Section 15.3, that the time, ta , in minutes between successive arrivals is obtained by:
(a) Generating a uniform 0 1 random variable U .
(b) Computing:
ta = (1/0.5) ln (1 U ).
Generating the Arrival of a Bus
The buses are scheduled to arrive every 15 minutes. If the simulation is started at time T = 0, then
the first bus should arrive at time T = 15, the second bus at time T = 30, and so on. However,
these buses are late by an amount of time that follows a normal distribution with a mean of = 4
minutes and a standard deviation of = 1. Recall from Section 15.3 that this random time, tl , by
which a bus is late is generated using the following steps:
(a) Generate a uniform 0 1 random number U .
(b) Find a z-value from the standard normal table in Appendix E so that the area to the left of
z is U .
Chapter 15
23
= +
=
15.4.4
( z)
+ (1 z).
One of the best ways to approach the bookkeeping scheme is to use the technique of working through
a specific example in which you take specific values for the given inputs and perform the needed
computations by hand to determine the desired output. Recall the values for the initial conditions
at time T = 0 for this problem: the stop is empty and the next bus is scheduled to arrive in 15
minutes.
To compute the outputs, you will need to know the status of the system (number of customers
in the system) at every point in time. However, observe that the status of the system changes only
when either:
1. A new customer arrives, or when
2. A bus arrives.
Thus, it is necessary to record the status of the system only at these points in time. You must know
which of these events occurs next and when. To begin with, consider the initial state of the system
at time T = 0.
Bookkeeping at Time T = 0
At time T = 0 there is no one waiting at the stop and a bus has just left. To determine when the
status of this system changes, you need to know:
1. The time at which the next customer arrives.
2. The time at which the next bus arrives.
These values need to be generated randomly according to their distributions.
Determining When the Next Customer Arrives
Use 0 1 random numbers to determine the arrival time of the next customer, as follows:
1. Arbitrarily start by choosing a uniform 0 1 random number say, U = 0.894206 in row 2
and column 4 of the table in Appendix D.
2. Compute the interarrival time, ta , as follows:
ta
= (1/0.5) ln (1 U )
= 2 ln (1 0.894206)
= 4.49 minutes.
24
Chapter 15
Time Event
Number of
Customers
0.00
Arrival time of
Next customer
Next bus
4.49
18.57
In other words, the next customer arrives 4.49 minutes from now, at time T = 0 + 4.49 = 4.49.
Determining When the Next Bus Arrives
The next bus is scheduled to arrive at time T = 15 minutes, but will actually arrive late by a random
amount of time, tl . To determine tl , use the next 0 1 random number in the table, U = 0.332668
in row 2 and column 5. From the standard normal table in Appendix E, the z-value for which the
area to the left of z is U is about -0.43. Using this z-value, compute:
tl
= + (z )
= 4
+ (0.43 1)
= 3.57 minutes.
In other words, the next bus is 3.57 minutes late, that is, it arrives at time T = 15 + 3.57 = 18.57.
These arrivals and the status of the system at T = 0 are summarized in Table 15.5.
Moving the Clock Time T
From Table 15.5, you can see that the status of the system remains the same until the first customer
arrives at time T = 4.49. This is because this customer arrives before the next bus.
Bookkeeping at Time T = 4.49
When this customer arrives at time T = 4.49, you must perform the following steps:
1. Change the Status of the System: The customer joins the others waiting at the stop, so
increase the number of waiting customers by 1.
2. Schedule the Next Arriving Customer: A new customer will arrive. To determine when,
generate an interarrival time, ta , according to an exponential distribution. Using the next
0 1 random number, U = 0.355729 from row 3 and column 1, and compute:
ta
= (1/0.5) ln (1 U )
= 2 ln (1 0.355729)
= 0.88 minutes.
The next customer arrives 0.88 minutes from now, at time T = 4.49 + 0.88 = 5.37.
Chapter 15
25
Time
Event
0.00
4.49 Customer
Number of
Customers
0
1
Arrival time of
Next customer
Next bus
4.49
5.37
18.57
18.57
Time
Event
0.00
4.49 Customer
5.37 Customer
Number of
Customers
0
1
2
Arrival time of
Next customer
Next bus
4.49
5.37
10.91
18.57
18.57
18.57
These changes are summarized in Table 15.6 in the row corresponding to time T = 4.49. At this
time, a new customer arrives, as indicated by the word Customer in the column labeled Event.
Moving the Clock Time T
From the second row of Table 15.6, you can see that the status of the system remains the same
until the next customer arrives at time T = 5.37. When this customer arrives, perform the following
steps:
1. Change the Status of the System: The customer joins the others waiting at the stop, so
increase the number of waiting customers from 1 to 2.
2. Schedule the Next Arriving Customer: A new customer will arrive. To determine when,
generate an interarrival time, ta , according to an exponential distribution. Using the next
0 1 random number, U = 0.937265 from row 3 and column 2, and compute:
ta
= (1/0.5) ln (1 U )
= 2 ln (1 0.937265)
= 5.54 minutes.
The next customer arrives 5.54 minutes from now, at time T = 5.37 + 5.54 = 10.91.
These changes are summarized in Table 15.7 in the row corresponding to time T = 5.37, at which
time a new customer arrives.
Repeating this process reveals that customers continue to arrive until time 16.62, as summarized
in Table 15.8. On the basis of the information in the last row of Table 15.8, you can see that the
next event is the arrival of the first bus at time T = 18.57.
26
Chapter 15
Time
Event
0.00
4.49
5.37
10.91
12.38
13.58
15.06
16.62
Customer
Customer
Customer
Customer
Customer
Customer
Customer
Number of
Customers
Arrival time of
Next customer
Next bus
0
1
2
3
4
5
6
7
4.49
5.37
10.91
12.38
13.58
15.06
16.62
19.86
18.57
18.57
18.57
18.57
18.57
18.57
18.57
18.57
= + (z )
= 4
+ (0.565 1)
= 3.44 minutes.
In other words, the next bus is 3.44 minutes late, that is, it arrives at time T = 30 + 3.44 =
33.44.
This arrival and the status of the system at T = 18.57 are summarized in the last row of Table 15.9.
From these sample events, you can see that the status of the system changes only when one of
two events occurs: (a) a new customer arrives or (b) a bus arrives. Depending on which event occurs
first, the clock is moved to that point in time and the following associated bookkeeping operations
are performed.
Bookkeeping When a New Customer Arrives
1. Change the Status of the System: Increase the number of waiting customers by 1.
2. Schedule the Arrival Time of the Next Customer: Determine when the next customer arrives
by generating a random interarrival time from the exponential distribution.
3. Add this information as the next row in the table.
Chapter 15
27
Time
Event
0.00
4.49
5.37
10.91
12.38
13.58
15.06
16.62
18.57
Customer
Customer
Customer
Customer
Customer
Customer
Customer
Bus
Number of
Customers
Arrival time of
Next customer
Next bus
0
1
2
3
4
5
6
7
0
4.49
5.37
10.91
12.38
13.58
15.06
16.62
19.86
19.86
18.57
18.57
18.57
18.57
18.57
18.57
18.57
18.57
33.44
Recall from Section 15.4.1 that the sought after objectives that is, the outputs of this simulation
are:
1. The expected waiting time for a customer at the stop.
2. The average number of customers waiting.
3. The maximum number of customers waiting.
The last step is to use the information in Table 15.10 to obtain these statistics, as now illustrated.
Computing the Expected Waiting Time
The average waiting time at the stop is computed using the following formula:
Average waiting time =
From the data in Table 15.10, a total of 27 customers have arrived at the stop.
28
Chapter 15
Time
Event
0.00
4.49
5.37
10.91
12.38
13.58
15.06
16.62
18.57
19.86
21.90
23.43
26.42
30.49
32.00
33.44
36.35
39.29
40.92
40.98
41.14
42.45
43.29
45.95
49.68
50.83
51.82
52.16
52.22
56.21
58.06
Customer
Customer
Customer
Customer
Customer
Customer
Customer
Bus
Customer
Customer
Customer
Customer
Customer
Customer
Bus
Customer
Customer
Customer
Customer
Customer
Customer
Customer
Customer
Customer
Bus
Customer
Customer
Customer
Customer
Customer
Number of
Customers
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
Arrival time of
Next customer
Next bus
4.49
5.37
10.91
12.38
13.58
15.06
16.62
19.86
19.86
21.90
23.43
26.42
30.49
32.00
36.35
36.35
39.29
40.92
40.98
41.14
42.45
43.29
45.95
49.68
51.82
51.82
52.16
52.22
56.21
58.06
63.55
18.57
18.57
18.57
18.57
18.57
18.57
18.57
18.57
33.44
33.44
33.44
33.44
33.44
33.44
33.44
50.83
50.83
50.83
50.83
50.83
50.83
50.83
50.83
50.83
50.83
64.23
64.23
64.23
64.23
64.23
64.23
Chapter 15
29
Number in line
6
8
2
0
10
20
30
40
50
Time (minutes)
60
= 7.5938 minutes.
On average, a customer can expect to wait about 7.6 minutes before the next bus arrives.
30
Chapter 15
9.69
6.20
8.76
8.50
7.28
6.25
3.83
4.60
3.74
1.15
0.1615
0.1034
0.1460
0.1417
0.1213
0.1042
0.0639
0.0767
0.0623
0.0191
fraction
fraction
fraction
fraction
of
of
of
of
time
time
time
time
0 are waiting
1 is waiting
2 are waiting
3 are waiting
..
.
+
+
+
+
Chapter 15
31
When the computation of the statistics is based on the relatively short period of 60 minutes, the
initial conditions can have a significant eect on the final values. However, if the simulation is
performed over a longer period of time, say over a two-hour period, you can assume that the eects
of the initial conditions are relatively insignificant. In general, the longer the period you simulate,
the less the impact of the initial conditions.
Another way to become more certain of the values of the estimates of the performance measures is
to repeat the above simulation and computations for many dierent days, and then take the average
of each statistic. In Chapter 16 you will learn more about how many days you need to repeat the
simulation to become reasonably confident of the estimates.
Once the final statistics are obtained, the management of the RTA can determine if this schedule
will provide an accepatble level of service. For example, the management will implement this schedule
if they feel that customers will not mind waiting an average of 7.5 minutes.
The management of the RTA can use the average number of waiting customer and the maximum
number of customers to decide how big a shelter is needed.
15.5
You have seen how and when simulation is used to analyze complex systems. Doing so involves
building an appropriate computer model to calculate desired outputs using relevant inputs. Decisions
are then made based on the results of the simulation. In this section, several issues related to using
simulation and implementing the results are discussed.
15.5.1
DATA COLLECTION
32
Chapter 15
15.5.2
As you learned in Section 15.3, one set of input values to a simulation model is the initial conditions
that describe the state of the system at the time the simulation begins. In many cases, these values
are fixed and easily determined due to the nature of the system. For example, in simulating the
daily operation of a bank, the initial values that describe the conditions at the beginning of the
simulation (that is, the day) are that no customers are yet in the system and, consequently, that
all available tellers are idle. In contrast, in some problems the initial conditions are not so readily
available or, in fact, are not known. For example, in simulating the rush-hour operation of the bus
stop for the problem of the Regional Transit Authority in Section 15.4, the initial conditions consist
of the number of customers at the stop and the scheduled arrival of the next bus. These values vary
from day to day and cannot be known with certainty. In these cases, initial values are generally
chosen in one of the following ways:
1. By assigning values on the basis of your knowledge of how the system works and what you
would most likely expect at the time corresponding to the beginning of the simulation.
2. By assigning any reasonable initial values and running the simulation long enough to minimize the influence of the initial conditions. For example, whether you start with no customers
or three customers at the stop will have little impact on the final statistics if the simulation
is run for a period of two hours.
3. By assigning any reasonable initial values and running the simulation for some initial time
period, say T . Then discard all statistics accumulated during this period except the final
conditions. Use these final conditions as the initial conditions for running another simulation.
This second set of statistics are then compiled and recorded.
Statistical analysis is used to determined the appropriate length of the simulation run in (2) and the
initial time period T in (3). These analyses are beyond the scope of this textbook but they can be
found in any standard book on computer simulation.
Obtaining the output value from a single simulation run is statistically analogous to drawing
a single sample from a population. This is because the sequence of random numbers used in the
simulation run is based on the initial uniform random number chosen and is only one of many
possible outcomes. In Chapter 16 you will learn how to determine the number of simulation runs
needed to achieve a specified level of confidence in estimating the average of the output value.
15.6
SUMMARY
In this chapter you have learned that the management science technique of computer simulation is
a useful tool for studying complex systems that cannot be analyzed mathematically because:
1. It is not possible or practical to develop a solution methodology based on mathematical
analysis.
2. To apply mathematical analysis requires additional assumptions about the model that are
not applicable or realistic.
The design and analysis of a simulation model depends on first classifying the system as either
a discrete-event system, in which the state of the system changes only at certain points in time, or
a continuous system, in which the state of the system changes at every moment in time, continuously. Only discrete-event systems are discussed in this chapter. These discrete systems are further
classified as terminating, in which there are precise and known starting and ending conditions, or
Chapter 15
33
nonterminating, in which the system is on going. In the former case it is necessary to determine
only the number of simulation runs; in the latter case you must also determine the length of each
simulation run.
Designing the details of a computer simulation involves specifying the objectives of the study in
the form of specific numerical outputs. Then, you must identify the needed inputs, which fall into
one of the three categories of:
1. Initial conditions, which describe the beginning state of the system.
2. Deterministic data, consisting of known values needed to perform the calculations in obtaining the outputs.
3. Probabilistic data, consisting of those quantities whose values are needed to obtain the outputs of the simulation, but are uncertain. Although the specific values of these probabilistic
data are unknown, their general behavior must be known through a probability distribution or a density function depending, respectively, on whether the values are discrete or
continuous.
The actual simulation consists of using a computer simulation package or other computer language to write a model to perform the following two steps:
Step 1. Generating Random Numbers: Obtain the probabilistic inputs for the model by generating
random numbers according to the associated distributions.
Step 2. Bookkeeping: Design a systematic method for storing and processing all the input values
and for performing the computations needed to obtain the output values.
The output obtained from one simulation run is only one of many possible values. Therefore,
in general, you cannot have confidence in the output value from a single simulation run. Rather,
you need to repeat the simulation run many times each time using a dierent initial uniform
random number thereby obtaining dierent output values. The actual number of runs to perform
is discussed in Chapter 16.
34
Chapter 15
Appendix 15A
USING 0 1 RANDOM NUMBERS TO OBTAIN
RANDOM NUMBERS FROM A GIVEN DISTRIBUTION
In Section 15.2, you learned how to transform a 0 1 random number into one that follows a
given density function, f (t), and its associated cumulative distribution function, F (t), by performing
the following steps:
1. Generate a uniform random number between 0 and 1 say, U .
2. For the given value of U in Step 1, use the cumulative distribution F (t) to determine the
value of t for which
F (t) = U
3. Use the value of t computed in Step 2 as the desired random number.
These three steps are justified by the following mathematical theorem.
Theorem 15.1 Let f (t) is a given density function with cumulative distribution function F (t). If
R is a uniformly distributed random variable whose value is between 0 and 1, then the value T that
satisfies R = F (T ) is a random variable whose cumulative distribution is F (t).
Proof: From the definition of a cumulative probability distribution as reviewed in Appendix B, to
prove that T has cumulative distribution F (t) requires showing that
P( T t ) = F (t)
To show this is true for the random variable T for which R = F (T ), from Figure 15.9, observe that
T t whenever R U (where U = F (t)). Thus,
P( T t ) = P( R U )
= U
(because R is uniform 0 1)
= F (t)
(because U = F (t))
As a result of Theorem 15.1, if you know a value U for the uniform 0 1 random variable R, then
you can generate a corresponding value for the random variable T with a cumulative distribution
F(t) by determining that value of t for which:
F (t) = U
Chapter 15
35
Figure 15.9: Generating a Random Number Using a Cumulative Distribution Function and a Uniform 0 1 Random Number