Discrete Event Simulation

Slides:



Advertisements
Similar presentations
McGraw-Hill/Irwin Copyright © 2013 by The McGraw-Hill Companies, Inc. All rights reserved. A PowerPoint Presentation Package to Accompany Applied Statistics.
Advertisements

Based on Law & Kelton, Simulation Modeling & Analysis, McGraw-Hill
Simulating Single server queuing models. Consider the following sequence of activities that each customer undergoes: 1.Customer arrives 2.Customer waits.
IE 429, Parisay, January 2003 Review of Probability and Statistics: Experiment outcome: constant, random variable Random variable: discrete, continuous.
Modeling & Simulation. System Models and Simulation Framework for Modeling and Simulation The framework defines the entities and their Relationships that.
Lab Assignment 1 COP 4600: Operating Systems Principles Dr. Sumi Helal Professor Computer & Information Science & Engineering Department University of.
Fundamentals of Python: From First Programs Through Data Structures
 1  Outline  performance measures for a single-server station  discrete-event simulation  hand simulation  process-oriented simulation approach.
Sampling Distributions (§ )
Building and Running a FTIM n 1. Define the system of interest. Identify the DVs, IRVs, DRVs, and Objective. n 2. Develop an objective function of these.
Components and Organization of Discrete-event Simulation Model
1 Performance Evaluation of Computer Networks Objectives  Introduction to Queuing Theory  Little’s Theorem  Standard Notation of Queuing Systems  Poisson.
Evaluating Hypotheses
Lecture 4 Mathematical and Statistical Models in Simulation.
Lab 01 Fundamentals SE 405 Discrete Event Simulation
Graduate Program in Engineering and Technology Management
Slide - 1 Dr Terry Hinton 6/9/05UniS - Based on Slides by Micro Analysis & Design An example of a Simulation Simulation of a bank: Three tasks or processes:
Simulation Output Analysis
Simulation Examples ~ By Hand ~ Using Excel
1 Performance Evaluation of Computer Networks: Part II Objectives r Simulation Modeling r Classification of Simulation Modeling r Discrete-Event Simulation.
 1  Outline  stages and topics in simulation  generation of random variates.
