0% found this document useful (0 votes)
30 views

02 - SYSC4005 - Simulation Examples

Uploaded by

Macaulay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

02 - SYSC4005 - Simulation Examples

Uploaded by

Macaulay
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Simulation Examples

SYSC 4005/5001W
Discrete Simulation/Modeling
Winter 2024

1
Introduction

• This chapter presents several examples of simulations that can be


performed by devising a simulation table either manually or with a
spreadsheet.
• The simulation table provides a systematic method for tracking system
state over time.
• These examples provide insight into the methodology of discrete-system
simulation and the descriptive statistics used for predicting system
performance.
• This chapter gives a number of simulation examples in queueing,
inventory, reliability, and network analysis.

2
Simulation Steps

Step 1. Determine the characteristics of each


of the inputs of the simulation (modeled as
probability distributions)

Step 2. Construct a simulation table


In this example, there are 𝑝𝑝 inputs and one
response 𝑦𝑦𝑖𝑖 . The simulation has 𝑛𝑛 reptations
Step 3. For each repetition, generate inputs (trials). For each repetition 𝑖𝑖, input values
and calculate the output. Examples: activity are computed by sampling values from the
times, random variables, system state, event, distributions chosen in Step 1.
clock tick, model output, model response.

3
Simulation of Queueing Systems (1/4)
• A queueing system is described by its calling population, the nature of
the arrivals, the service mechanism, the system capacity, and the
queueing discipline.
• The members of the calling population may be, for example, customers,
telephone calls, or jobs in a repair shop; here, we refer to them as units.

4
Simulation of Queueing Systems (2/4)
• Assumptions: unlimited potential calling population and a constant
arrival rate.
• no matter how many units have already arrived or are still present in
the system, the interarrival time until the next arrival follows the same
statistical distribution.
• Arrivals for service occur one at a time in a random fashion; once they
join the waiting line, they are eventually served.
• Service times are of some random length according to a probability
distribution which does not change over time.
• The system capacity has no limit, any number of units can wait in line.

5
Simulation of Queueing Systems (3/4)

• Units are served in the order of their arrival (FIFO/FCFS) by a single


server or multiple parallel servers.
• Services and arrivals are defined by the distribution of service times and
the distribution of time between arrivals, respectively.
• For any simple single- or multi-channel queue, the overall effective arrival
rate must be less than the total service rate, or the waiting line will grow
without bound (termed explosive or unstable.)
• More complex situations can occur—for example, arrival rates that are
greater than service rates for short periods of time, or networks of
queues with routing.

6
Simulation of Queueing Systems (4/4)

• System state consist of:


• the number of units in the system, and
• the server status, either busy or idle.
• An Event: is a set of circumstances that causes an instantaneous change
in the state of the system. In a single-channel (or any multi-channel)
queueing system, the events are:
• the arrival event,
• the service beginning event, and
• the departure event, also called the service completion event.
• The simulation clock is used to track simulated time.

7
Simulation of Queueing Systems
Departure Event

• Departure event causes a


change in system state.
• If no more units waiting in the
queue  server becomes
idle.
• If there are unit(s) waiting 
next service begins.
• In both cases, number of units
in the system decreases by
one.

8
Simulation of Queueing Systems
Arrival Event

• The unit finds the server


either idle or busy; therefore,
• either the unit begins
service immediately, or
• it enters the queue.

9
Simulation of Queueing Systems

Server outcomes after the completion


Potential unit actions upon arrival of service

10
Simulated Clock

• Simulations of queueing systems require the maintenance of an event list


for determining what happens next.
• This list tracks the future times at which the different types of events
will occur.
• The simulation is simplified (only in these examples) by tracking each
unit explicitly.
• this ad hoc approach is satisfactory for simple simulations in a
spreadsheet,
• more systematic approach is essential for the more complex real-
world simulations.

11
Random Numbers

• In simulation, events usually occur at random times, the randomness


