+ All Categories
Home > Documents > Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that...

Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that...

Date post: 22-Jan-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
14
1 Simulating Queuing Models in SAS® Danny Rithy, California Polytechnic State University, San Luis Obispo, CA ABSTRACT This paper introduces users to how to simulate queuing models using SAS®. SAS will simulate queuing system in which entities (like customers, patients, cars or email messages) arrive, get served either at a single station or at several stations in turn, might have to wait in one or more queues for service, and then may leave. After the simulation, SAS will give a graphical output as well as statistical analysis of the desired queuing model. INTRODUCTION Queuing is a common occurrence in everyday life. From the customer perspective, we want to be served as quickly as possible. From the company’s perspective, we want a smooth process flow so customers do not need stay in the system for an inappropriately long period of time. Unfortunately, businesses have limited resources so they cannot hire many employees or machines to serve all their customers. A standard queuing system is needed in order to balance the needs and desires of both customers and service. To analyze the efficiency of such a system, our approach will be to simulate queuing models. Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has a system where customers have to go through a process. For example, a grocery store has several checkout lanes so customers pay their groceries and exit once they finished. A patient enters a hospital to receive treatment for an illness and exits the hospital once they have completed acute treatment. There are many components that build each individually unique system. In our grocery store example, we have the grocery cart corral, individual product aisles, front-end purchase centers, registers, and bagging stations. In the hospital example, we have registration, the urgent-care clinic, exam rooms, treatment rooms, discharge, and pharmacy. Any system is always consisted of queues (waiting lines) and service. Queuing theory is usually introduced in stochastic processes, (stochastic) operations research, and discrete event simulation to industrial engineers, operations researchers and statisticians. The math behind these models is based on continuous-time Markov chains, of which will not be covered in this paper. This paper will show how SAS users can simulate queuing models based on real world operations. An alternative approach is to use a discrete event simulation software to point-and-click the component of the system for better visualization and less computation-intense. ARRIVAL, SERVICE AND QUEUE CHARACTERISTICS There are two main characteristics in the queuing models: arrival and service distribution. The arrival distribution describes the customer’ s arrival into the system. It can be either finite or infinite. The distribution usually follows the Poisson distribution. A customer doesn’t always arrive and waits in the queue. Their behavior depends on the number of customers waiting in line. They can be patient, balking (those who do not join a queue due to the long line), and reneging (those who join a queue but leave before being served). The service distribution describes the service time during which a customer is being served. It can be either constant or random. The distribution usually follows an exponential distribution. However, it can be any distribution where mean and variance are known. There are several ways to serve each customer from the queue when the server completes the service of the current customer. First-In First-Out is a common discipline to serve customers on a first-in first-out basis. Last-In First-Out is also a common discipline to serve customers on a last-in first-out basis. Priority occurs when a customer is served based on the importance to complete their service requirement.
Transcript
Page 1: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

1

Simulating Queuing Models in SAS®

Danny Rithy, California Polytechnic State University, San Luis Obispo, CA

ABSTRACT

This paper introduces users to how to simulate queuing models using SAS®. SAS will simulate queuing system in which entities (like customers, patients, cars or email messages) arrive, get served either at a single station or at several stations in turn, might have to wait in one or more queues for service, and then may leave. After the simulation, SAS will give a graphical output as well as statistical analysis of the desired queuing model.

INTRODUCTION

Queuing is a common occurrence in everyday life. From the customer perspective, we want to be served as quickly as possible. From the company’s perspective, we want a smooth process flow so customers do not need stay in the system for an inappropriately long period of time. Unfortunately, businesses have limited resources so they cannot hire many employees or machines to serve all their customers. A standard queuing system is needed in order to balance the needs and desires of both customers and service. To analyze the efficiency of such a system, our approach will be to simulate queuing models.

Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has a system where customers have to go through a process. For example, a grocery store has several checkout lanes so customers pay their groceries and exit once they finished. A patient enters a hospital to receive treatment for an illness and exits the hospital once they have completed acute treatment. There are many components that build each individually unique system. In our grocery store example, we have the grocery cart corral, individual product aisles, front-end purchase centers, registers, and bagging stations. In the hospital example, we have registration, the urgent-care clinic, exam rooms, treatment rooms, discharge, and pharmacy. Any system is always consisted of queues (waiting lines) and service.

Queuing theory is usually introduced in stochastic processes, (stochastic) operations research, and discrete event simulation to industrial engineers, operations researchers and statisticians. The math behind these models is based on continuous-time Markov chains, of which will not be covered in this paper.

