CPSC 531 DiscreteEvent Simulation Instructor Anirban Mahanti Office
CPSC 531: Discrete-Event Simulation Instructor: Anirban Mahanti Office: ICT 745 Email: mahanti@cpsc. ucalgary. ca Class Location: TRB 101 Lectures: TR 15: 30 – 16: 45 hours Class web page: http: //pages. cpsc. ucalgary. ca/~mahanti/teaching/F 05/CPS C 531/ Notes derived from “Simulation Modeling and Analysis” by A. Law and W. Kelton, Third edition, Mc. Graw Hill, 2000. CPSC 531: DES Overview 1
Objective r Learn the basics of discrete-event simulation r We will focus on a simple single-server service center. Possible examples: m Convenience store: customers, cashiers m Airport: runways, airplanes Customer in service Arriving customer Customers in queue Server Departing customer CPSC 531: DES Overview 2
What is Discrete-Event Simulation (DES)? r Modeling of a system as it evolves over time by a representation where the state variables change instantaneously at separated points in time m More precisely, state can change at only a countable number of points in time m These points in time are when events occur r What is an event? Instantaneous occurrence that may change the state of the system m Arrival of a customer m Service completion (and departure) of a customer m End of simulation (a “fake” event) CPSC 531: DES Overview 3
Single-Server Service Center Customer in service Arriving customer Customers in queue Server Departing customer r Performance measures of interest: m Average customer waiting time m Average number of customers in queue m Average server utilization r How do we simulate this system and obtain measures of interest? m Need to simulate “time” … CPSC 531: DES Overview 4
Time Advance Mechanism r Simulation clock: Variable that keeps the current value of (simulated) time in the model m Must decide on, be consistent about, time units m Usually no relation between simulated time and (real) time needed to run a model on a computer r Two approaches for time advance m Fixed-increment time advance m Next-event time advance CPSC 531: DES Overview 5
Fixed-Increment Time Advance 0 Δt 2Δt 3Δt e 1 4Δt e 2 5Δt 6Δt Time r Events occur at a fixed increment r Events occurring between time increments must be moved to an increment boundary r Simple to implement, but not an accurate realization of occurrence of events CPSC 531: DES Overview 6
Next-event Time Advance r Initialize simulation clock to 0 r Determine times of occurrence of future events – event list r Clock advances to next (most imminent) event, which is executed m Event execution may involve updating event list r Continue until stopping rule is satisfied (must be explicitly stated) r Clock “jumps” from one event time to the next, and doesn’t “exist” for times between successive events … periods of inactivity are ignored CPSC 531: DES Overview 7
Next-event time-Advance (cont’d. ) r Consider the single-server service center example ti = time of arrival of ith customer (t 0 = 0) Ai = ti – ti-1 = interarrival time between (i-1)st and ith customers Si = time spent serving the ith customer Di = delay in queue of ith customer Ci = ti + Di + Si = time ith customer completes service and departs CPSC 531: DES Overview 8
Want to write a next-event program? r Determine the events and understand what happens when it occurs r Generate events and keep a time-ordered list of the events r Based on the time-ordered list, we will have to schedule events r Track information of interest during the simulation r Finally, generate report when simulation ends CPSC 531: DES Overview 9
Components of a DES Program r Simulation clock – current value of simulated time r System state – variables to describe state m Server status, number in queue, arrival times, etc r Event list – times of future events for each event type r Statistical counters – to accumulate performance measures m Waiting time in queue, server utilization, … CPSC 531: DES Overview 10
Components of a DES Program (cont’d. ) r Initialization routine m Start simulation at time 0 r Timing routine m determines next event time, type; advances clock r Event routines m carry out logic for each event type r Library routines m utility routines to generate random variates, etc. r Report generator r Main program m ties routines together, executes them in the correct order CPSC 531: DES Overview 11
Organization of a DES Program Start Initialization Routine Timing Routine Main Routine Event Routines Report Generator Yes Simulation Done? Library Routines No Stop CPSC 531: DES Overview 12
DES Program Flow Start Initialization Routine Main Routine 1. Set clock = 0 2. initialize state & counters 3. Initialize event list 4. Return to main program CPSC 531: DES Overview 13
DES Program Flow Main Routine Timing Routine 1. Determine next event type i 2. Advance simulation clock 3. Return to main program CPSC 531: DES Overview 14
DES Program Flow Main Routine Event routine i Library Routine 1. update system state 2. update counters 3. generate future events & add them to the event list CPSC 531: DES Overview 15
DES Program Flow Timing Routine Main Routine Event Routines Simulation Done? No Return to main; Invoke timing routine CPSC 531: DES Overview 16
Hand Simulation of a Single Server Service Center r Interarrival times (all times are in minutes): 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … r service times: 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … r n = 6 delays in queue desired r “Hand” simulation: m Display system, state variables, clock, event list, statistical counters … all after execution of each event m Use above lists of interarrival, service times to “drive” simulation m Stop when number of delays hits n = 6, compute output performance measures CPSC 531: DES Overview 17
Performance Measures r “Expected” average delay in queue (excluding service time) of the n customers completing their delays r Expected average number of customers in queue (excluding any in service) m A continuous-time average r Expected utilization (proportion of time busy) of the server m Another continuous-time average CPSC 531: DES Overview 18
Time = 0 Status shown is after all changes have been made in each case … Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 19
Time = 0. 4 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 20
Time = 1. 6 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 21
Time = 2. 1 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 22
Time = 2. 4 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 23
Time = 3. 1 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 24
Time = 3. 3 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 25
Time = 3. 8 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 26
Time = 4. 0 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 27
Time = 4. 9 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 28
Time = 5. 6 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 29
Time = 5. 8 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 30
Time = 7. 2 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … CPSC 531: DES Overview 31
Time = 8. 6 Interarrival times: Service times: 0. 4, 1. 2, 0. 5, 1. 7, 0. 2, 1. 6, 0. 2, 1. 4, 1. 9, … 2. 0, 0. 7, 0. 2, 1. 1, 3. 7, 0. 6, … Final output performance measures: Average delay in queue = 5. 7/6 = 0. 95 min. /customers Time-average number in queue = 9. 9/8. 6 = 1. 15 customers Server utilization = 7. 7/8. 6 = 0. 90 (dimensionless) CPSC 531: DES Overview 32
DES Programming Issues r Program termination rules m Number of events, total time r Client balking – leave the queue without service r Time breaking during event scheduling m Choose departure before arrival m Two arrivals at the same time? Randomly choose one m Other defined rules CPSC 531: DES Overview 33
- Slides: 33