imitating uncertainty in real life.
• The randomness needed to imitate real life is made possible through
using “Random Numbers”
• Random numbers are distributed uniformly and independently on the
interval (0, 1).
• Random numbers are made of random digits, which are uniformly
distributed on the set {0, 1, 2, … , 9}, by selecting the proper number of
digits for each random number and placing a decimal point to the left of
the value selected.
• The number of digits is dictated by the required accuracy.

12
Random Numbers
• Random numbers can be taken from random digits table, or can be
generated in simulation packages and in spreadsheets (such as Excel).
• E.g., Excel has a macro function called RAND() that returns a
"random" number between 0 and 1.
• When numbers are generated by using a procedure, they are often
referred to as Pseudo-Random Numbers (PRNs).
• Because the procedure is fully
known, it is always possible to
predict the sequence of
numbers that will be generated
prior to the simulation.

13
Single Channel Queue – Interarrival Times

• In a single-channel queueing
simulation, interarrival times and
service times are generated from
the distributions of these random
variables.
• For simplicity, assume that the
times between arrivals were
generated by rolling a dice (die)
five times and recording the up These five interarrival times are used to
face. This table contains a set of compute the arrival times of six customers at
five inter-arrival times generated the queueing system
in this manner.

14
Single Channel Queue – Service Times

• The second time of interest is the service time.


• This table contains service times generated at
random from a distribution of service times.
• The only possible service times are 1, 2, 3,
and 4 time units, all four values are equally
likely to occur.
• These RNs are generated by placing the
numbers 1 to 4 on chips and drawing the chips
from a hat with replacement, being sure to
record the numbers selected.

15
Single Channel Queue – Simulation Table

• Now, the interarrival times


and service times must be
meshed (stitched) to
simulate the single-
channel queueing system
• This table was designed
specifically for a single-
channel queue that serves
customers on FIFO basis.
The clock time of The clock time of
each arrival event each departure event

16
Chronological Ordering of Events

• This table is ordered by clock


time, in which case the events
may or may not be ordered by
customer number.
• The chronological ordering of
events (event list) is the basis of
the approach to discrete-event
simulation.

17
Number of Customers in the System

18
Example
• A small grocery store has one checkout counter.
• Customers arrive at the checkout counter at random times from 1 to 8
minutes apart, interarrival times are integer-valued with each of the 8
values having equal probability; this is a discrete uniform distribution
• The service times vary from 1 to 6 minutes (also integer-valued), with the
probabilities 0.1, 0.2, 0.3, 0.25, 0.10, 0.05, respectively.
• Our objective is to analyze the system by simulating the arrival and
service of 100 customers and to compute a variety of typical measures of
performance for queueing models.
• 100 customers is too small for good analysis.

19
Example
Interarrival Times • A set of uniformly distributed between 0
and 1 RNs is needed to generate the
arrivals at the checkout counter.
Successive RNs are independent.
• 99 RNs is needed. Three-place RNs will
suffice. (Table A.1)
• There are 1000 three-digit values possible
(001 through 000).
• The third column is the cumulative
probability for the distribution.

Distribution of Time Between Arrivals • The probability of a time-between-arrival


of 1 min is 0.125  125 of the 1000
Average Interarrival Time = (1+8)�2 = random digit values are assigned to such
4.5 minutes an occurrence.

20
Example
• A set of uniformly distributed between 0
Service Time and 1 RNs is needed to generate the
arrivals at the checkout counter.
Successive RNs are independent.
• 99 RNs is needed. Two-place RNs will
suffice. (Table A.1)
• There are 100 three-digit values
possible (01 through 00).
• The third column is the cumulative
probability for the distribution.
Service Time Distribution • The probability of a service time of 1
Average Service Time = ∑6𝑖𝑖=1 𝑠𝑠𝑖𝑖 𝑝𝑝(𝑠𝑠𝑖𝑖 ) = 4.5 min is 0.10  10 of the 100 random
digit values are assigned to such an
minutes
occurrence.

21
Interarrival Time Generation

22
Service Time Generation

Service times are generated using the


same methodology.

