# 2 trams are coming every 5 and 10 minutes. On average, how long do I have to wait for any tram to come?

I want to follow the approach from Christian Blatter here

3 trams are coming every 10, 15 and 15 minutes. On average, how long do I have to wait for any tram to come?

using "the assumption that the trams arrive on time with unknown but equidistributed phases. In the following I shall treat model". However, my theoretical result do not match my simulation result.

A random point $P=(X,Y)$ is chosen in the block $$B:=\{(x,y)\>|\>0\leq x\leq5,\ 0\leq y\leq 10,\}\ .$$ The waiting time $T$ is then given by $T=\min\{X,Y\}$.

The points $P$ with waiting time between $t$ and $t+dt$ is a panel of thickness $dt$ and having a distance $t$ from the planes $x=0$ and $y=0$. (Here the union of pairwise buses is one because there are only two buses.) The area of the panel is $(10-t)(5-t)$.

Therefore, the pdf $f_T$ of the waiting time is given by $$f_T(t)={1 \over 5 \cdot 10}(5-t) \cdot (10-t) \qquad(0\leq t\leq5)\ .$$ $$f_T(t)={1 \over 50}(50-15t+t^2) \qquad(0\leq t\leq5)\ .$$

From this we obtain the expected waiting time as $$E(T)=\int_0^{5} t \cdot f_T(t) dt= \int_0^{5} \frac{1}{50}[50t-15t^2+t^3] = \frac{1}{50}[50/2t^2-15/3t^3+1/4t^4)]^{5}_0 = 3.125.$$

However, from my simulation I get around 2.09, I guess that is 25/12:

I did a R simulation with the assumptions that buses arrive promptly every 5 and 10 minutes, respectively. However, the interval time among buses is fixed with uniformly distributed starting times. I simulate buses between [0,10000] minutes and the guy arriving at the bus stop at time t in [50,9950] and check the minimum time to next bus (which arrives first out of 2).

   upperbound <- 10000
waitVector <- vector()
nbRuns <- 10000
for(count1 in 1:nbRuns) {
seq1 <- 10*runif(1) + seq(from=0,to=upperbound,by=10)
seq2 <- 5*runif(1) + seq(from=0,to=upperbound,by=5) # uniformly distributed, but fixed distance among both buses
seq3 <- sort(c(seq1,seq2))
arrivalTime <- runif(n=1,min=50,max=(upperbound-50))
minSeq <- seq3 - arrivalTime
minSeq <- minSeq[minSeq > 0] # cant catch bus who left before I arrived
minTime <- min(minSeq)
waitVector <- c(waitVector,minTime)
}
minAvgWaitTime <- mean(waitVector)
print(range(waitVector))
print(paste("Minimum avg wait time base on ",nbRuns," simulations is: ",minAvgWaitTime,sep=""))

• Here's a basic sanity check: If there is just the single tram that goes every 5 minutes, the average wait will be 2.5 minutes. Adding more trams can never increase that value. Jul 4, 2016 at 19:57
• Yeah, I understand for one bus it is just the expected value based on distribution $\sim U[0,5],$ i.e. $E[X] = \frac{5-0}{2} = 2.5$ Jul 8, 2016 at 11:53

Your transfer of the solution from $3D$ to $2D$ is wrong. What was a plane is now a line; what was a panel is now a strip. There are two strips of width $\mathrm dt$, with lengths $10-t$ and $5-t$, so the probability distribution function is

$$f_T(t)=\frac{15-2t}{50}$$

and the expected waiting time is

$$E(T)=\int_0^5tF_T(t)\,\mathrm dt=\frac{25}{12}\;.$$

• Thanks! So how does that generalize for n buses? Jul 4, 2016 at 23:17
• Thanks! So how does that generalize for n buses? My guess is that in nD the pdf is formed by the sum (union) of n hyperplanes which are of dimension (n-1) each; and each hyperplane is formed by a polynomial of dimension (n-1) obtained by the product of multiplying the waiting conditions, such as (10-t), of (n-1) terms from the n terms available. Jul 4, 2016 at 23:23
• @PT272: That's exactly right; and the denominator is the product of all the periods. Jul 5, 2016 at 10:30
• Thanks for that; I think I understood it on an algebraic level. But I am still a bit puzzled why it is like that, e.g. for the 3D case we have the sum of 3 pairwise waiting times forming hyperplanes (quadratic polynomial) of dimension 2 (panels). In this case I would have thought that the arrival times of all 3 buses are independent, i.e. just the product of all 3 terms (cubic polynomial). Jul 5, 2016 at 23:56
• @PT272: I get the impression that you're confusing the density for a certain triple of individual waiting times for the individual buses with the density for the waiting time for the next bus. The density for a certain triple of individual waiting times is indeed just the product of the densities for the three independent waiting times, but that's boring, since they're all uniform and the product is also uniform -- that tells us nothing about the actual waiting time, and that's not the product that's being calculated here. Jul 6, 2016 at 7:41

Personally, I find it much easier to think in CDF terms. In this example, the cumulative probability of waiting for a tram for up to $$t$$ corresponds to the area of the shaded region in the chart below.

In other words, $$F_T(t) = \frac{1}{50} (5t + 10t - t^2)$$, and $$f_T(t) = \frac{1}{50} (15 - 2t)$$. We thus avoid thinking in $$dt$$ terms.

This could have been a comment to @joriki answer, but I need to include the chart.