Top Banner
Lecture 19 Nov10, 2010 Discrete event simulation (Ross) • discrete and continuous distributions • computationally generating random variable following various distributions. repair problem
35

Lecture 19 Nov10, 2010 Discrete event simulation (Ross)

Jan 04, 2016

Download

Documents

steel-salazar

Lecture 19 Nov10, 2010 Discrete event simulation (Ross) discrete and continuous distributions computationally generating random variable following various distributions. repair problem. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Lecture 19 Nov10, 2010

Discrete event simulation (Ross)

• discrete and continuous distributions

• computationally generating random variable following various distributions.

• repair problem

Page 2: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Exercise 2: (coupon collector’s problem) When you buy a can of soda, it contains a coupon with a label in 1:n. The labels on the can are random in the sense that, at any point during simulation, the probability that the next can you buy will contain label j is 1/n. The goal is the determine the average number of cans you need to buy before you have collected all the n coupons.

Idea: create an array A of size n, all set to 0. Create another array to keep track of the number of cans to buy before all n coupons are collected. The size of this array B is m = the number of trials. Repeat generating a random number j in 1:n, and increment A(j) until all A(j) are > 0. At this point, set B(k) to sum(A) and repeat fro k = 1, 2, …, m.

Page 3: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Probability distributions

• In a Discrete Event Simulation, you need to decide what probability distribution functions best model the events.

in most situations, uniform distribution does not work.

• Pseudorandom number generators generate numbers in a uniform distribution

• One basic trick is to transform that uniform distribution into other distributions.

• Some standard probability distributions are convenient to represent mathematically.

• They may or may not represent reality, but can be useful simplification.

Page 4: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Mean and Variance of a Discrete Random Variable

Page 5: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Example:

Page 6: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Mean and Variance of a Discrete Random Variable

Expected Value of a Function of a Discrete Random Variable

Page 7: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Discrete Uniform Distribution

Definition

Page 8: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Discrete Uniform Distribution

Example:

Page 9: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Discrete Uniform Distribution

Probability mass function for a discrete uniform random variable.

Page 10: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Discrete Uniform Distribution

Mean and Variance

Page 11: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Binomial Distribution

Random experiments and random variables

Page 12: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Binomial Distribution

Definition

Page 13: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Binomial Distribution

Binomial distributions for selected values of n and p.

Page 14: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Binomial Distribution

Example:

Page 15: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Binomial Distribution

Example

Page 16: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Binomial Distribution

Mean and Variance

Page 17: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Geometric and Negative Binomial Distributions

Example

Page 18: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Geometric Distribution

Definition

Page 19: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Geometric Distribution

Definition

Page 20: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Poisson distribution

X follows a Poisson distribution if:

!}{

ieiXP

i

Page 21: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Normal or Gaussian distribution

Ubiquitous in statistics

Many phenomena follow this distribution

When an experiment is repeated, the sum of the outcomes tend to be normally distributed.

We can test this experimentally using a Matlab simulation.

Page 22: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Normal Distribution

Normal probability density functions for selected values of the parameters and 2.

Page 23: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Normal Distribution

Some useful results concerning the normal distribution

Page 24: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Normal Distribution

Definition : Standard Normal

Page 25: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Exponential Distribution

Page 26: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Simulating a Probability distribution

Sampling values from an observational distribution with a given set of probabilities (“discrete inverse transform method”).

Suppose the distribution we want to simulate is X where

p(X = x1) = p0, p(X = x2) = p1, …, p(X = xn) = pn-1

Generate a random number UIf U < p0 return X1

If U < p0 + p1 return X2

If U < p0 + p1 + p2 return X3

etc.

This can be speeded up by sorting p so that the larger intervals are processed first, reducing the number of steps.

Page 27: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Poisson distribution• Example of algorithm to sample from a

distribution.• X follows a Poisson distribution if:

An algorithm for sampling from a Poisson distribution:1. Generate a random number U2. If i=0, p=e-l, F=p3. If U < F, return I4. P = l * p / (i + 1), F = F + p, i = i + 15. Go to 3

There are similar tricks to sampling from other probability distributions. Some of the distributions (e.g.

Poisson, Normal etc.) can be generated using Matlab’s built-in functions.

!}{

ieiXP

i

Page 28: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)
Page 29: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Input:

N = the number of machines needed to run the system

S = the number of spare machines

P1 = the distribution of failure time of a machine

P2 = the probability distribution of the time to service a faulty machine

Output:

The time at which the system crashes.

To get the average time between successive crashes, we should repeat the simulation many times and sum the times, divide by the number of trials.

Page 30: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Algorithm for simulation

Variables used: time – t, system variable – r: the number of machines down at time t.

An event occurs when a machine fails or a machine has been repaired.

Event list:

*

321 ,... ttttt n

tj is the time at which the j-th machine currently in use will fail.

t* is the time at which the present machine being repaired will be ready for use, t* = if no such machine.

Page 31: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

function T = simulate_repair(n, s, l1, l2)% simulation of a repair problem% F = prob distribution defining failure of machine, i.e., % F(t) = prob(time taken for machine to break down = t)% G = prob distribution defining the time taken to repair% ie., G(t) = prob(time taken to repair = t)% n = number of machines, s = additional number of machines% goal is to compute time T at which the sytem fails % system fails when more than s machines are in repair% failure rate is a uniform distribution with values 1, 2, ..., l1% repair time follows a uniform distribution in [1, l2] t = 0; r = 0; tstar = Inf; mqueue = []; for j=1:n mqueue(end+1) = uniform(l1); end; mqueue(end+1)=tstar; mqueue = sort(mqueue);

Simulation function – based on algorithm from Ross’s book (Chapter 6)

Page 32: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

while 1 t1 = mqueue(1); if t1 < tstar t = mqueue(1); r = r + 1; if r == s+1 T = t; return; else x = uniform(l1); mqueue(end+1)=t+x; mqueue = mqueue(2:end); mqueue = sort(mqueue); end; if r == 1 y = uniform(l2); tstar = t+y; end;

else t = tstar; r = r - 1; if r == 0 tstar = Inf; else y = uniform(l2); tstar = t + y; end; end; end;

Page 33: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

It is easy to modify the code so that the distributions (for failure time and repair time) are not uniform, but say Poisson, exponential or normal etc.

Exercise: Try replacing uniform by Poisson or exponential and compute the expected time for crash.

Does it increase the expected time before the system crashes (given the same mean)?

Page 34: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Service queue simulation

Problem: Each customer joins a queue serviced by a single server. The arrival time of the customer is a random number given by a known distribution. Time to service obeys a known (possibly different) probability distribution. Assume that there are a total of N customers. (N is known.) Goal is to calculate the average time a customer has to wait in the service line? We may also want to calculate the average waiting time of the k-th customer.

Variations: 1) assume that after some time T, no additional customer allowed.

2) There are two service providers.

Page 35: Lecture 19                                   Nov10, 2010 Discrete event simulation (Ross)

Simulation of a car wash system