Suppose you own a small grocery store. You have recently heard a few rumors that people don’t want to shop at your store because they have to wait too long to check out. But hiring more cashiers is an expensive option. And how many extra cashiers should you hire? If you hire too few, you might lose customers. If you hire too many, you will lose money. You need to find a way to determine the best number of cashiers to hire. One way to handle this situation is to simulate having more cashiers. But a monte carlo simulation is not appropriate since the system is not stable. This process changes at a countable number of points in time called events like every time a customer enters the store. For example, the distribution of waiting times for a cashier for the second customer is different than the distribution of waiting times for the first customer. Discrete event simulation is designed for just these types of situations. SAS® Simulation Studio is a discrete event simulation tool that can be used to model a system as it changes over time. This post will discuss, at a high level, how to create a discrete event simulation model of a simple grocery store.
To start creating a discrete event simulation model, creating a process flow diagram is a good first step. This diagram illustrates all of the steps of the process that are relevant to the purpose of the study. In this case, we are interested in how long people wait for a cashier as well as how many cashiers are needed for the store. The process, in words at a high level is as follows:
In order to create the process flow diagram, some more information is needed. For example, how often do customers come to the store? How long do they shop? How long does it take for the cashier to scan the purchases and collect the money? The answers to these questions are typically answered by using a statistical distribution. Typically, the distributions are determined by examining past data. For our example we will use the following:
Customers enter the store according to an exponential distribution with a mean of 4 minutes. Customer shopping follows a uniform distribution from 5 minutes to 30 minutes. The checkout time follows an exponential distribution with mean of 3 minutes.
With the diagram in hand, we need to discuss a little bit of terminology. For discrete event simulations the item (or items) that moves through the process is called an entity. Entities can have properties or attributes such as the age of the customer. The entities need to be generated according to a distribution of interarrival times rather than the number of entities. An exponential distribution, which is commonly used for interarrival times, will be used with a mean of 4 minutes. While the customer is shopping, that appears as a delay in our simulation since the customer is not using any of our services. The customer then waits in a queue for the cashier. In fact, the cashier is a resource that is needed by the customer to complete their shopping. Resources control the flow of the entity through the process. In our case, the customer is delayed by using the resource (cashier). That delay or checkout time is called Service in the diagram also uses an exponential distribution with a mean of 5 minutes. Finally, we are interested in two outputs from this model: the customer’s average time waiting for the cashier and the utilization of the cashier. In other words, how busy is that cashier?
Building the model Simulation Studio involves dragging blocks to build the model and using links to connect the ports that are attached to each block. A block is the most fundamental unit of the discrete event simulation model. Each block has a well-defined and specialized function. There are ports on each block that allow communication between the blocks. Red ports are on the left and right side of the blocks that allow entities to pass through the block. Blue ports are on the top and bottom of the blocks and allow information or data to pass through the block. The links define the path of the flow of entities and/or information. You end up with a graphical picture for a model. We won’t be able to go through all of the details here, but we will build our simple grocery store model.
Simulation Studio is based around projects. When you create a new project, you are presented with this interface.
You drag blocks from the templates into the model window to build the model. For this model we will only need six blocks.
We will start by dragging an entity generator block into the model to generate the customer entities. We attach a numeric source block to specify the exponential distribution with a mean of 4. After the entity generator block, the customer moves to a delay block to indicate their time spent shopping. Another numeric source block is attached to the delay block to specify the uniform distribution between 5 and 30 minutes. Next is a queue block which shows the customer entering the line for the cashier. Note that the queue block is only used if the cashier is already busy. Otherwise the customer passes directly to the server block which indicates the check out time with the cashier. Yet another numeric source block is used to indicate the distribution of checkout times. Finally, the customer leaves the store as indicated by the disposer block. The randomness of this model is all handled by the numeric source blocks which are pulling random numbers from the specified distributions. The final model looks as follows.
The details of this model, such as the different distributions that are used, and their parameters are all specified in the numeric source blocks. Similarly, the server block specifies the number of cashiers working in the store.
A few additional modifications are made to this model so that we can see some of the statistics that we are interested in observing. I have added two number holder blocks which are blocks that will store the maximum queue length and the average amount of time spent waiting in the queue. I ran the simulation, closing the store doors at 6:00 pm and allowing the customers in the store to finish their shopping.
The results of running this simulation show that the maximum number of people waiting for the cashier was 13. We also see that on average people waited 19.9 minutes for the cashier. Finally, once we closed the doors (which occurred after 600 minutes), the system clock in the upper-right of the screen capture displays 652.02004. This means that it took the cashier just over 52 minutes to checkout the people in line after the store closed.
Now these results are alarming, but this was a simulation. Maybe the next day would look better? So, let’s run the simulation for 10 days. This is accomplished by entering 10 replicates in the Experiment window. You will also see that some other responses have been added like cashier utilization.
Running the simulation for 10 days shows that the 19.9 minute average waiting time was indeed a bit unusual. On average across all of the days (the top line of the table), customers are waiting 9.6577 minutes. Maybe things are not as bad as they first seemed.
But what if we did hire a second cashier? Running the simulation for 10 days with two cashiers results in lower waiting times, as expected.
The average wait time is now under a minute. However, the cashier utilization is now 0.38 meaning that cashiers are only busy just over 38% of the time. Two cashiers are not really needed. Perhaps better customer service can be achieved by having one cashier and maybe a manager to come and help checkout people during rush hours. Or possibly have a part-time cashier to come in during the busiest times. We could modify our model to handle either of these situations, if we want.
Hopefully this simple example illustrates the value of discrete event simulation. Discrete event simulation is a tool that can be used to model real-life scenarios that have a countable number of changes to the system over time. Simulation Studio is a flexible tool that can be used to allow analysts to make decisions on many hypothetical situations by creating a model of real-world scenarios.
Find more articles from SAS Global Enablement and Learning here.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.