23
The Simulation Table
• Columns are added to
answer questions posed.
• All rows are based on the
random numbers for
interarrival and service
times and the completion
time of the previous
customer
• The rightmost columns have
been added to collect
statistical measures of
performance (each
customer’s time in system
and the server’s idle time).
24
Example Results

total time customers wait in queue


• Average waiting time (minute) = =
174
total number of customers
100
= 1.74 minutes

number of customers who wait 46


• Probability (wait) = total number of customers = 100
= 0.46

total idle time of server (minutes) 101


• Probability of idle server =
total run time of simulation (minutes) = 418
=
0.24

25
Example Results
total service time (minutes) 317
• Average service time (minute) =
total number of customers = 100
=
3.17 minutes

This can be compared with the expected service time by finding the
mean of the service-time distribution

𝐸𝐸 𝑆𝑆 = ∑∞
𝑠𝑠=0 𝑠𝑠𝑠𝑠 𝑠𝑠 = 1 0.10 + 2 0.20 + 3 0.30 + 4 0.25 + 5 0.10 +
6 0.05 = 3.2 minutes

• Slightly higher than that of the simulation.

• The longer the simulation, the closer the average will be to 𝐸𝐸 𝑆𝑆 .

26
Example Results
• Average time between arrivals (minute) =

sum of all times between arrival (minutes) 415


= = 4.19 minutes
number of arrivals − 1 99

• This can be compared with the expected time between arrivals by finding
the mean of the discreet uniform distribution whose endpoints are 𝑎𝑎 =
1 and 𝑏𝑏 = 8.
𝑎𝑎+𝑏𝑏 1+8
𝐸𝐸 𝐴𝐴 = 𝑠𝑠
= 2
= 4.5 minutes

• Slightly higher than that of the simulation. The longer the simulation, the
closer the average will be to 𝐸𝐸 𝐴𝐴 .

27
Example Results

• Average waiting time of those who wait (minute) =

total time customers wait in queue (minutes) 174


= = 3.22 minutes
total number of customers that wait 54

• Average time customer spends in the system (minute) =

total time customers spend in the system (minutes) 491


= = 4.91 minutes
total number of customers 100

28
Waiting Time Distribution

• Waiting time in queue for the


first trail of 100 customers is
shown in this histogram.
• 46% of customers did not
have to wait.
• 42% waited less than four
minutes (but more than 0
minutes)

29
Simulating a Queue with Two Servers
The Able-Baker Call Center Problem
• A computer technical support
center is staffed by two people,
Able and Baker, who take calls
and try to answer questions and
solve computer problems. The
time between calls ranges from
1 to 4 minutes, with distribution
as shown in the Table.
• Able is more experienced and
can provide service faster than
Baker. The distributions of their
service times are shown in the
tables.
30
Simulating a Queue with Two Servers
The Able-Baker Call Center Problem

The workbook provides a detailed explanation of the simulation steps, including the
underlying logic (formulas) for computing each step.

31
Simulating a Queue with Two Servers
The Able-Baker Call Center Problem

Using the interarrival and service


times distributions/tables.

32
Simulating a Queue with Two Servers
The Able-Baker Call Center Problem

• The frequency chart shows that the


caller delay distribution often has a
long, thin tail to the right.
• One trial does not provide sufficient
data on which to form reliable
conclusions.
• When repeating the simulation, the
effect of variability will be quietly
evident.

33
Simulating a Queue with Two Servers
The Able-Baker Call Center Problem

• How does average caller delay


(for the first 100 customers)
vary from day to day?
• We set the “Number of
Trials” to 400 (representing
400 days). The resulting
distribution of average caller
delay is shown in the
histogram.

34
Inventory Simulation An order quantity, Q1, is placed
to bring the inventory level
up to 𝑀𝑀.
• The inventory system shown is called
an (𝑀𝑀, 𝑁𝑁) system:
• an inventory review every 𝑁𝑁 time
periods, maximum inventory level
𝑀𝑀
• at each 𝑁𝑁 time units, the inventory
level is checked and an order is
made to bring the inventory up to
the level 𝑀𝑀.
• For simplicity, the lead time is shown
as zero (in reality, it is modeled as a Shortage.
random variable.)

