Discrete Event Simulation

Similar documents
CDA6530: Performance Models of Computers and Networks. Chapter 8: Discrete Event Simulation (DES)

Queuing Analysis. Chapter Copyright 2010 Pearson Education, Inc. Publishing as Prentice Hall

Ways to study a system System

Mechanics Answers to Examples B (Momentum) - 1 David Apsley

Clairvoyant scheduling of random walks

Introduction to Queuing Networks Solutions to Problem Sheet 3

Mechanics Lecture Notes

Collision Theory. Reaction Rates A little review from our thermodynamics unit. 2. Collision with Incorrect Orientation. 1. Reactants Must Collide

λ λ λ In-class problems

Physics 207 Lecture 10. Lecture 10. Employ Newton s Laws in 2D problems with circular motion

Clock-driven scheduling

Automation in Complex Systems MIE090

5/15/18. Operations Research: An Introduction Hamdy A. Taha. Copyright 2011, 2007 by Pearson Education, Inc. All rights reserved.

Lab Activity Momentum (20 Points)

Notes on numerical solution of differential equations

TOPIC B: MOMENTUM EXAMPLES SPRING 2019

Mining Data Streams. The Stream Model Sliding Windows Counting 1 s

The University of British Columbia Computer Science 405 Practice Midterm Solutions

Time Reversibility and Burke s Theorem

NAME DATE CLASS. Motion and Speed. position 1. When something moves, it changes iitsopon. Motion. 2. Otoinm can be described as a change in position.

Discrete Event Simulation. Motive

Conceptual Chemistry

Gravity Teacher s Guide

Momentum & Collisions

Minimizing the Number of Tardy Jobs

Physics 207 Lecture 11. Lecture 11. Chapter 8: Employ rotational motion models with friction or in free fall

Isaac Newton ( ) 1687 Published Principia Invented Calculus 3 Laws of Motion Universal Law of Gravity

PHYS 1405 Conceptual Physics 1 Laboratory #5 Momentum and Collisions. Investigation: Is the total momentum of two objects conserved during collisions?

Cyclic Schedules: General Structure. Frame Size Constraints

Homework 4 Math 11, UCSD, Winter 2018 Due on Tuesday, 13th February

Physics Knowledge Organiser P8 - Forces in balance

Session-Based Queueing Systems

Moving away from Happy Physics World

Problem Set 4 Momentum and Continuous Mass Flow Solutions

Chapter 6. Preview. Section 1 Gravity and Motion. Section 2 Newton s Laws of Motion. Section 3 Momentum. Forces and Motion.

( m/s) 2 4(4.9 m/s 2 )( 52.7 m)

( m/s) 2 4(4.9 m/s 2 )( 53.2 m)

Introduction to Queueing Theory with Applications to Air Transportation Systems

Scheduling I. Today Introduction to scheduling Classical algorithms. Next Time Advanced topics on scheduling

Queuing Theory. The present section focuses on the standard vocabulary of Waiting Line Models.

Chapter 2 Motion in One Dimension. Slide 2-1

Mining Data Streams. The Stream Model. The Stream Model Sliding Windows Counting 1 s

Math 416 Lecture 11. Math 416 Lecture 16 Exam 2 next time

EE 368. Weeks 3 (Notes)

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

PHY 221 Lab 8. Momentum and Collisions: Conservation of momentum and kinetic energy

Queueing systems. Renato Lo Cigno. Simulation and Performance Evaluation Queueing systems - Renato Lo Cigno 1

Distributed Systems Principles and Paradigms. Chapter 06: Synchronization

A Deeper Look into Phase Space: The Liouville and Boltzmann Equations

Operations Research II, IEOR161 University of California, Berkeley Spring 2007 Final Exam. Name: Student ID:

A 2-Approximation Algorithm for Scheduling Parallel and Time-Sensitive Applications to Maximize Total Accrued Utility Value

Continuous-Time Markov Chain

Distributed Systems Principles and Paradigms

Queuing Networks: Burke s Theorem, Kleinrock s Approximation, and Jackson s Theorem. Wade Trappe

UNIVERSITY OF YORK. MSc Examinations 2004 MATHEMATICS Networks. Time Allowed: 3 hours.

Insert Sorted List Insert as the Last element (the First element?) Delete Chaining. 2 Slide courtesy of Dr. Sang-Eon Park

CHAPTER 2UNIFORMLY ACCELERATED MOTION

Andrew Morton University of Waterloo Canada

Chapter 3 Acceleration

Contents. Objectives Velocity Addition CM Velocity 2 D Collisions totally inelastic elastic Recap. Contents

Solutions to COMP9334 Week 8 Sample Problems

