You are on page 1of 71

Chapter 21

Simulation
to accompany
Operations Research: Applications and Algorithms
4th edition by Wayne L. Winston

Copyright (c) 2004 Brooks/Cole, a division of Thomson Learning, Inc.

Description
Simulation is a very powerful and widely used management
science technique for the analysis and study of complex systems.
Simulation may be defined as a technique that imitates the
operation of a real-world system as it evolves over time. This is
normally done by developing a simulation model. A simulation
model usually takes the form of a set of assumptions about the
operation of the system, expressed as mathematical or logical
relations between the objects of interest in the system.
Simulation has its advantages and disadvantages. We will focus
our attention on simulation models and the simulation technique.
2

21.1 Basic Terminology

In most simulation studies, we are concerned


with the simulation of some system.

Thus, in order to model a system, we must


understand the concept of a system.

Definition: A system is a collection of entities


that act and interact toward the
accomplishment of some logical end.

Systems generally tend to be dynamic their


status changes over time. To describe this
status, we use the concept of the state of a
system.
3

Definition: The state of a system is the


collection of variables necessary to describe the
status of the system at any given time.

Customers arrive and depart, the status of the


system changes. To describe these changes in
status, we require a set of variables called the
state variables.

In a system, an object of interest is called an


entity, and any properties of an entity are
called attributes.

Systems may be classified as discrete or


continuous.
4

Definition: A discrete system is one in which


the state variables change continuously over
time. A bank is an example of a discrete system.

Definition: A continuous system is one in


which the state variables change continuously
over time.

There are two types of simulation models, static


and dynamic.

Definition: A static simulation model is a


representation of a system at a particular point
in time.
5

We usually refer to a static simulation as a


Monte Carlo simulation.

Definition: A dynamic simulation is a


representation of a system as it evolves over
time.

Within these two classifications, a simulation


may be deterministic or stochastic.

A deterministic simulation model is one


that contains no random variables; a
stochastic simulation model contains one or
more random variables.
6

21.2 An Example of a Discrete-Event


Simulation

To simulate a queuing system, we first have to


describe it.

We assume arrivals are drawn from an infinite


calling population.

There is unlimited waiting room capacity, and


customers will be serve in the order of their
arrival (FCFS).

Arrivals occur one at a time in a random fashion.

All arrivals are eventually served with the


distribution of service teams as shown in the
book.
7

Service times are also assumed to be random.


After service, all customers return to the calling
population.

For this example, we use the following


variables to define the state of the system: (1)
the number of customers in the system; (2)
the status of the server that is, whether the
server is busy or idle; and (3)the time of the
next arrival.

An event is defined as a situation that causes


the state of the system to change
instantaneously.
8

All the information about them is maintained in


a list called the event list.

Time in a simulation is maintained using a


variable called the clock time.

We begin this simulation with an empty system


and arbitrarily assume that our first event, an
arrival, takes place at clock time 0.

Next we schedule the departure time of the


first customer.
Departure time = clock time now + generated service
time
9

Also, we now schedule the next arrival into the


system by randomly generating an interarrival
time from the interarrival time distribution and
setting the arrival time as
Arrival time = clock time now + generated interarrival time

Both these events are their scheduled times are


maintained on the event list.

This approach of simulation is called the nextevent time-advance mechanism, because of


the way the clock time is updated. We advance
the simulation clock to the time of the most
imminent event.
10

As we move from event to event, we carry out the


appropriate actions for each event, including any
scheduling of future events.

The jump to the next event in the next-event


mechanism may be a large one or a small one;
that is, the jumps in this method are variable in
size.

We contrast this approach with the fixedincrement time-advance method.

With this method, we advance the simulation clock


in increments of t time units, where t is some
appropriate time unit, usually 1 time unit.
11

For most models, however, the next event


mechanism tends to be more efficient
computationally.

Consequently, we use only the next-event