35
Inventory Simulation

• Demands are not usually known with certainty, so the order quantities are
modeled by a probability distribution.
• In the example graph, demand is shown as being uniform over the
time period.
• In the second cycle, the amount in inventory drops below zero, indicating
a shortage. These units are backordered; when the order arrives, the
demand for the backordered items is satisfied first.
• To avoid shortages, a buffer, or safety, stock would need to be carried.
• In some inventory systems, a portion of sales may be lost rather than
backordered when inventory runs out.

36
Inventory Simulation

• Inventory systems have a number of potential sources of revenue and


costs:
1. Revenue from sales;
2. Cost of items sold;
3. Carrying cost, the cost of carrying stock in inventory;
4. Ordering cost, the cost associated with placing orders;
5. Cost of lost sales or backorders;
6. Cost due to scrap;
7. Salvage revenue from scrap or other damaged goods.

37
Inventory Simulation
• The total cost (or total profit) of an inventory system is the measure of
performance, can be affected by the policy alternatives
• the decision maker can control 𝑀𝑀 and 𝑁𝑁.
• Inventory systems have a number of parameters, some controllable and
some not.
• The controllable variables are the decision or policy variables. For each
item in inventory, these include:
1. The maximum inventory level, 𝑀𝑀
2. The review period, 𝑁𝑁
3. The order quantity (for replenishment), 𝑄𝑄
4. Lead time for replenishment, 𝐿𝐿

38
Inventory Simulation

• In a model of an (𝑀𝑀, 𝑁𝑁) inventory system, the events that may occur are
1. the demand for items in the inventory,
2. the review of the inventory position and resulting decision to place a
replenishment order, and
3. the arrival of replenishment stock.
• When the lead time is assumed to be zero, events 1 & 2 occur at the
same time.

39
Simulating the News Dealer’s Problem
• In this example, a news dealer must decide how many newspapers to
buy. In this and similar problems, only a single time period of specified
length is relevant, and only a single procurement is made.
• Inventory remaining at the end of the single time period is sold for
scrap, discarded or recycled.
• The dealer buys papers for 33 cents each and sells them for 50 cents
each. Newspapers not sold at the end of the day are sold as scrap for 5
cents each. Newspapers can be purchased in bundles of 10. Thus, the
newsstand can buy 50 or 60 or 70 papers, and so on. The order quantity,
𝑄𝑄, is the only policy decision.
• Unlike some inventory problems, the order quantity 𝑄𝑄 is fixed since
ending inventory is always zero due to scrapping leftover papers.

40
Simulating the News Dealer’s Problem

Distribution of Daily Newspaper Demand, by Distribution of Type of


Type of Newsday Newsday

The news dealer cannot


predict which type will occur
on any given day.

41
Simulating the News Dealer’s Problem

• Our objective is to compute the optimal number of papers the newsstand


should purchase, 𝑄𝑄.
• This will be accomplished by simulating demands for 20 days and
recording profits from sales each day for a given order quantity.
• After a trial is completed, total profit is calculated.

42
Simulating the News Dealer’s Problem
Simulation Table for Purchase
of 70 Newspapers

• The profit for the 20-day


period is the sum of the daily
profits, $114.70

43
Simulating the News Dealer’s Problem

• The results of an experiment


with 400 trials or replications
for the order policy of ordering
70 newspapers (each trial
being a 20-day simulation run)
are shown in this histogram.

44
Simulating the News Dealer’s Problem
Results Analysis
• The average total (20-day) profit was $135.49 (averaged over the 400
trials).
• The minimum 20-day profit was $86.60 and the maximum was $198.00
• The figure shows that only 38 of the 400 trials resulted in a total 20-day
profit of more than $160.
• The single trial had a profit of $114.70, which is on the low side of the
distribution in the histogram figure. This shows that
• the result for one 20-day trial may not be representative of long-term
performance, and
• it is necessary to simulate many trials as well as conduct a careful
statistical analysis before drawing conclusions.

45
Questions?

46

You might also like