Queueing Theory I Summary! Little s Law! Queueing System Notation! Stationary Analysis of Elementary Queueing Systems " M/M/1 " M/M/m " M/M/1/K "

Chapter 11 Output Analysis for a Single Model. Banks, Carson, Nelson & Nicol Discrete-Event System Simulation

Name of the Student: Problems on Discrete & Continuous R.Vs

AP Physics Study Guide Chapter 17 Electric Potential and Energy Name. Circle the vector quantities below and underline the scalar quantities below

Classical Mechanics Lecture 4

8. The graph below shows a beetle s movement along a plant stem.

The Generalized Interpolation Material Point Method

Physics 201, Midterm Exam 1, Fall Answer Key

EE/PEP 345. Modeling and Simulation. Spring Class 11

Online Supplement to Delay-Based Service Differentiation with Many Servers and Time-Varying Arrival Rates

Physics 20 Amusement Park WEM

3 Acceleration. positive and one is negative. When a car changes direction, it is also accelerating. In the figure to the

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Physics Department. Physics 8.01 Fall Term 2006

a = v2 R where R is the curvature radius and v is the car s speed. To provide this acceleration, the car needs static friction force f = ma = mv2

Magnetism and Gravity

(k = force constant of the spring)

Learning Objectives:

Simulation & Modeling Event-Oriented Simulations

Created by T. Madas COLLISIONS. Created by T. Madas

Unit 1: Mechanical Equilibrium

If there is now a constant air resistance force of 35 N, what is the new maximum height the ball attains?

Class 11 Physics NCERT Exemplar Solutions Motion in a Straight Line

Chapter: The Laws of Motion

1 A freight car of mass 20,000 kg moves along a frictionless level railroad track with a constant speed of 15 m/s. What is the momentum of the car?


Physic 602 Conservation of Momentum. (Read objectives on screen.)

Functions of Two Variables

Directed Reading B. Section: Newton s Laws of Motion NEWTON S FIRST LAW OF MOTION

Got Me Under Pressure

Discrete-event simulations

1. A train moves at a constant velocity of 90 km/h. How far will it move in 0.25 h? A. 10 km B km C. 25 km D. 45 km E. 50 km

Modelling Complex Queuing Situations with Markov Processes

Course Outline Introduction to Transportation Highway Users and their Performance Geometric Design Pavement Design

Comp 204: Computer Systems and Their Implementation. Lecture 11: Scheduling cont d

CMSC 451: Lecture 7 Greedy Algorithms for Scheduling Tuesday, Sep 19, 2017

A particle system takes small time-steps and updates each particle's location and velocity based on the forces acting on it.

Scheduling I. Today. Next Time. ! Introduction to scheduling! Classical algorithms. ! Advanced topics on scheduling

Modeling the Motion of a Projectile in Air

The Discrete EVent System specification (DEVS) formalism

Transcription:

Discrete Event Simulation Henry Z. Lo June 9, 2014 1 Motivation Suppose you were a branch manager of a bank. How many tellers should you staff to keep customers happy? With prior knowledge of how often customers come in, how fast it takes to serve a customer, and how long customers wait before leaving, it is possible to answer this question using a simulation: Start with k tellers. Customers enter the bank at rate λ 1. If a customer enters when a teller is free, process the customer. Otherwise put customer in a queue. Customers get processed at rate λ 2, after which the teller is freed and handles the next customer from the dequeue. See Figure 1 for a diagram. In this simulation, we can measure performance in terms such as average queue length, average wait time, etc. λ 1 and λ 2 can represent a probability distribution of values (e.g. Poisson) rather than a single rate, but both cases are handled similarly. customers arriving at rate λ 1 customer queue teller 1 customers dequeuing at rate 3λ 2 teller 2 teller 3 Figure 1: Diagram demonstrating bank teller problem, with 3 tellers. 1

2 Techniques In general, there are two methods of performing this type of simulation: Simulate the passage of time, then calculate what events happened in the time period. Calculate when future events will happen (updating as needed), and then jump from event to event through time. 2.1 Time-driven simulation Time-driven simulations often need a time jump interval dt to be specified. The general procedure: 1. Move forward dt time units. 2. Calculate all events that happened within that time frame, and take them into account. 3. Loop back to 1 until complete. For our bank example: 1. Move forward dt time units. 2. Process events in this time span: If there are customers being processed, subtract dt from their process time; finish processing a customer if time exceeds λ 2. Subtract λ 1 from the time until next customer, resetting the time and adding customers as necessary. If a teller is free, dequeue a customer and start processing. 3. Loop back to 1 until complete. Note that calculating exactly what events occurred in the time step can be fairly difficult (which checks do we do first?). Thus, typically they are synchronized to the end of each leap, i.e. events such as dequeuing and queuing only happen at the end of each time leap. This can be simplified by a smaller dt, but this means we have to run many more checks. It may make more sense to model event-by-event instead. 2.2 Event-driven simulation Event-driven simulations can be more difficult to program, but are more accurate and faster. The idea is: 1. Add an initial set of events to happen in the future. 2