approach for the development of the models
for the rest of the chapter.

To demonstrate the simulation model, we need


to define several variables:

TM = clock time of the simulation

AT = scheduled time of the next arrival


12

DT = scheduled time of the next departure

SS = status of the server (1=busy, 0=idle)

WL = length of the waiting line

MX = length (in time units) of a simulation run

We now begin the simulation by initializing all


the variables. Details of the example are found
in the book.

This simple example illustrates some of the


basic concepts in simulation and the way in
which simulation can be used to analyze a
particular problem.
13

21.3 Random Numbers and Monte


Carol Simulation

The procedure of generating these times from


the given probability distributions is known as
sampling from probability distributions, or
random variate generation, or Monte Carlo
sampling.

We will discuss several different methods of


sampling from discrete distributions.

The principle of sampling from discrete


distributions is based on the frequency
interpretation of probability.

14

In addition to obtaining the right frequencies, the


sampling procedure should be independent; that is,
each generated service time should be independent
of the service times that precede it and follow it.

This procedure of segmentation and using a


roulette wheel is equivalent to generating integer
random numbers between 00 and 99.

This follows from the fact that each random


number in a sequence has an equal probability of
showing up, and each random number is
independent of the numbers that precede and
follow it.
15

A random number, Ri, is defined as an


independent random sample drawn from a
continuous uniform distribution whose
probability density function (pdf) is given by

1
f ( x)
0

0 x 1
otherwise

16

Random Number Generators

Since our interest in random numbers is for use


within simulations, we need to be able to generate
them on a computer.

This is done by using mathematical functions


called random number generators.

Most random number generators use some form


of a congruential relationships. Examples of such
generators include linear congruential generator,
the multiplicative generator, and the mixed
generator.

The lineal congruential generator is by far the


most widely used.
17

Each random number generated using this


methods will be a decimal number between 0
and 1.

Random numbers generated using congruential


methods are called pseudorandom numbers.

Random number generators must have these


important characteristics:
1.

The routine must be fast

2.

The routine should not require a lot of core storage

3.

The random numbers should be replicable; and

4.

The routine should have a sufficiently long cycle


18

Most programming languages have built-in


library functions that provide random (or
pseudorandom) numbers directly.

19

Computer Generation of Random


Numbers

We now take the method of Monte Carlo


sampling a stage further and develop a
procedure using random numbers generated on
a computer.

The idea is to transform the U(0,1) random


numbers into integer random numbers
between 00 and 99 and then to use these
integer random numbers to achieve the
segmentation by numbers.

We now formalize this procedure and use it to


generate random variates for a discrete
random variable.
20

The procedure consists of two steps:


1.

2.

We develop the cumulative probability distribution


(cdf) for the given random variable, and
We use the cdf to allocate the integer random
numbers directly to the various values of the random
variables.

21

21.4 An Example of Monte Carlo


Simulation

The book uses a Monte Carlo simulation to


simulate a news vendor problem.

The procedure in this simulation is different


from the queuing simulation, in that the
present simulation does not evolve over time in
the same way.

Here, every day is an independent simulation.


Such simulations are commonly referred to as
Monte Carlo simulations.

22

21.5 Simulations with Continuous


Random Variables

In many simulations, it is more realistic and


practical to use continuous random variables.

We present and discuss several procedures for


generating random variates from continuous
distributions.

The basic principle is similar to the discrete


case.

We first generate U(0,1) random number and


then transform it into a random variate from
the specified distribution.
23

The selection of a particular algorithm will


depend on the distribution from which we want
to generate, taking into account such factors as
the exactness of the random variables, the
computations and storage efficiencies, and the
complexity of the algorithm.

The two most common used algorithms are the


inverse transformation method (ITM) and the
acceptance-rejection method (ARM).

24

Inverse Transformation Method

The inverse transformation method is generally


used for distribution whose cumulative
distribution function can be obtained in closed
form.

