Modeling & Simulation- Lecture -7- 26/11/2014 Sampling from Discrete Probability Distributions A) Sampling from Poisson Distribution The Poisson distribution is used to model a random number of events that will occur in an interval of time. The Poisson distribution has only one parameter, λ. This distribution is unique in that the mean and variance are both equal to λ. Figure (1) shows the Poisson distribution. The probability density function is: p(n) = e−λ (λn ⁄n!), n = 0,1,2, … One method for generating Poisson variants involves the generation of exponentially distributed time intervals t1 , t 2 , t 3 ,... with an expected value equal to 1/λ. These intervals are accumulated until they exceed 1, the unit time period. That is, ∑ni=1 t i < 1 < ∑n+1 i=1 t i The stochastic variant n is simply the number of events occurred during a unit time period. Now, since t i = 1 −λ log ri , n can be obtained by simply summing up random numbers until the sum for n+1 exceeds the quantity e−λ . That is, n is given by the following expression: ∑ni=0 ri > e−λ > ∑n+1 i=0 ri …………..((6)) Figure (1) the Poisson distribution 1 Lecturer: Hawraa Sh. Modeling & Simulation- Lecture -7- 26/11/2014 B) Sampling from a geometric distribution Let p and q be the probability of a success and failure respectively. The probability density function of the geometric distribution is: p(n) = pqn , n = 0,1,2 And its cumulative probability density function is: F(n) = ∑ns=0 pqs , n = 0,1,2 The expectation and the variance are: E(X) = p q Var(X) = p q And the random variant can be generated as follows: F(n) = ∑ns=0 pqs =p Since p = 1 − q we obtain that: 1−qn+1 1−q 1 − F(n) = qn+1 And 1 − F(n) between 0 and 1 then: r = qn+1 log r = (n + 1) log q n= log r log q ……………..((7)) C) Sampling from Binomial Distribution The probability density function of the binomial distribution is: p(k) = (nk)pk qn−k , k = 0,1,2, … The expectation and the variance are : E(X) = np Var(X) = npq We can generate variants from a binomial distribution with a given p and n as follows. We generate n random numbers, after setting a variable k 0 equal to zero. For each random numberri , i=1, 2... n, a check is made, and the variable k i is incremented as follows: k + 1 if ri < p k i = { i−1 ……………..((8)) k i−1 if ri > p The final quantity k n is the binomial variant. 2 Lecturer: Hawraa Sh. Modeling & Simulation- Lecture -7- 26/11/2014 Entities, Attributes & Activities An entity is an object of interest in the system: customer, manager, and cashier. An attribute is a (relevant) property of an entity: account balance, gender, skills Attributes are state variables. Activities & Delays An activity: is duration of known length: check balance, drink coffee, serve customer. Activities form part of the model specification A delay: is duration of unknown length: Waiting time in queue, Delays form part of the simulation result. State, State Variables The system state: is a description which is -complete and - minimal at any point in time A state variable: is a variable needed to describe the state: length of queue (0, 1, 2 ...), current activity of manager (sleeping, drinking coffee ...). Events An event: is an occurrence which is instant may change the state of the system Service is completed, Customer arrives from outside. Model Specification Discrete-event modeling raises the following questions: How does each event affect the system state and attributes? How are activities defined? What events mark the beginning and the end? What conditions (if any) must hold? How are delays defined? How must the simulation be initialized? Event Notice, Event List Event notice: A data record specifying an event The event notice must contain all the information necessary to execute the event (in particular the time it is scheduled to occur) (Future) event list: A list of event notices for future events The event list is the main data structure in a discrete-event simulator 3 Lecturer: Hawraa Sh. Modeling & Simulation- Lecture -7- 26/11/2014 The Event List The (future) event list (FEL) controls the simulation The FEL contains all future events that are scheduled The FEL is ordered by increasing time of event notice Example FEL (at some simulation time ≤ t): Conditional and Primary Events A primary event: An event whose occurrence is scheduled at a certain time Arrivals of customers. A conditional even: An event which is triggered by a certain condition becoming true Customer moving from queue to service. Timing Sometimes, activities last for an exact amount of time: – The clock cycle in a computer – Each phase of a traffic light – A certain operation in a manufacturing line Such exact times are deterministic. 4 Lecturer: Hawraa Sh. Modeling & Simulation- Lecture -7- 26/11/2014 Usually, activities last for varying amounts of time: – Inter-arrival times at bank – Service times at bank – Time to failure for a machine – Time that a user program runs Such times are random stochastic. Two mechanisms to advance the simulated time: Next-event time advance: The simulation clock is always advanced to the time of the next event, the state variables are updated and future event times are determined, until termination. Fixed-increment time advance: The simulation clock is always advanced in increments of ∆t time units. 5 Lecturer: Hawraa Sh.