This paper will show how SAS users can simulate queuing models based on real world operations. An alternative approach is to use a discrete event simulation software to point-and-click the component of the system for better visualization and less computation-intense.

ARRIVAL, SERVICE AND QUEUE CHARACTERISTICS

There are two main characteristics in the queuing models: arrival and service distribution.

The arrival distribution describes the customer’s arrival into the system. It can be either finite or infinite. The distribution usually follows the Poisson distribution. A customer doesn’t always arrive and waits in the queue. Their behavior depends on the number of customers waiting in line. They can be patient, balking (those who do not join a queue due to the long line), and reneging (those who join a queue but leave before being served).

The service distribution describes the service time during which a customer is being served. It can be either constant or random. The distribution usually follows an exponential distribution. However, it can be any distribution where mean and variance are known.

There are several ways to serve each customer from the queue when the server completes the service of the current customer. First-In First-Out is a common discipline to serve customers on a first-in first-out basis. Last-In First-Out is also a common discipline to serve customers on a last-in first-out basis. Priority occurs when a customer is served based on the importance to complete their service requirement.

Page 2: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

2

KENDALL NOTATION

Kendall’s notation describes and classifies a queuing node, which denotes as A/B/s where:

A = The arrival distribution. M represents Markovian which it follows a Poisson distribution. D represents constant or deterministic distribution. G represents a general distribution where mean and variance are known. The Greek letter λ (lambda) represents the arrival distribution.

B = The service time distribution. M represents Markovian which it follows an exponential distribution. D represents a constant or deterministic distribution. G represents a general distribution where mean and variance are known. The Greek letter 𝜇 (mu) represents the service distribution.

s = Number of servers.

For example, the M/M/1 is the simplest queuing system where the arrival distribution represents a Poisson distribution, the service distribution represents an exponential distribution and the system has one server. An ATM is a typical example of the M/M/1 queuing system.

QUEUE PERFORMANCE

By the end of the simulation, we want to know the following questions:

How long does each customer being served in the system, on average?

What is the probability that there is no customers in the queue?

What is the average time that each customer is waiting in the line?

How many servers do we need?

These questions are typically measure the system performance with the following metrics:

Wq = Average time that each customer spends in the queue.

W = Average time that each customer spends in the system.

Lq = Average number of customers in the queue.

L = Average number of customers in the system.

𝜌 = Utilization factor in the system (e.g probability that all servers are busy).

One thing to note is 𝜌 has to between 0 and 1 (the average service rate is greater than the average arrival rate;

or λ < 𝜇). This means that the system has too many customers waiting in line than the servers provide. In the long

run, the system will be overload.

STATISTICAL ANALYSIS OF THE SIMULATION RESULTS

In order to understand a system, we need to measure the system performance with the metrics using PROC MEANS. The following statements are PROC MEANS for a specific metric. &system is a macro variable where it contains a

dataset of the simulation in a specific queuing system from the DATA step.

The following metrics are defined in the DATA step and used in the VAR statement for PROC MEANS:

Xt is the number of customers in the system at time t.

Lq is the number of customers in the queue at time t. In the DATA step, we define Lq as: Xt – 1. This can only calculated if there are greater than one customer in the system, or Xt > 1.

Wn is the waiting time in the system for customer nth.

Wn_Lq is the waiting time in the queue for customer nth.

p is defined as an indicator variable whether there is a customer at time t.

To calculate L, we simply specify Xt in the VAR statement.

title "Average Number of Customers in the System";

proc means data = &system mean;

var Xt;

ODS OUTPUT Means.Summary = L;

Page 3: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

3

run;

title;

To calculate Lq, we specify Lq in the VAR statement.

title "Average Number of Customers in the Queue";

proc means data = &system mean;

var Lq;

ODS OUTPUT Means.Summary = Lq;

run;

title;

In this statements, we want to take the average of Wn. The WHERE statement takes a subset of each customer leaving the system and more than one customer in the system. This reveals the amount of time each customer spends in the system.

title "Average Time in the System";

proc means data = &system mean;

var Wn;

where event = -1 or Xt >= 1;

ODS OUTPUT Means.Summary = W;

run;

title;

In this statements, we want to take the average of Wn_Lq. The WHERE statement takes a subset only when there are more than one customer in the system. The server can serve only one customer at a time, so any customer who enters the system while the server is busy must wait in line.