Examples include the exponential, the uniform,


the triangular, and the Weibull distributions.

For distributions whose cdf does not exist in


closed form, it may be possible to use some
numerical method, such as a power-series
expansion, within the algorithm to evaluate the
cdf.
25

The ITM is relatively easy to describe and


execute.

It consists of the following steps:

Step1: Given the probability density formula f(x) for


a random variable X, obtain the cumulative
distribution function F(x)x as

F ( x) f (t )dt

Step 2: Generate a random number r.

Step 3: Set F(x) = r and solve for x.

26

We consider the distribution given by the


function
x
2
f ( x)
0

0x2
otherwise

A function of this type is called a ramp


function.

To obtain random variates from the distribution


using the inverse transformation method, we
first computer the cdf as
t
F ( x) dt
2
x

x2

4
27

In Step 2, we generate a random number r.

Finally, in Step 3, we set F(x) =r and solve for


x.
x2
r
4
x 2 r

Since the service time are defined only for


positive values of x, a service
of
x 2time
r
as the solution for x. This equation is called a
random variate generator or a process
generator.
28

Thus, to obtain a service time, we first


generate a random number and then transform
it using the preceding equation.

As this example shows, the major advantage of


the inverse transformation method is its
simplicity and ease of application.

29

Acceptance Rejection Method

There are several important distributions,


including the Erlang (used in queuing models)
and the beta (used in PERT), whose cumulative
distribution functions do not exist in closed
form.

For these distributions, we must resort to other


methods of generating random variates, one of
which is the acceptance rejection method
(ARM).

This method is generally used for distributions


whose domains are defined over finite intervals.
30

Given a distribution whose pdf, f(x), is defined


over the interval a x b, the algorithm
consists of the following steps:

Step 1: Select a constant M such that M is the


largest value of f(x) over the interval [a, b].

Step 2: Generate two random numbers, r1 and r2.

Step 3: Computer x* = a + (b a)r1. (This ensures


that each member of [a, b] has an equal chance to
be chosen as x*.)

Step 4: Evaluate the function f(x) at the point x*.


Let this be f(x*).

31

Step 5: If

r2

f ( x*)
M

deliver x* as a random variate from the distribution


whose pdf is f(x). Otherwise, reject x* and go back
to Step 2.

Note that the algorithm continues looping back


to Step 2 until a random variate is accepted.

This may take several iterations. For this


reason, the algorithm can be relatively
inefficient.

The efficiency, however, is highly dependent on


the shape of the distribution.
32

There are several ways by which the method


can be made more efficient.

One of these is to use a function in Step 1


instead of a constant.

We now give an intuitive justification of the


validity of the ARM.

In particular, we want to show that the ARM


does generate observations from the given
random variable X.

33

Direct and Convolution Methods for


the Normal Distribution

Both the inverse transformation method and


the acceptance reject method are
inappropriate for the normal distribution,
because (1) the cdf does not equal in closed
form and (2) the distribution is not defined
over a finite interval.

Other methods such as an algorithm based


on convolution techniques, and then a direct
transformation algorithm that produces two
standard normal variates with mean 0 and
variance 1.
34

The Convolution Algorithm

In the convolution algorithm, we make direct use of


the Central Limit Theorem.

The Central Limit Theorem states that the sum Y of


n independent and identically distributed random
variables ( say Y1, Y2,Yn), each with mean and
finite variance 2) is approximately normally
distributed with mean n and variance n2.

If we want to generate a normal variate X with


mean and variance 2, we first generate Z using
this process generator then transform it using the
relation X = + Z. Unique to normal distribution.

35

The Direct Method

The direct methods for the normal distribution


was developed by Box and Muller (1958).

Its not as efficient as some of the newer


techniques, it is easy to apply and execute.

The algorithm generates two U(0,1) random


numbers, r1 and r2, and then transforms them
into two normal variates, each with mean 0
and variance 1, using the direct transformation.

