Simulation Example A Bank Simulator We are given
Simulation
Example: A Bank Simulator • We are given: – The number of tellers – The arrival time of each customer – The amount of time each customer requires for service • Goal: design a simulator that will tell us how long each customer waits in line
More specifically… num. Tellers 3 customer 1: arrival customer 2: arrival customer 3: arrival customer 4: arrival customer teller 35 39 78 79 service 62 57 124 32 1 does not wait in line, is serviced by 1, and leaves the bank at time 97 2 does not wait in line, is serviced by 2, and leaves the bank at time 96 3 does not wait in line, is serviced by 3, and leaves the bank at time 202 4 waits in line for 17, is serviced by 2, and leaves the bank at time 128
Event Simulation • Discrete time-driven simulation – Start a simulation clock at 0 ticks – At each iteration, advance the clock by 1 tick and process any events that happen at that time • Problem?
Event Simulation • Discrete time-driven simulation – Start a simulation clock at 0 ticks – At each iteration, advance the clock by 1 tick and process any events that happen at that time • Problem? – Running time is based on number of ticks, not number of events – Unlikely that there will be an event at every tick
Event Simulation • Event-driven simulation – Start a simulation clock at 0 ticks – At each iteration, advance the clock to time of next event – How many events in our example? • Design of simulator?
Simulator Design - Incomplete while there are still events to be processed determine next event (arrival or departure) current time = event time if arrival if teller is free record 0 wait time and schedule departure for arrival+service else insert into wait queue else (departure) record departure time if wait queue is not empty remove customer with smallest arrival time record wait time as (current time - arrival time) schedule departure for current time+service
Alternatives • Use some probability distribution to determine arrival and service times – Example: generate a random number to indicate amount of time a customer’s request will take to service
- Slides: 8