0% found this document useful (0 votes)
33 views43 pages

Chapter Two-Simulation Examples

Uploaded by

amirmm71382
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views43 pages

Chapter Two-Simulation Examples

Uploaded by

amirmm71382
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Computer Simulation

Dr. Bardia Safaei

Chapter Two: Simulation Examples

1
Steps Required for a Successful Simulation

n Three stages of simulations:


¨ Determining the characteristics of the inputs
n Typically, inputs are modeled as probability distributions
¨ Either continuous or discrete
¨ Constructing a simulation table
n Based on the problem at hand, different simulation tables could be
developed
¨ For every repetition i:
n Generate a value for each of the p inputs, and evaluate the function,
which gives the value of the response Y!
¨ The input values may be computed by sampling values from the
distributions determined in stage 1

n A response typically depends on the inputs and one or


more previous responses
Reliable and Durable IoT Applications & Networks
RADIAN Research Laboratory 2
Dr. Bardia Safaei
Simulation Table

n Simulation table is a representation tool for monitoring


the simulated system during the simulation period
n It mainly contains:
¨ Round of replication i
¨ Inputs X!"
¨ Outputs (or response) Y!

Inputs Response
Repetitions Xi1 Xi2 … Xij … Xip yi

1
2
··
·
n

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 3
Dr. Bardia Safaei
Simulation of Queuing Systems

n Why Queues?
¨ Queues are the best known model for discrete systems
¨ We do not have a queue-less system
n A queuing system is described by:
¨ Its calling population
¨ The nature of the arrival
n Indicated with rate of arrival
¨ The service mechanism
n Includes rate of service, number of servers, servers configuration
¨ The system capacity
n Number of customers can wait + Number of customers can get service
¨ The queuing discipline
n How the customers are selected for getting service
¨ Example: First come, First serve (FIFO)

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 4
Dr. Bardia Safaei
Servers Configuration (1)

n Based on the number of service phases, and service


channels we have 4 types of configurations:
¨ Single-channel/Single-phase system

¨ Single-channel/Multi-phase system

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 5
Dr. Bardia Safaei
Servers Configuration (2)

n Based on the number of service phases, and service


channels we have 4 types of configurations:
¨ Multi-channel/Single-phase system

¨ Multi-channel/Multi-phase system

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 6
Dr. Bardia Safaei
Single-channel Queue Assumptions (1)

n The calling population is infinite


¨ If a customer leaves the calling population and joins the waiting
line or enters service, there is no change in the arrival rate of
other customers that may join the queue
¨ This simplifies our study and reduces calculations
n Arrivals for service occur in a random fashion
n Once a customer joins the waiting line, it will be
eventually served (If we have self-service process)
n Service times are of some random length according to a
probability distribution
¨ Which does not change over time

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 7
Dr. Bardia Safaei
Single-channel Queue Assumptions (2)

n The system capacity has no limit


¨ Meaning that any number of customers can wait in the line
n Customers are served in the order of their arrival
¨ Often called FIFO: First In, First Out
¨ By a single server or channel
n Arrivals are defined by the distribution of the time
between arrivals
¨ Interarrival time
n Inverse of arrival rate
n Services are defined by the distribution of service times

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 8
Dr. Bardia Safaei
Single-channel Queue Assumptions (3)

n For any simple single (or multi) channel queue, the


overall effective arrival rate must be less than the total
service rate
¨ Otherwise, the waiting line will grow without bound
¨ System turns into unstable state
n In some systems, the condition about arrival rate being
less than service rate may not guarantee stability
¨ Other factors are also involved

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 9
Dr. Bardia Safaei
Simulation of Queuing Systems (1)

n System state in our simple queue model is the number of


units in the system along with the status of the server
¨ Status of the server could be busy or idle
n Recall:
¨ Event is a set of circumstances that cause an instantaneous
change in the state of the system
n In a single-channel queuing system there are only two
possible events that can affect the state of the system:
n Arrival event: the entry of a unit into the system
n Departure event: the completion of service on a unit
n An important element in simulations is the clock
¨ Clock is used to monitor the system during the simulation period

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 10
Dr. Bardia Safaei
Simulation of Queuing Systems (2)

