Discrete Event Simulation Speaker: Lee, Chia-Peng Advisor: Phone Lin MCN Lab., Dept. of CSIE, NTU Email: jet.lee@pcs.csie.ntu.edu.tw TEL: +886-2-33664888#538
Grading Midterm Exam 35% Final Exam 30% Final Project 30% • Step 1: Find a paper with the analytical model • Step 2: Read the paper in detail • Step 3: Write the simulation to validate the analytical model • Step 4: Compare the errors of your simulation results with the results in the paper • [optional] Step 5: Do some more if you can (e.g., performance analysis via simulation or analytical models). • Step 6: Prepare your presentation Report 5% 2
Grading Find a paper with the analytical model • Where to find a paper? - IEEE Xplore: http://ieeexplore.ieee.org/Xplore/guesthome.jsp - ACM Digital Library: http://portal.acm.org/ • Which Journal/Magazine? • Magazines • Journals - IEEE Personal Communications Magazine - IEEE Transactions on Vehicular Technology - IEEE Communications Magazine - IEEE Journal on Selected Areas in Communications - IEEE Wireless Communications Magazine - IEEE Transactions on Mobile Computing - IEEE Networks - IEEE Transactions on Computer - IEEE Communications Letter - IEEE Transactions on Wireless Communication - IEICE Transactions on Communication - Security and Communication Networks - ACM/Springer Wireless Networks - Journal of Wireless Communications and Mobile Computing - ACM/Springer Mobile Networks and Applications 3
Outline Introduction to Simulation • What is Simulation? • Why Simulate? • System & Simulation Simulation Implementation A Simulation Example • M/M/c/c • Handoff Model 4
What is Simulation? Simulation is the imitation of some real thing, state of affairs, or process. Simulation is defined as the process of creating a model of an existing or proposed system to gain some understanding of how the corresponding system behaves. 5
What is Simulation? System Experiment and Experiment with an Experiment with “ emulation ” system real system simulations and models (real traffic input/output) Test it in a testing Put the system in the real Physical Mathematical models environment (with environment and use it models (execution in no real-time, non generated traffic) (with real traffic) real traffic input/output) Analysis Simulation (Queueing Therory) 6
Why Simulate? (Example) stack landing 7
Why Simulate? (Example Cont. ) An Example of Simulation in the Real World • The Airport Problem - The airport has two runways, one for landing and one for takeoff. If the landing way is busy, the airplane in the air must enter in a stack. However, when the stack is full, the takeoff way must become landing way. Airports have a waiting stack, where airplanes wait before they can land. In this stack, airplanes fly a holding pattern on an assigned altitude. • What we want to know? - Calculate the stack length. - The average time a plane waits for takeoff. - The average utilization of the landing way and the takeoff way. 8
Why Simulate? (Example Cont. ) Such measures of performance can get from historical data records. However, we are interested in the impact of certain proposed changes. • Landing airplane arrival rate. • Takeoff airplane arrival rate. • Increasing the runways. 9
Why Simulate? Save time Reduce cost Test design ideas (performance measurement) • The impact of certain changes of parameter. - The arrival rate of certain traffic class. - The service time of certain traffic class. - The number of application server. Predict the future behavior of the system 10 10
Simulation Static/Dynamic Simulation • Static - Time simply plays no role • Dynamic - A system evolves over time Continuous/Discrete Simulation • Continuous - The state change continuously with respect to time • Discrete - The state change instantaneously at separated points in time 11 11
Discrete-Event Simulation Dynamic • Simulation clock - Keep track of the current value of simulated time as the simulation proceeds • A mechanism to advance simulated time from one value to another Discrete • The state change instantaneously at separate points in time - The system can change at only a countable number of points in time. • These points in time are the ones at which an event occurs. • Event - An instantaneous occurrence that may change the state of the system 12 12
Discrete-Event Simulation e e e e e e 0 3 5 4 1 2 Time a a d a d 0 1 2 1 3 2 A 2 A 3 A 1 S 1 S 2 All state changes occur only at event times for a discrete-event simulation model • Periods of inactivity are skipped over by jumping the clock from event time to event time Stochastic • Interarrival times A 1 , A 2 ,… and service times S 1 , S 2 ,… - Are random variables - Have cumulative distribution functions 13
The Phase of Simulation Construction • Formularize the problem • Collecting necessary input data as parameter (arrival rate, departure rate) • Design a simulation model to match the problem Running • Run this simulation for enough time to estimate the system’s result. Debugging • See if the result make sense. • Compare to an analytic model 14 14
SIMULATION IMPLEMENTATION
Simulation Event Implementation • An instantaneous occurrence that may change the state of the system Programming Attributes of an event Language • Type (e.g., arrival, departure, etc.) • C • Timestamp Priority Queue in C++ Standard Template Library • C++ priority_queue<T, Sequence, Compare> • Other attributes • Java - Location info. • C# • … Event List • Event list is a linked list • Events are sorted according to the timestamp value. • Automatically adjusts the event order at each event insertion. Efficiency • Data structure: link-list v.s. min-Heap data structure • Time Complexity • Memory allocation management • Freelist 16 16
Random Number Generator R.N.G.’s for various probability distributions • Used when we need a time period with a certain distribution • Uniform, exponential, gamma, etc. Implementation • The inverse transform method - CDF: F ( x ) = Pr[ X ≤ x ] 17 17
Inverse Transform Method 1 F ( x ) y j F -1 ( y j ) y i Probability Uniform(0,1) 0 x i x j X 18 18
Inverse Transform Method Validity of this method: • Whether r.v. F -1 ( U ) has the CDF F ( x )? F’ ( x ) = Pr[ F -1 ( U ) ≤ x ] = Pr[ U ≤ F ( x )] = F U ( F ( x ) ) = F ( x ) 19 19
Inverse Transform Method Example: exponential distribution with rate • CDF: F ( x ) = 1 - e - λ X • Set F ( X ) = U => 1 - e - λ X = U => e - λ X = 1- U => - λ X = ln(1- U ) => X = -ln(1- U )/ λ = -ln( U )/ λ Note: u!=0 20 20
Inverse Transform Method Applicable when the inverse function of F ( x ) , i.e., F -1 ( x ) , can be derived Preferably when F -1 ( x ) has an east-to-use form Steps: • Generate a uniform (0,1) random number u • Compute x = F -1 ( u ), and x is the desired random number 21 21
Generating Gamma-distributed 22 22
Generating Gamma-distributed 23 23
A S IMULATION E XAMPLE M/M/C/C
Queueing System Key elements: customers and servers • Customer: arrival process • Server: service rate and number of servers Notation: A/B/c/N/K • A: inter-arrival time distribution (arrival process) • B: service time distribution • c : number of servers/channels • N: system capacity • K: queue discipline (Unless specified, it is assumed to be First-In-First-Out) 25 25
Queueing System M/M/c/c • The 1 st M: Markovian / Memoryless - Possision arrivals / exponential inter-arrival time • The 2 nd M: Markovian - Exponential service time • c: c servers/channels • c: system capacity Blocking 26 26
Analysis: M/M/c/c (Erlang B) λ λ λ λ λ … 2 c-1 c 1 0 μ 2 μ (c-1) μ c μ 3 μ 27 27
Simulation Models: M/M/c/c • ARRIVAL event represents a customer arrival. arrival 1 arrival 2 departure 1 1. generate next call: arrival 2 2. if channel > 0 then channel-- and generate service time: departure 1 28 28
Simulation Models: M/M/c/c arrival 1 arrival 2 arrival 3 departure 1 departure 2 1. generate next call: arrival 3 2. if channel > 0 then channel-- and generate service time: departure 2 29 29
Simulation Models: M/M/c/c • DEPARTURE event represents a customer departure . arrival 1 arrival 2 arrival 3 departure 1 departure 2 1. channel++ 30 30
Simulation Models: M/M/c/c Assume that c=2 Arrival 5 is Blocking P b = N_blocking / N_arrival arrival 1 arrival 2 arrival 3 arrival 4 arrival 5 arrival 6 departure 1 departure 2 departure 4 1. generate next call: arrival 6 2. if channel = 0 then N_blocking++ 31 31
Simulation Models: Event Class 32 32
Simulation Models: Initialize 實驗次數 100 萬次 33 33
Simulation Models: Timing Routine generate next call if channel > 0 then channel generate service time if channel = 0 then N_blocking++ channel++ 34 34
Simulation Models: Report M/M/c/c • Inter-arrival time is Exponential distribution with rate 50.0 • Service time is Exponential distribution with rate 10.0 • c: number of channels is 8 • c: system capacity is 8 http://www.erlang.com/calculator/erlb 35 35
Priority Queue 36 36
Priority Queue 37 37
A S IMULATION E XAMPLE HANDOFF MODEL
Recommend
More recommend