2. Move to the first event to happen in this set. 3. Remove this event, and add new events spawned off by this event. 4. Repeat from step 2 until done. What data structure is optimal for storing events and when they occur? Priority queues! For our bank teller example: 1. Queue event new customer with time 1/λ 1. 2. Dequeue soonest event from priority queue, and subtract that time from all event times. If event is new customer and if a teller i is free, mark teller i as occupied, then add event customer done at teller i in 1/λ 2. if no teller is free, put customer into customer queue. If event is customer done at teller i and if the customer queue is not empty, then dequeue a customer, mark teller i as occupied, then add event customer done at teller i in 1/λ 2. if the customer queue is empty, then mark i as free. 3. Repeat step 2 until done. As events are precomputed in the past, they do not need to be checked at every time step as in time-driven simulations. This makes the simulation process much quicker. If we want to see the changes between events, e.g. for visualization purposes, then we can run the simulation without having to check for events, until a scheduled event occurs. We demonstrate this with another example. 3 Particle Collisions Given a bunch of particles (assumed to be spheres), how can you simulate them bouncing off of each other? Assume each point is a square of size 2s, a starting position x, y, and a starting velocity v x, v y. There are two types of events in this system: collisions between points, and collisions between a point and a wall. Suppose for the sake of simplicity, when two points collide sideways, they reverse horizontal direction, and when they collide vertically, they reverse vertical direction. There is no gravity or air resistance. The procedure goes as follows: 1. Delete the soonest event, subtract its time from all events. 3

Figure 2: A collision between two particles (a) and two particles passing through each other due to a large dt (b). 2. Disregard the event if one of the particles have been involved in a collision since the event has been added. 3. Process the event, and add others if needed. If two particles are colliding, update velocities of colliding particles (reverse horizontal direction if horizontal collision, etc.) Calculate future collisions for the particles with new velocities. Perform similar calculations for particles colliding with walls. 3.1 Collision detection The time-driven solution is to perform collision detection at each time step or frame. If particles overlap, then there was a collision. In order to avoid error, the simulation must be rewound to when the collision occurred and reran in order. Alternatively, we can simply bounce the particles when we detect the collision (rather than when the collision actually happens), and accept the error that comes with this. There is also the problem of the length of timestep dt, as before. When dt is too large, we may miss some collisions altogether (see Figure 2). When dt is too small, then we have to check collisions many times. In either case, if we have n particles, we need to do O(n 2 ) checks every time step. 3.2 Event-driven simulation At the beginning of the simulation, we first determine all the collisions that each particle will have - with the wall, and with each other. As these collisions happen, we move through time and add more collisions to the priority queue, and invalidate some of the future reactions that were previously predicted to happen. 4

Figure 3: Collision of a particle with wall. 3.2.1 Collisions with walls Collisions with walls are easiest to calculate, because the wall doesn t move. Suppose the walls exist at x = 0, y = 0, x = 1, and y = 1. Then the time until the particle s edge collides with a wall is t, where: x + s + v x t = 1 if v x > 0 x s + v x t = 0 if v x < 0 y + s + v y t = 1 if v y > 0 y s + v y t = 0 if v y < 0 Collisions in x don t affect collisions in y. Solving for t: 1 x s v x if v x > 0 x s v t = x if v x < 0 1 y s v y if v y > 0 y s v y if v y < 0 See Figure 3 for a visual. 3.3 Collisions between particles To simplify computations, let s be the same for every particle. There are two ways in which particles can collide - horizontally, after which they reverse horizontal directions, and vertically, in which case they reverse vertical directions. Since s is the same, one of the corners of one square must touch the edge of the other square. In other words, we have a horizontal collision at time t: 5

if v x > 0, x + s + v x t = x s + v xt (there is horizontal overlap) AND y + s + v y t is between y + s + v yt and y s + v yt OR y s + v y t is between y + s + v yt and y s + v yt if v x < 0, x s + v x t = x + s + v xt AND y + s + v y t is between y + s + v yt and y s + v yt OR y s + v y t is between y + s + v yt and y s + v yt The first case describes the first square going right, and the second square going left; the second case describes the opposite situation. Similar equations need to be defined for vertical collisions. We can solve either of these equations for the time of collision t: x + s + v x t = x s + v xt x x + s + s = v xt v x t x x + 2s v x v x = t 6