title "Average Waiting Time in the Queue";

proc means data = &system mean;

var Wn_Lq;

where Lq >= 1 and event = 1;

ODS OUTPUT Means.Summary = Wq;

run;

title;

To calculate p, again, we specify p in the VAR statement to take the average.

title "Average Server Utilization";

proc means data = &system mean;

var p;

ODS OUTPUT Means.Summary = rho;

run;

title;

M/M/1 QUEUE

Suppose we have a single server in a small grocery store. Customer arrival at the small grocery store holds a Poisson distribution at a mean rate of 15 customers per hour. A server can serve each customer with an exponential distribution at a mean service rate of 20 customers per hour.

Display 1 reveals the step plot of the number of customers who stay in the system over time where there is only one server. Depending on the arrival and service rate, the numbers will vary. If the service rate is much higher than the arrival rate, then we expect to see less than two customers in the service line at any given time. However, if the arrival rate is higher than the service rate, then we expect to see the number of customers grow exponentially and at a very fast rate.

Display 2 reveals the histogram of number of customers in the system. On average, the server will handle one customer at a time.

Table 1 has the summary statistics of the simulation. The average waiting time in the system is 32.4 seconds and the average waiting time in the queue is 25.2 seconds. The server is busy 68% of the time.

Page 4: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

4

Display 1. Step Plot of number of customers in the M/M/1 system over time.

Display 2. Histogram of number of customers in the M/M/1 system.

Page 5: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

5

Table 2. M/M/1 result with performance metrics.

M/D/1 QUEUE

The M/D/1 system is similar to the M/M/1 system except its service time is deterministic. A car wash is a typical example of the M/D/1 system.

Suppose that people arrive at a pizza vending machine at a rate of 15 per hour and follow a Poisson distribution. It takes exactly 3 minutes to cook a pizza for each person through the process of adding ingredients, baking, and putting into a box. In this case, we specify the service rate as 20 per hour.

Display 3 reveals the step plot of number of customers stay in the M/D/1 system over time while there is one server. Because the service time is deterministic, each customer leaves the system in 3 minutes. Therefore, the departure time is constant.

Display 4 reveals the histogram of number of customers in the M/D/1 system.

Table 2 has the summary statistics of the simulation. The average waiting time that each person spends in the queue is 6.09 minutes. The average time that each person spends in the system and receives his pizza is 12.94 minutes. The average time of the system is high due to a lengthy queue during a particular time.

Display 3. Step Plot of number of customers in the M/D/1 system over time.

Page 6: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

6

Display 4. Histogram of number of customers in the M/D/1 system.

Table 2. M/D/1 result with performance metrics.

M/G/1 QUEUE

The M/G/1 system’s service time has the general distribution where mean and variance are known. The distribution can any distribution ranges from binomial to normal. A repair shop is a typical example of the M/G/1 system where the repair time vary around the average.

Suppose that cars arrive at an oil change station at a rate of 4 per hour and follow the Poisson distribution. It takes 12 minutes, on average, to change an oil for each car with a variance of 4 minutes. Assume the service time follows the normal distribution.

Display 5 reveals the step plot of number of customers stay in the M/G/1 system over time while there is one server.

Display 6 reveals the histogram of number of customers in the M/G/1 system.

Table 3 has the summary statistics of the simulation. The average waiting time that each person spends in the queue is 25.2 minutes. The average time that each car spends in the system and gets oil change is 29.4 minutes.

Page 7: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

7

Display 5. Step Plot of number of customers in the M/G/1 system over time.

Display 6. Histogram of number of customers in the M/G/1 system.

Table 3. M/G/1 result with performance metrics.

Page 8: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

8

FUTURE WORK

This paper is a bit more challenging than I expected. Most of the simulation are involved in the DATA steps than anywhere else. The average time each customer spends in the system and queue are challenging to get the precise and consistent number compare to the classic performance metric.

I will update this paper in future conference proceedings and presentations. Particularly, I plan on adding the M/M/s system to the list of queuing processes. I also acknowledge that there are economics considerations that need to be added (e.g how many servers do we need?) in order for the models to near completeness. Because each queuing model is simple, it is also important to consider the many other variables that occur in real world business modeling. What is the probability that a customer arrives to the system decided not to join because of the lengthy queue? What is the probability that a customer leaves the queue? These metrics are known as balking and reneging, respectively, and require their own consideration in such a study.

ACKNOWLEDGMENTS