Verification & Validation
General Simulation Principles
Random Sampling, Point Estimation and Maximum Likelihood.
1 1 © 2003 Thomson  /South-Western Slide Slides Prepared by JOHN S. LOUCKS St. Edward’s University.
1 1 Slide © 2001 South-Western College Publishing/Thomson Learning Anderson Sweeney Williams Anderson Sweeney Williams Slides Prepared by JOHN LOUCKS QUANTITATIVE.
Chapter 3 System Performance and Models. 2 Systems and Models The concept of modeling in the study of the dynamic behavior of simple system is be able.
© 2003, Carla Ellis Simulation Techniques Overview Simulation environments emulation exec- driven sim trace- driven sim stochastic sim Workload parameters.
Queuing Theory Basic properties, Markovian models, Networks of queues, General service time distributions, Finite source models, Multiserver queues Chapter.
Entities and Objects The major components in a model are entities, entity types are implemented as Java classes The active entities have a life of their.
Data Structures Using C++ 2E Chapter 8 Queues. Data Structures Using C++ 2E2 Objectives Learn about queues Examine various queue operations Learn how.
Waiting Lines and Queuing Models. Queuing Theory  The study of the behavior of waiting lines Importance to business There is a tradeoff between faster.
+ Simulation Design. + Types event-advance and unit-time advance. Both these designs are event-based but utilize different ways of advancing the time.
Lecture 19 Nov10, 2010 Discrete event simulation (Ross) discrete and continuous distributions computationally generating random variable following various.
1 Chapters 8 Overview of Queuing Analysis. Chapter 8 Overview of Queuing Analysis 2 Projected vs. Actual Response Time.
Chapter 2 – Fundamental Simulation ConceptsSlide 1 of 46 Chapter 2 Fundamental Simulation Concepts.
CSC 205 Programming II Lecture 22 Carwash Simulation.
Data Structures Using Java1 Chapter 7 Queues. Data Structures Using Java2 Chapter Objectives Learn about queues Examine various queue operations Learn.
SIMULATION OF A SINGLE-SERVER QUEUEING SYSTEM
OPERATING SYSTEMS CS 3530 Summer 2014 Systems with Multi-programming Chapter 4.
Discrete Event (time) Simulation. What is a simulation? “Simulation is the process of designing a model of a real system and conducting experiments with.
1 Simulation Implementation Using high-level languages.
Network Simulation Motivation: r learn fundamentals of evaluating network performance via simulation Overview: r fundamentals of discrete event simulation.
MODELING EXAMPLES Types of model Conceptual Containing components that have not been clearly Identified in terms of theoretic categories such as state,
Exam 2: Rules Section 2.1 Bring a cheat sheet. One page 2 sides. Bring a calculator. Bring your book to use the tables in the back.
1 1 Slide © 2011 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole.
1 1 Slide © 2009 South-Western, a part of Cengage Learning Slides by John Loucks St. Edward’s University.
OPERATING SYSTEMS CS 3530 Summer 2014 Systems and Models Chapter 03.
Simulation Chapter 16 of Quantitative Methods for Business, by Anderson, Sweeney and Williams Read sections 16.1, 16.2, 16.3, 16.4, and Appendix 16.1.
Chapter 7 Queues Introduction Queue applications Implementations.
Dr. Anis Koubâa CS433 Modeling and Simulation
(C) J. M. Garrido1 Objects in a Simulation Model There are several objects in a simulation model The activate objects are instances of the classes that.
1 1 Slide Chapter 12 Waiting Line Models n The Structure of a Waiting Line System n Queuing Systems n Queuing System Input Characteristics n Queuing System.
CDA6530: Performance Models of Computers and Networks Chapter 8: Statistical Simulation ---- Discrete Event Simulation (DES) TexPoint fonts used in EMF.
SIMULATION EXAMPLES. Monte-Carlo (Static) Simulation Estimating profit on a sale promotion Estimating profit on a sale promotion Estimating profit on.
Advantages of simulation 1. New policies, operating procedures, information flows and son on can be explored without disrupting ongoing operation of the.
 Simulation enables the study of complex system.  Simulation is a good approach when analytic study of a system is not possible or very complex.  Informational,
MODELING AND SIMULATION CS 313 Simulation Examples 1.
Simulation Examples And General Principles Part 2
Simple Queueing Theory: Page 5.1 CPE Systems Modelling & Simulation Techniques Topic 5: Simple Queueing Theory  Queueing Models  Kendall notation.
Ch 1: Simulation of Computer Networks. 1.1 Computer Networks and the Layering Concept Layering Concept Service Interface Protocol.
OPERATING SYSTEMS CS 3502 Fall 2017
Data Structures Using C++ 2E
Prepared by Lloyd R. Jaisingh
Discrete Event Simulation
Modeling and Simulation CS 313
More Explanation of an example in chapter4
MECH 3550 : Simulation & Visualization
SIMULATION EXAMPLES QUEUEING SYSTEMS.
Presentation transcript:

Discrete Event Simulation

Discrete Event Simulation Purpose Used to study quantitative system behaviour when analytic queueing theory is difficult to apply or when analytic modelling assumptions are not valid Relies on Queues and Lists

Queue ADT Revisited ADT Review Methods Lists were positional Stacks were last in first out Queues Queues are first-in-first-out Can have variants, priority queues etc.. Methods queue() // constructor, create an empty queue queueIsEmpty() // Determine whether queue is empty queueAdd(newItem, Success) // Add newItem to Queue queueRemove(success) // Remove item from front of queue getQueueFront(success) // Return front item but leave it in the queue (Peek)

Queue ADT Implementations Array, or list Like stack, you can use a List ADT Why distinguish between these ADTs at all? If you only use the properties of a stack, then calling it a stack helps others understand the program better Same with lists and queues in general The ADTs are building blocks

Discrete Event Simulation Develop an abstract model of a system that includes: Entities: Customers (for ex: people that need to fill their cars with gas) Resources (queues and service centres) (for ex: gas pump) Events Events cause changes in system state, usually things that cause the movement of customers between queues Arrival, completions Attributes of entities Time between customer arrivals Resource demands of customers at resources (for ex: the time needed for fill-up: pump gas and pay) Use the model to answer questions What is the mean response time of customers that stop for gas? What percentage of the time is the pump in use for fill-up?