n The arrival event occurs when a unit enters the system


n The unit may find the server either idle or busy
¨ Idle: the unit begins service immediately
¨ Busy: the unit enters the queue for the server

Arrival
Event

Unit enters No Server Yes Unit enters queue


service busy? for service

Unit entering the system flow diagram

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 11
Dr. Bardia Safaei
Simulation of Queuing Systems (3)

n If a unit has just completed service


¨ The simulation proceeds in the manner shown in the flowing
diagram
n Note that we have assumed that the server has only two
possible states
¨ It is either busy or idle
Departure
n In other cases, the
Event
flow would be different

No Another unit Yes Remove the


Begin server idle time waiting unit from
waiting?
the queue

Service just completed flow diagram Begin servicing the unit

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 12
Dr. Bardia Safaei
Simulation of Queuing Systems (4)

n Based on the Potential unit actions upon arrival

queue and
server status,
the following
system states
are expected at
the instance a
unit enters or Server outcomes after service completion
leaves the
system

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 13
Dr. Bardia Safaei
Simulation of Queuing Systems (4)

n Simulation of queuing systems generally requires an event list


¨ To determine what will happen next
n Simulation clock is used to determine the exact times of arrival
and departure events
¨ Exact times are calculated based on interarrival and service times
n Events usually occur at random times
¨ Randomness provides uncertainty as in real life
¨ Random numbers are distributed uniformly and independently on the
interval (0,1)
¨ One simple approach for generating random numbers is to randomly
select digits, which are uniformly distributed on the set {0, 1, 2, … ,
9}, and concatenate them
n The proper number of digits is dictated by the accuracy of the data being
used for input purposes

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 14
Dr. Bardia Safaei
Simulation of Queuing Systems (5)

n Pseudo-random numbers should be generated using a


procedure
¨ Detailed in Chapters 6 and 7
¨ What is the difference between true and pseudo random number?
n Consider a shop, where 6 customers arrive randomly
¨ Assume that the Interarrival times for customers are generated
by rolling a die five times and recording the up face

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 15
Dr. Bardia Safaei
Simulation of Queuing Systems (6)

n Assume that there are four possible values for Service


Times ∈ {1,2,3,4}
¨ All have equal probabilities to occur
¨ These values could have been generated by writing down the
numbers on chips and drawing the chips from a hat with
replacement
n Be sure to record the numbers selected J

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 16
Dr. Bardia Safaei
Simulation of Queuing Systems (7)

n In order to analyze our simulated single-channel queuing


system, the interarrival times and service times must be
integrated
¨ Two previous tables must be merged
n The following table is specifically designed for a single-
channel queue, which serves customers based on FIFO
n Events are indicated based on the clock time

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 17
Dr. Bardia Safaei
Simulation of Queuing Systems (8)

n Event table:
¨ Unlike simulation table, entries are chronically ordered based on
the occurrence of events (not the customers)
¨ Occurrence of two types of events (arrival and departure) in their
chronological order is shown in the following table
¨ Based on this table, the number of customers in every instance of
time could be represented as in the figure

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 18
Dr. Bardia Safaei
Simulation of Queuing in a Grocery Store (1)

n Assumptions in this example:


¨ Only one checkout counter (only one server)
¨ Customers arrive at this checkout counter at random from 1 to 8
minutes apart
¨ Each possible value of interarrival time has the same probability
of occurrence, as shown in the next slide
¨ The service times vary from 1 to 6 minutes with different
probabilities shown in the next slide
Arrival Departure
n The problem is to analyze
the system by simulating the
arrival and service of 20
customers Checkout Counter

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 19
Dr. Bardia Safaei
Simulation of Queuing in a Grocery Store (2)

n The distribution of interarrival and service times are


shown below
¨ Based on the probability distribution, and their cumulation, the
two following issues would be determined:
n The precision required for random number generation
¨ Number of decimal points
n An interval for selecting a specific value for interarrival or service time

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 20
Dr. Bardia Safaei
Simulation of Queuing in a Grocery Store (3)

n Simulating a grocery store that starts with an empty system is


