Cpsc531 Des
Cpsc531 Des
Carey Williamson
Department of Computer Science
University of Calgary
Fall 2017
Recap: Simulation Model Taxonomy
2
Recap: DES Model Development
3
Overview of DES Module
4
Outline
5
Outline
6
Concepts in Discrete-Event Simulation (1 of 2)
7
Concepts in Discrete-Event Simulation (2 of 2)
9
Example 1: ABC Call Center
▪ Random variables:
— Arrival time between calls
— Service time (different distributions for Alice, Bob, and Chris)
10
States in ABC Call Center Example
▪ System state:
— The number of callers waiting to be served at time t
— Indicator that Alice is idle or busy at time t
— Indicator that Bob is idle or busy at time t
— Indicator that Chris is idle or busy at time t
▪ Events:
— Arrival of a call
— Service completion by Alice
— Service completion by Bob
— Service completion by Chris
▪ Activities:
— Inter-arrival time
— Service time by Alice
— Service time by Bob
— Service time by Chris
▪ Random variables:
— Arrival times of customers
— Sizes of groups
— Time of day
— Service times for ordering, eating, payment, etc.
13
Example 2: Pancake Manor
14
States in Pancake Manor Example
▪ System state:
— The number of customers waiting to be seated at time t
— The number of customers waiting to order at time t
— The number of customers waiting for food at time t
— The number of customers eating at time t
— The number of customers waiting to pay at time t
— The number of available/occupied tables at time t
▪ Events:
— Arrival of a customer (or group of customers)
— Service completion by host/hostess
— Service completion by waiter/waitress
— Service completion by cook
— Service completion by cashier
▪ Activities:
— Inter-arrival time
— Service time by host/hostess
— Service time by waiter/waitress
— Service time by cook
— Service time by cashier
16
Outline
17
Components of a Simulation
▪ In DES simulation:
— The simulation is driven by events
— The simulation time advances based on sequence of events
— System state changes with events
▪ Requirements:
— Time advance algorithm
— Event scheduling
— Event processing
18
Time Advance Approaches
19
Time-Stepping Approach
▪ At any given time 𝑡, the future event list (FEL) contains all
previously scheduled future events and their associated event
times (𝑡1 , 𝑡2 , … )
21
Event-Scheduling Approach
22
List Processing
▪ Arrival event:
— For example, at time 0, the first arrival event is generated and is
scheduled on the FEL. When the clock eventually is advanced to
the time of this first arrival, a second arrival event is generated.
▪ Service completion event:
— Triggered only on the condition that a customer is present and a
server is free
▪ Stopping event, E:
— At time 0: schedule a stop simulation event at a specified future
time TE
— Run length TE is determined by the simulation itself. Generally,
TE is the time of occurrence of some specified event E (e.g.,
completion of 1000th customer) or condition (e.g., relative
change in estimate of π, or standard deviation of queue size)
24
Outline
25
Example 3: Grocery Store
Customer being
checked out
Customers waiting
in checkout line
26
Components of Grocery Store Example
▪ Model components:
— System state:
▪ 𝐿𝑄 𝑡 : # of customers waiting in line at time 𝑡 (excluding the
customer being checked out)
▪ 𝐿𝑆 𝑡 : # of customer being checked out (1 or 0) at time 𝑡
— Entities: the server and customers are not explicitly modeled,
except in terms of the state variables
— Events: arrival (A), departure (D), stopping event (E)
— Event notices (event type, event time):
▪ (A, 𝑡) representing an arrival event to occur at future time 𝑡
▪ (D, 𝑡) representing a customer departure at future time 𝑡
▪ (E, 60) representing the simulation stop event at future time 60
— Activities: inter-arrival time and service time
— Delay: customer time spent in waiting line
27
Arrivals in Grocery Store Example
28
Departures in Grocery Store Example
29
Scenario 1 in Grocery Store Example
30
Event Summary for Grocery Store Example
Simulation Table
31
Manual vs. Computer Simulation
32
Scenario 2 in Grocery Store Example
33
Statistics for Grocery Store Example
Collected Statistics:
34
Computing Statistics for Grocery Store Example
Updating Statistics:
▪ At time 18, when the departure event (D, 18, C3) is being
executed, the response time for customer C3 is computed as:
Response time = clock time - attribute ‘time of arrival’
= 18 -14 = 4 minutes
35
Summary Table for Grocery Store Example
▪ Input parameters:
Interarrival Times 0 8 6 1 8
Service Times 4 1 4 3 5
14 0 1 (C3, 14) (A, 15, C4), (D, 18, C3), (E, 60) 5 2 1
15 1 1 (C3, 14), (C4, 15) (D, 18, C3), (A, 23, C5), (E, 60) 5 2 1
18 0 1 (C4, 15) (D, 21, C4), (A, 23, C5), (E, 60) 9 3 2
36
Simulation Table
Outline
37
Generic Simulation Program (1 of 4)
▪ Initialization
— Initialize clock to zero
— Initialize state variables and
statistical counters
— Initialize event list (with already
known future events)
38
Generic Simulation Program (2 of 4)
39
Generic Simulation Program (3 of 4)
40
Generic Simulation Program (4 of 4)
▪ Report generator
— Invoked when simulation has terminated
— Compute and output performance measures
of interest
41
Simulation of Queueing Systems
42
Components of a Queueing System
5. Service
discipline
4. Waiting
positions 3. Number of
servers
43
Arrival Definition
▪ Arrival time
— Time at which a customer arrives at a service facility
▪ Inter-arrival time
— Time between two successive arrivals to a service facility
▪ Arrival rate
— Number of arrivals per unit of time
44
Timing Diagram
45
Relationship between Arrival Rate and Inter-arrival Time
▪ Define:
L nj1 y j
L
▪ Mean inter-arrival time
n
n 1
▪ Arrival rate
L mean interarrival time
46
Service Definition
service requirement
▪ Service time =
server capacity
▪ Service rate
— Number of customers served per second
(assuming no idle time)
47
Timing Diagram
48
Relationship between Service Rate and Service Time
▪ Define:
L nj1 x j
L
▪ Mean service time
n
n 1
▪ Service rate
L mean service time
49
Service Disciplines
Examples:
▪ First-Come-First-Serve (FCFS) (a.k.a. FIFO)
▪ Last-Come-First-Serve (LCFS)
▪ Round-Robin (RR) with a fixed quantum
Infinitesimal quantum Processor Sharing (PS)
▪ Shortest Job First (SJF)
▪ Shortest Remaining Processing Time (SRPT)
▪ And many more…
50
Typical Performance Measures
▪ Response time
— Elapsed time from arrival to departure
▪ Waiting time
— Time spent in queue
▪ Number of customers in system
▪ Number of customers in queue
▪ Server utilization
— Proportion of time that the server is busy
▪ Throughput
— Rate at which customers leave the service facility after
completing service
51
Utilization
s1 s2 s3 s4 sn
•••
Time
0 L
n
— Total busy time = sj
j 1
1 n
— U = proportion of time server is busy =
L
s
j 1 j
Note: U ≤ 1
52
Throughput
53
Single Server Queue Example (ssq3.c)
54
Customer Arrivals - Infinite Population Model
55
Single Server Queue Example
time
56
Single Server Queue Model
▪ Assumptions
— Inter-arrival times are independent of system state
— Inter-arrival times are iid (independent and identically
distributed)
— Service times are independent of system state
— Service times are iid
— FCFS scheduling
— System is empty at time zero
— Arrival of first customer occurs after the first inter-arrival
time
— Simulation terminates when the m-th customer starts
service
57
Single Server Queue Model
▪ Input parameters
— Inter-arrival time distribution (e.g., exponential)
— Service time distribution (e.g., uniform)
58
Single Server Queue Model
▪ State variables
— status = server status (busy or idle)
— n = number of customers in system
▪ Statistical counters
— nw = number of waiting times accumulated
— sw = sum of accumulated waiting times
— sa = sum of accumulated areas (for calculating 𝑛)
ത
— last_event = time of last event when accumulating
area
59
Single Server Queue Model
▪ Lists
— event_list
— queue
▪ Event types
— type 1: arrival
— type 2: start_service
— type 3: departure
60
Single Server Queue Model (1 of 4)
▪ Initialization
— clock = 0
— status = idle
—n = 0
— nw = sw = 0
— last_event = 0
— sa = 0
— Initialize queue to empty
— Initialize event_list to empty
— Determine inter_t, the first interarrival time
— Schedule an arrival event to occur at clock +
inter_t
61
Single Server Queue Model (2 of 4)
62
Single Server Queue Model (3a of 4)
63
Single Server Queue Model (3b of 4)
64
Single Server Queue Model (3c of 4)
65
Single Server Queue Model (4 of 4)
▪ Report generator
ഥ = sw/nw
— Mean waiting time: 𝑤
ത = sa/clock
— Mean no. of customers in system: 𝑛
— Output results
66
Sequence of Events
C1 C2 C3
departures
server
C1 C2 C3 C4 start service
queue
0 1 3 4 6 9 10 11
arrival
C1 C2 C3 C4
Cj - customer j
time
number of 2
customers
in system 1
0 1 3 4 6 9 10 11
time 67
Manual Trace of Single Server Queue Example
clock event status n event list queue nw sw
69
Finite Population Model
70
Finite Population Model
71
Finite Population Model
▪ Assumptions
— Service times are iid and independent of system state
— Think times are iid and independent of system state
— FCFS scheduling
— System is empty at time zero
— For each of the N users, the first request is submitted after a
think time
— Subsequent arrivals depend upon prior service completions
— Simulation terminates at time term_sim
72
Finite Population Model
▪ Initialization
— clock = 0
— status = idle
—n = 0
— Initialize queue to empty
— Initialize event_list to empty
— for user j (j = 1 to N)
Determine think_t, a think time of user j,
and schedule an arrival event at clock + think_t
end for
— Schedule an end_simulation event at term_sim
73
Finite Population Model
▪ arrival event
—n = n + 1
— Enter arriving customer to end of queue
— If status is idle, invoke routine for start_service
event
▪ start_service event
— Remove customer from front of queue
— status = busy
— Determine serv_t, the service time of customer
— Schedule a departure event to occur at clock +
serv_t
74
Finite Population Model
▪ departure event
—n = n - 1
— status = idle
— Determine think_t
— Schedule an arrival event at clock + think_t
— If n > 0, invoke event routine for start_service
▪ end-simulation event
— exit main loop
75
Example: Tandem Queue – M Stages
76
Simulation Program
77
Example: Tandem Queue with Blocking
78
Tandem Queue with Blocking
▪ Two stages
▪ Finite waiting room at stage 2 (number of customers
in system < K)
▪ Blocking
— Server 1 is blocked if a customer completing service at
stage 1 finds no queuing space at stage 2
79
Tandem Queue with Blocking
80
Simulation Program
81
Simulation Program
▪ Modifications (cont.):
— start_service event at stage 1: add the step
▪ Schedule an end_service event at stage 1
instead of a departure event at stage 1
— end_service event at stage 1: add the step
▪ If number in system at stage 2 < K
invoke routine for departure event at
stage 1
▪ else b = 1
82
Simulation Program
▪ Modifications (cont.):
— departure event at stage 1: add the step
▪ Invoke routine for arrival event at stage
2
— arrival event at stage 2:
▪ Do not schedule the next arrival event
— departure event at stage 2: add the step
▪ If b = 1, then b = 0 and invoke routine
for departure event at stage 1
83
Example: Closed Network Model
84
Subsystems and Interaction
85
Simulation Program
86
Simulation Program
87
Outline
88
Verification and Validation
Abstraction = Simulation
System Model
Program
Validation Verification
89
Verification
90
Fundamental Results
91
Analytic Results
92
Validation
93
Three Step Approach to Validation
94
Three Step Approach to Validation
Input Data
(from system Model Output Data
measurement) (from model)
=?
Output Data
(from system
measurement)