Types of models Open models Closed models Infinite number of customers, they arrive with a certain rate regardless of how long it takes to get service Gas station on the 401 Closed models Fixed number of customers, rate of arrivals is affected by customer response times Gas station for a taxi fleet with 10 taxis

Open single server queue (Simulation terminology) Entity: building block that describe, customers, queues, and servers Events: cause movement of customers between queues, or other changes to system state Server Entity: Attributes: Scheduling Discipline (Fifo, could be others) Service Rate (Different pumps can serve a different number of litres per second and different systems for paying) Customer Arrival Event (Car arrives for gas) Server Customer Entity: Attributes: Mean Service time (for fill-up, could be expressed in litres) Mean interarrival time (Time between arrivals of cars) Departures Arrivals Device Completion Event (Customer has filled-up and leaves) Queue Entity: Attributes: Max Size (Is there a limit on how many cars can queue?)

Discrete event simulation process Events are maintained in a future event list ordered by time Discrete event simulation only considers time instants at which events occur System state remains unchanged between events Simulation clock used to keep track of simulated time To process the next event Advance clock to time of event Change the system state to reflect the impact of the event For example if a customer arrives it must be enqueued Generate future events caused by this event If the server is idle , the server starts to serve the customer so a device completion event must be enqueued at the appropriate place in the future event list

Event scheduling approach Keep track of all known future events in an event list Simulation divided into three parts 1. Initialization Data structures reflect system state at time zero 2. Main loop Take next event from event list Event includes time, type, and optional parameters Set clock to time of the event Call a function to handle event (and cause future events) Enqueue a customer or update the event list further Quit when termination condition is met 3. Output routine Output metrics collected in main loop

Flow chart for events of open single server queue Get next event Advance clock to the time of the event ? Arrival event Departure event N=N+1 Number of customers in system N=N-1 Set server idle Schedule arrival event for future customer Enqueue this customer Queue Not Empty ? Queue Empty Instructor’s Note: N is the number of customers in the system (ie queued or in service). Customers in service are not in the queue. Server Idle ? Server Busy Start service event Deque this customer, set server busy Schedule departure event for this customer

Single server queue pseudo-code Initialization: Let N be the number of customers in the system, set N=0 Set queue to empty Set server to idle Set event list to empty Set clock to zero Schedule first arrival event at time zero Enter main loop

Event subroutine pseudo-code Arrival event Increment N by 1 (N is the number of customers queued or in service) Schedule next arrival event: event time = clock + interarrival time Enqueue arriving customer If server is idle, call subroutine "start service" event Start service event Dequeue customer Set server to busy Schedule a departure event: event time = clock + service time Departure event Decrement N by 1 Set server to idle If queue is non-empty, call subroutine for "start service event"

Options for terminating the simulation To leave the main loop and go to step 3 Call output routine when N exceeds some pre-specified quantity Schedule "end of simulation" event during initialization Event time equal to desired termination time Call output routine when event occurs Stop scheduling arrivals after some pre-specified time Call output routine if no events remain in event list

Closed model exercise Consider a closed model with a single server Customers think for an average of Z time units between visits to the server How do we adapt the open model simulation pseudo-code for this purpose? Solution: Initialization, start with N customers instead of zero, generate an arrival event for each with a mean inter-arrival time of Z time units (put them in the future event list) Arrival subroutine: don’t generate a future arrival Departure subroutine: generate an arrival event with mean value Z for the customer Solution: Initialization, start with N customers instead of zero, generate an arrival event for each with a mean interarrival time of Z time units (put them in the future event list) Arrival subroutine: don’t generate a future arrival Departure subroutine: generate an arrival event with mean value Z for the customer

Using distributions for generating psuedo-random variates (numbers) for service and inter-arrival times Using distributions Service times, sleeping times, inter-arrival times etc Can come from many possible distributions Deterministic Uniform Normal Exponential 1 Cummulative Density Function (CDF) 1 Value of variate

Inverse transformation method Use a pseudo-random number generator to generate number between 0 and 1, then compute random variate using a known inverse function for the CDF y = Math.random() returns a psuedo-random double number betwewn 0.0 and 1.0, the numbers are pseudo-random because they eventually repeat themselves Inverse CDFs are well known for many distributions Deterministic Uniform Normal Exponential 1 Value of variate x = x x = y x = x = - ln y