not realistic
¨ Unless, the goal is to model the system from startup until the steady-
state
n Based on the required accuracy for interarrival and
service times, we must generate a random number
¨ In order to determine the value of interarrival and service time
parameters for every customer, we must match the generated
numbers with the intervals
The rightmost two columns
n

¨ Random numbers have the following properties:


n They are uniformly distributed between 0 and 1
n Successive random numbers are independent
¨ Use RAND() function in Excel or rand function in Matlab

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 21
Dr. Bardia Safaei
Simulation of Queuing in a Grocery Store (4)

n Example: Determining an interarrival time for the 2nd


customer
¨ Since there were 8 values for interarrival times with uniform
distribution, each will have 0.125 probability
n Cumulation of these values and turning them into integer intervals
requires three point decimal precision for the random number
¨ The generated number will be then multiplied by 1000

¨ Assume that the first


random digits is 913
n To obtain the
corresponding interarrival
time, enter the fourth
column of the table and
read 8 minutes from the
first column of the table
Reliable and Durable IoT Applications & Networks
RADIAN Research Laboratory 22
Dr. Bardia Safaei
Simulation of Queuing in a Grocery Store (5)

n Determining the service time:


¨ Unlike interarrival time, service time is also specified for the 1st
customer
¨ In the following table, the first customer's service time is 4
minutes, because the generated random digits 84 fall in the range
61-85

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 23
Dr. Bardia Safaei
Simulation of Queuing in a Grocery Store (6)

n As we observed, the fundamental tool for a manual simulation


is the simulation table
n One of the most important reasons for using a simulation table
is to obtain statistical measures of performance for the
intended system
n Statistical measures of performance in this example are:
¨ Every customer’s spent time in the system
¨ The server's idle time
n In order to compute the required statistics, totals are formed
as shown in the next table
n These totals are calculated for:
¨ Service times
¨ Time customers spend in the system
¨ Idle time of the server
¨ Customers waiting time in the queue
Reliable and Durable IoT Applications & Networks
RADIAN Research Laboratory 24
Dr. Bardia Safaei
Simulation of Queuing in a Grocery Store (7)

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 25
Dr. Bardia Safaei
Performance Analysis of Grocery Store (1)

n Based on the achieved totals, the statistical performance


measures could be calculated for analysis:
¨ The average waiting time for a customer (minutes):
Total time customers wait in Queue 56
Average waiting time = = = 2.8 minute
Total number of customers 20

¨ The probability that a customer has to wait in the queue:


Number of customers who wait 13
Waiting probability = = = 0.65
Total number of customers 20

¨ The percentage of idle time for the server:


Total idle time of server 18
Probability of idle server = = = 0.21
Total run (time of simulation) 86
¨ The probability of the server being busy:
Probability of busy server = 1 − idle probability = 1 − 0.21 = 0.79

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 26
Dr. Bardia Safaei
Performance Analysis of Grocery Store (2)

n Calculations (cont’d):
¨ The average (mean) service time (minute):
𝑇𝑜𝑡𝑎𝑙 𝑠𝑒𝑟𝑣𝑖𝑐𝑒 𝑡𝑖𝑚𝑒 68
𝐴𝑣𝑒𝑟𝑎𝑔𝑒 𝑠𝑒𝑟𝑣𝑖𝑐𝑒 𝑡𝑖𝑚𝑒 = = = 3.4 minute
𝑇𝑜𝑡𝑎𝑙 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑐𝑢𝑠𝑡𝑜𝑚𝑒𝑟𝑠 20
¨ Note: we could have calculated the average service time without
using the simulation table
n It could be obtained by using the probability distribution table for
service time, and the expected value equation
$
Expected Value = E(S) = b S×P(S) [Eq. 1]
!"#
= 1 0.10 + 2 0.20 + 3 0.30 + 4 0.25 + 5 1.10 + 6 0.05 = 3.2 minute

n The expected service time is slightly lower than the average service
time in the simulation
¨ The longer the simulation, the closer the average will be to

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 27
Dr. Bardia Safaei
Performance Analysis of Grocery Store (3)