36

1
2

Z1 (2 ln r1 ) sin 2r2
1
2

Z2 (2 ln r1 ) cos 2r2

It is easy to transform these standardized


normal variates intro normal variates X1 and
X2 from the distribution with mean and
variance 2, using the equations

X1 Z1
X2 Z2
37

21.6 An Example of a Stochastic


Simulation

Cabot Inc. is a large mail order firm in Chicago.

Orders arrive into the warehouse via


telephones. At present, Cabot maintains 10
operators on-line 24 hours a day.

The operators take the orders and feed them


directly into a central computer, using
terminals.

Each operator has one terminal. At present, the


company has a total of 11 terminals.

That is, if all terminals are working, there will


be 1 spare terminal.
38

Cabot managers believe that the terminal system


needs evaluation, because the downtime of
operators due to broken terminals has been
excessive.

They feel that the problem can be solved by the


purchase of some additional terminals for the
spares pool.

It has been determined that a new terminal will


cost a total of $75 per week.

It has also been determined that the cost of


terminal downtime, in terms of delays, lost orders,
and so on is $1000 per week.
39

Given this information, the Cabot managers would like to


determine how many additional terminals they should
purchase.

This model is a version of the machine repair problem.

It is easy to find an analytical solution to the problem using


the birth-death processes.

However, in analyzing the historical data for the terminals,


it has been determined that although the breakdown times
can be represented by the exponential distribution, the
repair times can be adequately represented only by the
exponential distribution.

40

This implies that analytical methods cannot be used and


that we must use simulation.

To simulate this system, we first require the parameters


of both the distributions.

The data show that the breakdown rate is exponential


and equal to 1 per week per terminal.

In other words, the time breakdowns for a terminal is


exponential with a mean equal to 1 week.

Analysis for the repair times shows that this distribution


can be represented by the triangular distribution which
has a mean of 0.075 week.

41

10 400 x 0.025 x 0.075


f ( x)
50 400 x 0.075 x 0.125

The repair stuff on average can repair 13.33


terminals per week.

To find the optimal number of terminals, we


must balance the cost of the additional
terminals against the increased revenues
generated as a result of the increase in the
number of terminals.

In this simulation we increase the number of


terminals in the system, n, from the present
total of 11 in increments of 1.

42

For this fixed value of n, we then run our


simulation model to estimate the net revenue.

Net revenue here is defined as the difference


between the increase in revenues due to the
additional terminals and the cost of these
additional terminals.

We keep on adding terminals until the net


revenue position reaches a peak.

To calculate the net revenue, we first computer


the average number of on-line terminals, ELn, for
a fixed number of terminals in the system, n.
43

Once we have a value of ELn, we can computer


the expected weekly downtime costs, given by
1000(10-ELn).

Then the increase in revenue as a result of


increasing the number of terminals from 11 to
n is 1000(ELn EL11). Mathematically, we
compute ELn
m

ELn

N (t )dt
T

A
i 1

44

where
T = length of simulation
N(t) = number of terminals on-line at time t (0tT)
Ai = area of rectangle under N(t) between ei-1 and ei
(where ei is the time of the ith event)
m = number of events that occur in the interval [0,T]

Between time 0 and time e1, the time of the first


event, the total on-line time for all the terminals
is given by 10ei, since each terminal is on-line
for a period of e1 time units.
45

If we now run this simulation over T time units


and sum up the areas A1, A2, A3,, we can get
an estimate for EL10 by dividing this sum by T.
This statistic is called a time-average statistic.

We would like to set up the process in such way


that it will be possible to collect the statistics to
computer the areas A1, A2, A3,.

That is, as we move from event to event, we


would like to keep track of at least the number
of terminals on-line between the events and the
time between events.
46

We first define the state of the system as the


number of terminals in the repair facility.

The only time the state of the system will


