Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  ·...

37
1 Chapter 21 Simulation Operations Research: Applications and Algorithms 4th edition by Wayne L. Winston Copyright (c) 2004 Brooks/Cole, a division of Thomson Learning, Inc.

Transcript of Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  ·...

Page 1: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

1

Chapter 21

Simulation

Operations Research: Applications and Algorithms

4th edition by Wayne L. Winston

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

Page 2: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

2

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.

Page 3: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

3

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.

Page 4: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

4

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.

Page 5: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

5

Definition: A discrete system is one in which the state variables change only at discrete or countable points in 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.

Page 6: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

6

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.

Page 7: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

7

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 served 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 textbook.

Page 8: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

8

An Example of a Discrete-Event Simulation

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.

Page 9: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

9

An Example of a Discrete-Event Simulation

All the information about events 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

Page 10: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

10

An Example of a Discrete-Event Simulation

Also, we now schedule the next arrival into the system by randomly generating an interarrivaltime from the interarrival time distribution and setting the arrival time as:Arrival time = clock time now + generated interarrival

time

Both these events and their scheduled times are maintained on the event list.

This approach of simulation is called the next-event 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.

Page 11: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

11

An Example of a Discrete-Event Simulation

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 fixed-increment time-advance method.

With this method, we advance the simulation clock in increments of ∆t time units, where ∆tis some appropriate time unit, usually 1 time unit.

Page 12: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

12

An Example of a Discrete-Event Simulation

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

Page 13: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

13

An Example of a Discrete-Event Simulation

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. For details of the example look up in the textbook.

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.

Page 14: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

14

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.

Page 15: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

15

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.

Page 16: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

16

A random number, R, is defined as an independent random sample drawn from a continuous uniform distribution whose probability density function (pdf) is given by

otherwise0

101)( xxf

Page 17: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

17

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.

Page 18: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

18

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

Page 19: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

19

Most programming languages have built-in library functions that provide random (or pseudorandom) numbers directly.

Page 20: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

20

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.

Page 21: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

21

The procedure consists of two steps:1. We develop the cumulative probability distribution

(cdf) for the given random variable, and

2. We use the cdf to allocate the integer random numbers directly to the various values of the random variables.

Page 22: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

22

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.

Page 23: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

23

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.

Page 24: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

24

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).

Page 25: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

25

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.

Page 26: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

26

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) as

Step 2: Generate a random number r.

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

xdttfxF )()(

Page 27: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

27

We consider the distribution given by the function:

A function of this type is called a ramp function.

To obtain random variates from the distribution using the inverse transformation method, we first compute the cdf as:

02)(

x

xf 0 ≤ x ≤ 2otherwise

4

2)(

2

0

x

dttxFx

Page 28: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

28

In Step 2, we generate a random number r.

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

Since the service time are defined only for positive values of x, is the only feasible solution for x. This equation is called a random variate generator or a process generator.

rx

rx

242

rx 2

Page 29: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

29

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.

Page 30: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

30

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.

Page 31: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

31

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: Compute 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*).

Page 32: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

32

Step 5: If

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.

Mxfr *)(2

Page 33: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

33

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.

Page 34: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

34

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 exist 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.

Page 35: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

35

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 nσ2.

If we want to generate a normal variate X with mean µ and variance σ2, we first generate Zusing this process generator, then transform it using the relation X = µ + σZ. Unique to normal distribution.

Page 36: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

36

The Direct Method

The direct methods for the normal distribution was developed by Box and Muller (1958).

It’s not as efficient as some of the newer techniques, while 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:

Page 37: Chapter 21 Simulation - Department of Mathematics and …raguimov/math4170_y14/Lecture_… ·  · 2014-12-06Chapter 21 Simulation ... Copyright (c) 2004 Brooks/Cole, a division of

37

It is easy to transform these standardized normal variates into normal variates X1 and X2from the distribution with mean µ and variance σ2, using the equations:

221

12

221

11

2cos)ln2(

2sin)ln2(

rr

rr

Z

Z

22

11

ZXZX