n Calculations (cont’d):
¨ The average of interarrival times (minute):
Sum of interrrivals 82
Average of interarrival times = = = 4.3 minute
Number of customers − 1 19
¨ This result can be compared to the expected time for the
uniformly distributed interarrivals
n This could be calculated by finding the mean of the discrete
uniform distribution whose endpoints are a=1 and b=8
a+b 1+8
E A = = = 4.5 minute
2 2
n Again, the longer the simulation, the closer the average will be
¨ The average waiting time of those who wait:
Total time customers wait in queue 56
Average waiting time of those who wait = = = 4.3 minute
Total numbers of customers who wait 13

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 28
Dr. Bardia Safaei
Performance Analysis of Grocery Store (4)

n Calculations (cont’d):
¨ The average time a customer spends in the system:
Total time customers spend in the system
Average time customers spends in the system =
Total number of customers
124
= = 6.2 minute
20

¨ As it could be seen:
Average time Average time Average time
customer spends = customer spends + customer spends
in the system waiting in the for getting service
queue

n Average time a customer spends in the system = 2.8 + 3.4 = 6.2


minute

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 29
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (1)

n In fast food restaurants, a drive-in facility has been


considered
¨ Customers can order and receive their food while driving
¨ The person who gets the job done is called carhop
n In our example, two carhops are employed for both
receiving orders, payment, and delivery simultaneously
¨ Hence, the system is two-channel/single-phase
¨ But the system could have been more complicated if the drivers
had to order in one window, and get their food in another window,
a few meters ahead
n The system would be two-channel/two-phase

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 30
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (1)

n Assumptions:
¨ Customers (cars) arrive in the manner shown in next slide
¨ Our carhops have different attributes:
n Able does the job a little bit faster than Baker
n The distribution of their service times is shown in the next slide
¨ There would be two different tables
Able

2 Servers (channels)

Baker

A drive-in restaurant where carhops take orders and bring food to the car
Reliable and Durable IoT Applications & Networks
RADIAN Research Laboratory 31
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (2)

n Tables for interarrivals and service times are illustrated


below
n Rules of the problem:
¨ If both carhops are idle, Able
gets the customer
¨ If both are busy, the customer
begins service with the first
server to become free
¨ To analyze the system
performance, a 1-hour period
simulation is conducted
¨ The problem is to find how well
the current arrangement is
working?
Reliable and Durable IoT Applications & Networks
RADIAN Research Laboratory 32
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (3)

n Manual simulation data has been recorded as follows:

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 33
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (4)

n In many cases, the pen & paper technique for obtaining


the simulation table is infeasible
¨ Especially when the number of customers and events is high and
the configuration of the system is complicated
n It takes significant time to generate the table L
¨ Solution: Excel or Matlab
n The row for the first customer is filled in manually
¨ To generate random numbers, use RAND() function in case of Excel or another
random function replacing the random digits
n After the first customer, the rows for other customers must be filled based on
logic and formulas
¨ Example: the “Clock Time of Arrival” (column D) in the row for the second customer
is computed as follows:
§ D! = D!"# + C!
¨ Add the arriving time for the previous customer, and interarrival time for the current
customer

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 34
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (4)

n It is possible to use conditional logic for the customers in


Excel
¨ We can use the macro function IF(), which returns one of two
values depending on whether a condition is true or false:
n IF (condition, value if true, value if false)
¨ This macro has three arguments:
n The condition to be checked
n The returned value in case of a true condition
n The returned value in case of a false condition

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 35
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (5)

n Simplified flowchart of the Able/Baker problem algorithm


has been illustrated below: Clock=0

Generate a random digit Is Baker Is it time for A Service


Clock++
for the service idle? arrival completed?

Convert the random digit Store clock time


into random number for
Baker service time
Is Able Generate a random digit for
idle? service

Baker service begins Convert the random digit


into random number for
Able service time
Customer enters
waiting line Able service begins

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 36
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (6)

n How to specify whether Able or Baker provides service?


¨ This is later used to calculate their busy/idle time
¨ It is necessary to find the beginning of service for a customer
n Assume customer 10
n We use the built-in Excel function for maximum over a range, MAX()