I would like to thank my industrial engineering professors, Dr. Kurt Colvin and Jill Speece, for introducing me to queuing theory. I would like to thank my statistics professor, Dr. Kevin Ross, for teaching stochastic processes at Cal Poly and diving deeper into the theory with mathematical models using continuous-time Markov chains. I would like to thank Deanna Schreiber-Gregory for providing me feedbacks on this paper. Lastly, I would like to thank WUSS and Statistics and Analytics committees for accepting my paper!

CONTACT INFORMATION

Your comments and questions are valued and encouraged. Contact the author at:

Name: Danny Rithy E-mail: [email protected] Web: linkedin.com/in/drithy

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.

Other brand and product names are trademarks of their respective companies.

Page 9: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

9

Source Code

/* M/M/1 Queue */

data mm1;

* Specify parameters;

lambda = 10; * arrival rate ;

mu = 20; * service rate ;

* Specify # of jumps for simulation ;

Njumps = 50;

* Start simulation at time 0 ;

Xt = 0; * number of customers in time t;

cumsum_Wn = 0; * cumsum_Wn is the cumulative waiting time for job nth ;

p = 0; * 1 if server is busy and 0 otherwise ;

output;

* Start simulation in a do-until loop until we reach the limit ;

do n = 2 to Njumps;

t_rexp = rand("Exponential") * lambda;

/* This if-else statement is based on the transition probability matrix

and we randomly sample either -1 or 1 */

if rand("Uniform") <= mu / (lambda+mu) then

event = -1;

else

event = 1;

/* If there is no customer in time t, then immediately move the process from

0 to 1 customer according to transition rate matrix */

if Xt = 0 then

do;

Xt = Xt + 1;

cumsum_Wn = cumsum_Wn + (t_rexp / lambda);

p = 0;

end;

else

do;

Xt = Xt + event;

cumsum_Wn = cumsum_Wn + (t_rexp / (lambda + mu));

p = 1;

end;

output;

end;

drop lambda mu mins event hours;

run;

data mm1;

set mm1;

Wn = dif(cumsum_Wn); * Take the difference between waiting time

of the nth job and (n-1)th job ;

* Create a variable called Lq where it measures # of customers waiting in the queue;

if Xt = 0 then

Lq = 0;

else

Lq = Xt - 1;

run;

data mm1;

set mm1;

Page 10: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

10

Wn_Lq = abs(dif(Wn)); * Take the difference between waiting time

of the nth job and (n-1)th job in the QUEUE;

run;

/* M/D/1 Queue */

data md1;

* Specify parameters;

D = 20; * Deterministic time ;

lambda = 15; * arrival rate ;

mu = D; * service rate ;

* Specify time for simulation ;

Njumps = 50;

* Start simulation at time 0 ;

Xt = 0; * number of customers in time t;

cumsum_Wn = 0; * cumsum_Wn is the cumulative waiting time for job nth ;

p = 0;

output;

do n = 2 to Njumps;

t_rexp = rand("Exponential") * lambda;

/* This if-else statement is based on the transition probability matrix

and we randomly sample either -1 or 1 */

if rand("Uniform") <= mu / (lambda + mu) then

event = -1;

else

event = 1;

/* If there is no customer in time t, then immediately move the process from

0 to 1 customer according to transition rate matrix */

if Xt = 0 then

do;

Xt = Xt + 1;

event = 1;

cumsum_Wn = cumsum_Wn + (t_rexp / lambda);

end;

else

do;

Xt = Xt + event;

if event = -1 then

cumsum_Wn = cumsum_Wn + mu;

else

cumsum_Wn = cumsum_Wn + (t_rexp / mu + lambda);

end;

if Xt = 0 then

p = 0;

else

p = 1;

output;

end;

drop lambda mu n D Njumps;

run;

data md1;

set md1;

Wn = dif(cumsum_Wn); * Take the difference between waiting time

of the nth job and (n-1)th job ;

Page 11: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

11

* Create a variable called Lq where it measures # of customers waiting in the queue

;

if Xt = 0 then

Lq = 0;

else

Lq = Xt - 1;

run;

data md1;

set md1;

Wn_Lq = abs(dif(Wn)); * Take the difference between waiting time

of the nth job and (n-1)th job in the QUEUE;

run;

/* M/G/1 Queue */

data mg1;

* Specify parameters;

lambda = 4; * arrival rate ;

mu = 15; * service rate ;

sd = 2;

* Specify time for simulation ;

Njumps = 50;

