Simulation

Modeling Theme Park Queues

Who doesn’t love a day at the theme park? You can go on thrilling roller‒coaster rides, enjoy elaborate shows, have a tasty lunch in between or just relax and take in the scenery. Of course there’s one thing that does spoil the fun a bit: the waiting. For the most popular attractions waiting times of around one hour are not uncommon during peak times, while the ride itself may be over in no more than two or three minutes.

Let’s work towards a basic model for queues in theme parks and other situations in which queues commonly arise. We will assume that the passing rate R(t), that is, the number of people passing the entrance of the attraction per unit time, is given. How many of these will enter the line? This will depend on the popularity of the attraction as well as the current size of the line. The more people are already in the line, the less likely others are to join. We’ll denote the number of people in the line at time t with n(t) and use this ansatz for the rate r(t) at which people join the queue:

Mathematical Shenanigans_html_5618c8ce

The constant a expresses the popularity of the attraction (more specifically, it is the percentage of passers‒by that will use the attraction if no queue is present) and the constant b is a “line repulsion” factor. The stronger visitors are put off by the presence of a line, the higher its value will be. How does the size of the line develop over time given the above function? We assume that the maximum serving rate is c people per unit time. So the rate of change for the number of people in line is (for n(t) ≥ 0):

Mathematical Shenanigans_html_5c443fa7

In case the numerical evaluation returns a value n(t) < 0 (which is obviously nonsense, but a mathematical possibility given our ansatz), we will force n(t) = 0. An interesting variation, into which we will not dive much further though, is to include a time lag. Usually the expected waiting time is displayed to visitors on a screen. The visitors make their decision on joining the line based on this information. However, the displayed waiting time is not updated in real‒time. We have to expect that there’s a certain delay d between actual and displayed length of the line. With this effect included, our equation becomes:

Mathematical Shenanigans_html_m2ee86a4f

Simulation

For the numerical solution we will go back to the delay‒free version. We choose one minute as our unit of time. For the passing rate, that is, the people passing by per minute, we set:

R(t) = 0.00046 · t · (720 ‒ t)

We can interpret this function as such: at t = 0 the park opens and the passing rate is zero. It then grows to a maximum of 60 people per minute at t = 360 minutes (or 6 hours) and declines again. At t = 720 minutes (or 12 hours) the park closes and the passing rate is back to zero. We will assume the popularity of the attraction to be:

a = 0.2

So if there’s no line, 20 % of all passers‒by will make use of the attraction. We set the maximum service rate to:

c = 5 people per minute

What about the “line repulsion” factor? Let’s assume that if the line grows to 200 people (given the above service rate this would translate into a waiting time of 40 minutes), the willingness to join the line drops from the initial 20 % to 10 %.

Mathematical Shenanigans_html_3d42d26c

→ b = 0.005

Given all these inputs and the model equation, here’s how the queue develops over time:

Mathematical Shenanigans_html_79a0f216

It shows that no line will form until around t = 100 minutes into opening the park (at which point the passing rate reaches 29 people per minute). Then the queue size increases roughly linearly for the next several hours until it reaches its maximum value of n = 256 people (waiting time: 51 minutes) at t = 440 minutes. Note that the maximum value of the queue size occurs much later than the maximum value of the passing rate. After reaching a maximum, there’s a sharp decrease in line length until the line ceases to be at around t = 685 minutes. Further simulations show that if you include a delay, there’s no noticeable change as long as the delay is in the order of a few minutes.

(This was an excerpt from my ebook “Mathematical Shenanigans”)

Advertisements

My Fair Game – How To Use the Expected Value

You meet a nice man on the street offering you a game of dice. For a wager of just 2 $, you can win 8 $ when the dice shows a six. Sounds good? Let’s say you join in and play 30 rounds. What will be your expected balance after that?

You roll a six with the probability p = 1/6. So of the 30 rounds, you can expect to win 1/6 · 30 = 5, resulting in a pay-out of 40 $. But winning 5 rounds of course also means that you lost the remaining 25 rounds, resulting in a loss of 50 $. Your expected balance after 30 rounds is thus -10 $. Or in other words: for the player this game results in a loss of 1/3 $ per round.

 Let’s make a general formula for just this case. We are offered a game which we win with a probability of p. The pay-out in case of victory is P, the wager is W. We play this game for a number of n rounds.

The expected number of wins is p·n, so the total pay-out will be: p·n·P. The expected number of losses is (1-p)·n, so we will most likely lose this amount of money: (1-p)·n·W.

 Now we can set up the formula for the balance. We simply subtract the losses from the pay-out. But while we’re at it, let’s divide both sides by n to get the balance per round. It already includes all the information we need and requires one less variable.

B = p · P – (1-p) · W

This is what we can expect to win (or lose) per round. Let’s check it by using the above example. We had the winning chance p = 1/6, the pay-out P = 8 $ and the wager W = 2 $. So from the formula we get this balance per round:

B = 1/6 · 8 $ – 5/6 · 2 $ = – 1/3 $ per round

Just as we expected. Let’s try another example. I’ll offer you a dice game. If you roll two six in a row, you get P = 175 $. The wager is W = 5 $. Quite the deal, isn’t it? Let’s see. Rolling two six in a row occurs with a probability of p = 1/36. So the expected balance per round is:

B = 1/36 · 175 $ – 35/36 · 5 $ = 0 $ per round

I offered you a truly fair game. No one can be expected to lose in the long run. Of course if we only play a few rounds, somebody will win and somebody will lose.

It’s helpful to understand this balance as being sound for a large number of rounds but rather fragile in case of playing only a few rounds. Casinos are host to thousands of rounds per day and thus can predict their gains quite accurately from the balance per round. After a lot of rounds, all the random streaks and significant one-time events hardly impact the total balance anymore. The real balance will converge to the theoretical balance more and more as the number of rounds grows. This is mathematically proven by the Law of Large Numbers. Assuming finite variance, the proof can be done elegantly using Chebyshev’s Inequality.

The convergence can be easily demonstrated using a computer simulation. We will let the computer, equipped with random numbers, run our dice game for 2000 rounds. After each round the computer calculates the balance per round so far. The below picture shows the difference between the simulated balance per round and our theoretical result of – 1/3 $ per round.

Image

(Liked the excerpt? Get the book “Statistical Snacks” by Metin Bektas here: http://www.amazon.com/Statistical-Snacks-ebook/dp/B00DWJZ9Z2)