F10 = IF 'D10 > MAX H$1: H9 , D10, IF 3D10 > MAX K$1: K9 , ""
BOOK

, MIN MAX H$1: H9 , MAX K$1: K9 4(

n How the logic works?


¨ D10 is the arrival of customer 10
¨ H$1:H9 represents the finishing time of service for last customers
who got service from Able
¨ K$1:K9 represents the finishing time of service for last customers
who got service from Baker
Reliable and Durable IoT Applications & Networks
RADIAN Research Laboratory 37
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (7)

n If the first condition (Able is idle when customer 10 arrives)


is true, then the customer gets immediate service,
beginning at its arrival time in D10
n Otherwise, a second IF() function is evaluated, which says
if Baker is idle, put nothing in the cell
n Otherwise, the function returns the time that Able or Baker
becomes idle
¨ Whichever is first [the minimum or MIN() of their respective
completion times]
n Is this correct?
¨ F10 = IF 'D10 > MAX H$1: H9 , D10, IF 3D10 > MAX K$1: K9 , ""

, MIN MAX H$1: H9 , MAX K$1: K9 4(


Reliable and Durable IoT Applications & Networks
RADIAN Research Laboratory 38
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (8)

n The mentioned code assumes that there is only a single


column indicating the beginning of service for every
customer
¨ Regardless of having two servers
n Each must have a column for beginning of service for their own
¨ This assumption is not with accordance to principles of the
problem
n We must indicate the beginning of service for a specific
customer on the related column, only if the
corresponding server handles the job
¨ Just assume MAX(H)>MAX(K)
n Baker beginning will be written on Able’s, which is incorrect
¨ 𝐈𝐅(𝐌𝐀𝐗 𝐇$𝟏: 𝐇𝟗 ≤ 𝐌𝐀𝐗 𝐊$𝟏: 𝐊𝟗 , 𝐌𝐀𝐗 𝐇$𝟏: 𝐇𝟗 , "")
Reliable and Durable IoT Applications & Networks
RADIAN Research Laboratory 39
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (9)

n For service times of Able, you could use another IF()


function to make the cell blank or have a value:
¨ G10 = IF(𝐅𝟏𝟎 > 𝟎, new service time, "")
¨ F10>0 means customer 10 was assigned to Able
n Therefore, we check the Able service time table and assign a service
time to customer 10
n As you can see, service time value could be only
indicated for a server, if it has a corresponding start time
¨ Based on what we discussed in previous slide
n To obtain service ending time:
¨ H10 = IF(F10 > 0, F10 + G10, "")

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 40
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (9)

n Let’s have a discussion about performance of this


queuing system:
n The analysis of our simulation table results in the
following:
¨ Busy time of Able (%):
"#$%& $!() #* +,&) -)./!0) $!() 34
n = = 90%
"#$%& -!(1&%$!#2 $!() 45
n Over the 62-minute period Able was busy 90% of the time
¨ Busy time of Baker (%):
"#$%& $!() #* 6%7). -)./!0) $!() 89
n
"#$%& -!(1&%$!#2 $!()
= 45 = 69%
n Baker was busy only 69% of the time
n Why?
¨ The seniority rule keeps Baker less busy (and gives Able more tips)

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 41
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (10)

n Nine of the 26 arrivals (about 35%) had to wait in the


queue
n The average waiting time for all customers was only
about 0.42 minute (25 seconds), which is very small
@@
¨ Average queue time = = 0.42 Minute = 25 Seconds
AB
n Those nine who did have to wait only waited an average
of 1.22 min, which is quite low
@@
¨ Average queue time for those who waited = = 1.2 Minute
C

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 42
Dr. Bardia Safaei
Simulation of Able Baker Carhop Problem (11)

n In summary, this system seems to be well balanced


n One server cannot handle all the diners
n Three servers would probably be too many
n Adding an additional server would surely reduce the
waiting time to nearly zero
¨ However, the cost of waiting would have to be quite high to justify
an additional server

Reliable and Durable IoT Applications & Networks


RADIAN Research Laboratory 43
Dr. Bardia Safaei

You might also like