* Start simulation at time 0 ;

Xt = 0; * number of customers in time t;

cumsum_Wn = 0; * cumsum_Wn is the cumulative waiting time for job nth ;

p = 0;

output;

do n = 2 to Njumps;

t_rexp = rand("Exponential") * lambda;

service_time = rand("Normal", mu, sd);

/* This if-else statement is based on the transition probability matrix

and we randomly sample either -1 or 1 */

if rand("Uniform") <= mu / (lambda + mu) then

event = -1;

else

event = 1;

/* If there is no customer in time t, then immediately move the process from

0 to 1 customer according to transition rate matrix */

if Xt = 0 then

do;

Xt = Xt + 1;

event = 1;

cumsum_Wn = cumsum_Wn + (t_rexp / lambda);

end;

else

do;

Xt = Xt + event;

if event = -1 then

cumsum_Wn = cumsum_Wn + 1/service_time;

else

cumsum_Wn = cumsum_Wn + (t_rexp / (lambda + mu));

end;

if Xt = 0 then

Page 12: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

12

p = 0;

else

p = 1;

output;

end;

drop lambda mu n Njumps;

run;

data mg1;

set mg1;

Wn = dif(cumsum_Wn); * Take the difference between waiting time

of the nth job and (n-1)th job ;

* Create a variable called Lq where it measures # of customers waiting in the queue

;

if Xt = 0 then

Lq = 0;

else

Lq = Xt - 1;

run;

data mg1;

set mg1;

Wn_Lq = abs(dif(Wn)); * Take the difference between waiting time

of the nth job and (n-1)th job in the QUEUE;

run;

* Use SAS Macros to generate results from multiple datasets ;

%macro queuing_plot(system=);

title "Step Plot of Number of Customers in the System Over Time";

proc sgplot data = &system;

step x = cumsum_Wn y = Xt;

xaxis label = "Time (t)";

yaxis label = "X(t)";

run;

title;

title "Histogram of Number of Customers in the System";

proc sgplot data = &system;

histogram Xt;

xaxis label = "# of Customers";

run;

title;

title "Histogram of Waiting Time in the Queue";

proc sgplot data = &system;

histogram Wn / nbins = 10;

xaxis label = "Time";

run;

title;

title "Average Number of Customers in the System";

proc means data = &system mean;

var Xt;

ODS OUTPUT Means.Summary = L;

run;

title;

Page 13: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

13

title "Average Number of Customers in the Queue";

proc means data = &system mean;

var Lq;

ODS OUTPUT Means.Summary = Lq;

run;

title;

title "Average Time in the System";

proc means data = &system mean;

var Wn;

where event = -1 or Xt >= 1;

ODS OUTPUT Means.Summary = W;

run;

title;

title "Average Waiting Time in the Queue";

proc means data = &system mean;

var Wn_Lq;

where Lq >= 1 and event = 1;

ODS OUTPUT Means.Summary = Wq;

run;

title;

title "Average Server Utilization";

proc means data = &system mean;

var p;

ODS OUTPUT Means.Summary = rho;

run;

title;

%mend;

data op_characteristics;

input OP $45.;

datalines;

Average Number of Customers in the Queue

Average Number of Customers in the System

Average Waiting Time in the Queue

Average Time in the System

Average Server Utilization

run;

%macro queuing_metrics(system=, title=);

data mean;

set Lq (rename = (Lq_Mean = Mean))

L (rename = (Xt_Mean = Mean))

Wq (rename = (Wn_Lq_Mean = Mean))

W (rename = (Wn_Mean = Mean))

rho (rename = (p_Mean = Mean));

run;

data &system._result;

merge op_characteristics mean;

run;

ODS PDF FILE = "F:\F-\WUSS 2016\Queuing Theory\&system._result.pdf";

title " &title Result";

proc report data = &system._result nowd

style(header) = [background = BIBG font_size = 1 font_weight = bold];

column OP mean;

define OP / "Operating Characteristics";

define mean / "Mean" mean format = 5.2;

Page 14: Simulating Queuing Models in SAS® · Queuing models are analytical modeling approaches that develop a simulation of the process of the system. In the real world, every service has

Simulating Queuing Models in SAS, continued

14

compute OP;

if OP IN ("Average Number of Customers in the System",

"Average Time in the System") then

call define (_row_, 'STYLE','STYLE = [background = BIBG ]');

endcomp;

run;

title;

ODS PDF CLOSE;

%mend;


Recommended