Examples For the exponential distribution: x = - mean ln(y) Say random returns the values y = 0.1, 0.5, and 0.3 Suppose we want an exponentially distributed random variable with a mean of 4 then: x = - 4 * ln(0.1) = 9.21 x = -4 * ln(0.5) = 2.77 x = -4 * ln(0.3) = 4.81 After a very large number of independent uniformly distributed values for y, the mean of x will approach 4

Histogram method Observe inter-arrival times and service times Record them in a table such as follows: Chose a uniformly distributed pseudo random variable between 0 and 1, match with appropriate value Better for multi-modal distributions or for values of unknown distribution Value 0 1 Probability

Collection of metrics Once we are able to step through a simulation we can collect metrics Suppose we are interested in the following The average number of customers waiting for service The standard deviation of the number of customers waiting for service The utilization of the server We now consider how to modify the simulator for this purpose Define the average and sample variance as

Collection of metrics for open single server queue Get next event Advance clock ? Arrival event Departure event N=N+1 busytime = busytime + (clock - busystart) N=N-1 Set server idle Schedule arrival event for future customer Enqueue this customer save time of arrival Queue Not Empty Queue Empty Server Idle Server Busy busystart = clock waiting time = clock - time of arrival NWAIT = NWAIT + 1 SWAIT = SWAIT + waiting time SQWAIT = SQWAIT + sqr(waiting time) Start service event Deque customer, set server busy Schedule departure event for this customer

Collection of metrics Mean and variance of customer waiting time Initialization NWAIT = 0 (Total number of customers that have waited) SWAIT = 0 (Sum of waiting times) SQWAIT = 0 (Sum of squares of waiting times) Waiting time computed when customer begins service Remove first customer from queue and get its time of arrival waiting time = clock - time of arrival NWAIT = NWAIT + 1 SWAIT = SWAIT + waiting time SQWAIT = SQWAIT + sqr(waiting time) At end of simulation Mean waiting time = SWAIT/NWAIT Population variance in waiting time = (SQWAIT - sqr(SWAIT)/NWAIT)/NWAIT Standard deviation of waiting time is therefore sqrt(population variance) Visualize whats going on in the collection of mean waiting time

Utilization Start service event Departure event Output Results Busy start = clock time Departure event Busy time = Busy time + (clock time - Busy start) Output Results Utilization = Busy time / Total time Where Total time is the final value on the simulation clock Visualize the collection of the utilization measure

Instrumenting to collect metrics Tedious and error prone Need to verify your instrumentation code One of the advantages of simulation packages is that they provide automatic support for many metrics

Example of Results Suppose we have an open model with arrival rate  = 1, 2, 3, 4 arrivals per second The time between arrivals (interarrival times are exponentially distributed) The service times have a mean of S = 0.18 seconds and are exponentially distributed  Rclient = S/(1-U), Userver =  D (from queueing theory) 1 0.2 0.19 2 0.3 0.38 3 0.4 0.57 4 0.8 0.76 5 3.8 0.95

Notes For this simple system we can use queueing theory Simulation will only approximate the exact results of the queueing theory (because of pseudo random numbers and finite number of events) As U increases we will have to simulate longer and longer We always repeat simulations many times with different initial seeds Math.setSeed(long seed) to start the sequence of numbers at a specific value The mean of the mean results of each run is normally distributed (central limit theorem), therefore we can take a confidence interval to assess the statistical significance of the results As we vary our assumptions about distributions and sequences requests for queues -- simulation can give more accurate results

How can OO support simulation? Various types of queues can be subclasses of a Queue class First come first served Multiple server queues Processor sharing Each of n queued customers gets 1/nth of the server Various types of events can be subclasses of an Event class Arrival events, departure events, other events if they are needed Customer objects can keep track of their own state as they flow through the system

Simulating Program Behaviour Customer starts Consider the following graph that describes a program’s logic The edges are annotated with branching probabilities for going from one vertex to the next The nodes are labeled with a service (S) demand at a processor 1 1 If 2 0.3 0.7 Loop 13 3 1 1 4 1 5 0.9 0.1 6 Customer ends