change is when there is either a breakdown or
a completion of a repair.

Therefore, there are two events in this


simulation: breakdown and completion of
repairs.

To set up the simulation, our first task is to


determine the process generators for both the
breakdown and the repair times.
47

We use the ITM to develop the process


generators.

For the exponential distribution the process


generator is simply x = -log r

In case of the repair times, applying the ITM


gives us

x 0.025 0.005r (0 r 0.5)

and

x 0.125 0.005(1 r ) (0.5 r 1.0)


as the process generators.
48

For each n, we start the simulation in the state


where there are no terminals in the repair
facility.

In this state, all 10 operators are on-line and


any remaining terminals are in the spares pool.

Our first action is the simulation is to schedule


the first series of events, the breakdown times
for the terminals presently on-line.

Having scheduled these events, we next


determine the first event, the first breakdown,
by searching through the current event list.
49

We then move the simulation clock to the time


of this event and process this breakdown.

To process a breakdown, we take two separate


series of actions
1.

Determine whether a spare is available.

2.

Determine whether the repair staff is idle.

These actions are summarized in the system


flow diagram showed in the book in Figure 17.

Otherwise, we process a completion of a repair.

50

To process the completion of a repair, we also


undertake two series of actions.
1.

2.

At the completion of a repair, we have an additional


working terminal, so we determine whether the terminal
goes directly to an operator or to the spares pool.
We check the repair queue to see whether any terminals
are waiting to be repaired.

We proceed with the simulation by moving from


event to event until the termination time T.

At this time, we calculate all the relevant


measures of performance from the statistical
counters.
51

Our key measure is the net revenue for the


current value of n.

If this revenue is greater than the revenue for


a system with n-1 terminals, we increase the
value of n by 1 and repeat the simulation with
n +1 terminals in the system.

Otherwise, the net revenue has reached a


peak.

The simulation outlined in this example can be


used to analyze other policy options that
management may have.
52

The simulation model provides a very flexible


mechanism for evaluating alternative policies.

53

21.7 Statistical Analysis of


Simulations

As previously mentioned, output data from


simulation always exhibit random variability,
since random variables are input to the
simulation model.

We must utilize statistical methods to analyze


output from simulations.

The overall measure of variability is generally


stated in the form of a confidence interval at a
given level of confidence.

Thus, the purpose of the statistical analysis is


to estimate this confidence interval.
54

Determination of the confidence intervals in


simulation is complicated by the fact that
output data are rarely, if ever, independent.

This means that the classical methods of


statistics, which assumer independence are not
directly applicable to the analysis of simulation
output data.

We must modify the statistical methods to


make proper inferences from simulation data.

55

In addition to the problem of autocorrelation, we


must have a second problem, in that the
specification of the initial conditions of the system
at time 0 may influence the output data.

This initial period of time before a simulation


reached steady state is called the transient
period or warmup period.

There are two ways of overcoming the problems


associated with the transient period.

The first approach is to use a set of initial


conditions that are representative of the system in
a steady state.
56

The alternative approach is to let the


simulation run for a while and discard the initial
part of the simulation.

Since each simulation model is different, it is


up to the analyst to determine when the
transient period ends.

This is a difficult process, there are some


general guidelines one can use.

57

Simulation Types

For the purpose of analyzing output data, we


generally categorize simulations into one of two
types: terminating simulations and steadystate simulations.

A terminating simulation is one that runs for


a duration of time TE, where E is a specified
event (or events) that stops the simulation.

A steady-state simulation is one that runs


over a long period of time; that is, the length
of the simulation goes to infinity.

58

Often, the type of model determines which


type of output analysis is appropriate for a
particular simulation.

However, the system or model may not always


be the best indicator of which simulation would
be the most appropriate.

It is quite possible to use the terminating


simulation approach for systems more suited to
steady-state simulations, and vice versa.

The analysis for steady-state simulations is


much more involved.
59

