## 03 June, 2015

### Restroom Queues

This is a post about a vaguely baseball-related problem that happened recently - on opening day at Wrigley field the lines to use the restrooms were a complete disaster. Turns out you can use statistical modeling to model queues (fancy word for lines), and with some assumptions, you can actually figure out how long the average wait is and how many people are, on average, in line!

Before I get started, the purpose of this post is just as a demonstration of basic queuing theory, not a full analysis of the situation at Wrigley field. A full analysis would require many, many more assumptions, and would take computer modeling and simulation in order to produce estimates.

A queuing model envisions two "parts" of the queue - a line, and a "service center" that people spend time in at the end of the line, and then depart from. If people are leaving the service center faster than they are arriving to the line, the line will be short. If people are arriving to the line faster than they leave the service center, the line will be long.

Underlying queuing theory is the model of times between arrivals and the times for service. The basic model for these is

$A_i \sim Exp(\lambda)$
$S_i \sim Exp(\mu)$

That is, times between arrivals $A_i$ are exponentially distributed with a constant rate of $\lambda$ arrivals per unit of time and service times $S_i$ are exponentially distributed with a constant rate of $\mu$ services per unit of time. Of course in the real world the arrival and service rates are not constant, but we can make the assumption for the purpose of a quick discussion and it should work out okay.

So what happened at Wrigley field? The answer is that the queuing system became unstable - meaning, essentially, that people were arriving faster to restrooms much faster than they were leaving them. What happens in an unstable system? The line just keeps getting longer and longer - theoretically leading to an infinite line, but in the real world leading to situations like at Wrigley Field's.

What makes a system unstable? Depends on the number of "service stations" available - we'll call this quantity $c$. In a bank with one teller, for example, $c = 1$. If there's only one service station, then the system becomes unstable when $\lambda > \mu$ - the arrival rate is greater than the service rate.

Now let's think about restrooms. Clearly in a restroom there can be multiple types of service stations  - toilets, urinals, and sinks - all of which will have different service times, and some people may skip the sink all together (gross). So clearly this is not a "basic" modeling situation, but again - demonstration, not full analysis.

Let's combine one toilet/urinal and one sink into a single service station, and say that there are $c$ of them in a restroom. The system is unstable, then, if $\lambda > c\mu$ - that is, the arrival rate is larger than $c$ times the service rate.

What about all the other quantities involved? There's a handy queuing theory calculator I've found on the internet - we're going to choose "M/M/c." The first and second M stand for "Memoryless" - referencing our choice of the exponential distribution for interarrival and service times - and the $c$ is the number of servers as defined above.

Let's plug in a few numbers into the calculator - for example, say there are $\lambda = 60$ customers arriving per hour, there are $c = 10$ service stations (toilet/urinal and sink combined) that can handle $\mu = 8$ customers per hour each. What are the properties of the queuing system?

There are, on average, about 8.4 customers in the system (using the restroom plus in line). On average there are 0.92 customers in line. The customer will have to wait approximately 0.92 minutes on average in line before using the restroom. All well and good.

What happens as $\lambda$ approaches $c \mu$? Let's say now that $\lambda = 60$ customers per hour and $\mu = 8$ customers per hour, but two toilets break and now there are only $c = 8$ service stations. The properties of the queueing system are

A customer is likely to have to wait 12.1 minutes before using the restroom, and there are 12.1 people in line, on average.

As $\lambda$ and $c\mu$ move closer to each other, what tends to happen is that the average time spent waiting in the queue becomes longer and longer, and the average number of people in the queue becomes longer and longer, until the system reaches instability and the (theoretical) average number of people in the system and the average wait time goes to infinity. In the restroom example, what happens if one more toilet breaks and the system now has $c = 7$ service stations? $60 > 7*8 = 56$, and the system very quickly goes from "stable but with a wait" to - well, what you saw reported on the news at Wrigley field.

So what do I think happened at Wrigley? If we think of each restroom as its own queuing  system, the construction meant that there were fewer restrooms for more people, suddenly and drastically increasing $\lambda$ for each system while $\mu$ and $c$ stayed constant - leading to instability of what previously seemed like a very stable system.