To illustrate the terminating simulation approach,


we use an example from the Cabot case.

We assume there are 11 terminals in the system


and we perform only 10 independent terminating
runs of the simulation model.

The terminating event, E, is a fixed time.

That is, all 10 simulations are run for the same


length of time.

The overall average for these 10 runs for the


expected number of terminals on-line turns out
to be 9.331.
60

If we now calculate the sample variance, we


find S2 = 0.018.

Since t(.025,9)=2.26, we obtain


9.331 2.26

0.0180
9.331 0.096
10

as the 95% confidence interval for this sample.

We could have also computed t(.025,9)in


EXCEL with the formula =TINV(0.5,9).

This yields 2.26, which is consistent with the T


Table.
61

As we saw in this example, the terminating


simulation approach offers a relatively easy
method for analyzing simulation data may be
more efficient for a give problem.

62

21.8 Simulation Languages

One of the most important aspects of a


simulation study is the computer programming.

Several special-purpose computer simulation


languages have been developed to simplify
programming.

The best known and most readily available


simulation languages, including GPSS, GASP IV
and SLAM.

Most simulation languages use one of two


different modeling approaches or orientations;
event scheduling or process interaction.
63

GPSS uses the process-interaction approach.

SLAM allows the modeler to use either


approach or even a mixture of the two,
whichever is the most appropriate for the
model being analyzed.

Of the general-purpose languages, FORTRAN is


the most commonly used in simulation.

In fact, several simulation languages, including


GASP IV and SLAM, use a FORTRAN base.

64

To use GASP IV we must provide a main


program, an initialization routine, and the event
routines.

For the rest of the program, we use the GASP


routines.

Because of these prewritten routines, GASP IV


provides a great deal of programming flexibility.

GPSS, in contrast to GASP, is a highly


structured special-purpose language.

GPSS does not require writing a program in the


usual sense.
65

Building a GPSS model then consist of combining


these sets of blocks into a flow diagram so that
it represents the path an entity takes as it
passes through the system.

SLAM was developed by Pritsket and Pegden


(1979). It allows us to develop simulation model
as network models, discrete-event models,
continuous models, or any combination of these.

In Chapter 10, we will show you how to use the


user-friendly powerful process model package
which is included on the books CD-ROM.

66

The decision of which language to use is one of


the most important that a modeler or an
analyst must make in performing a simulation
study.

The simulation language offer several


advantages.

The most important of these is that the specialpurpose languages provide a natural framework
for simulation modeling and most of the
features needed in programming a simulation
model.
67

21.9 The Simulation Process

We now discuss the process for a complete


simulation study and present a systematic
approach of carrying out a simulation.

A simulation study normally consists of several


distinct stages. (See Figure 21 in the book)

However, not all simulation studies consist of all


these stages or follow the order stated here.

On the other hand, there may even be


considerable overlap between some of these
stages.
68

The initial stage of any scientific study, including


a simulation project, requires an explicit
statement of the objectives of the study.

The next stage is the development of the model


and the collection of data.

We next put it into a form in which it can be


analyzed on the computer. This usually involves
developing a computer program for the model.

Once the program has been developed and


debugged, we determine whether the program
is working properly.
69

In other words, is the program doing what it is


supposed to do? This process is call the
verification step and is usually difficult, since
for most simulations, we will not have any
results with which to compare the computer
output.

We now move to the validation stage.

In this step we validate the model to determine


whether it realistically represents the system
being analyzed and whether the results from
the model will be reliable.
70

If we are satisfied at this stage with the


performance of the model, we can use the model to
conduct the experiments to answer the questions at
hand.

The data generated by the simulation experiments


must be collected, processed, and analyzed.

The results are analyzed not only as the solution to


the model but also in terms of statistical reliability
and validity.

Finally, after the results are processed and analyzed,


a decision must be mage whether to perform any
additional experiments.
71

You might also like