Understanding M/M/1 queue simulation

115 Views Asked by At

I'm trying to simulate a M/M/1 queue where the service is exponential(10/hr) while the arrivals are Poisson(5/hr). I'm trying to find the long-term average number of customers through simulation, and while I know the answer of the question to be the mean of a geometric(1), my simulation does not have the same answer. What I did was: I start with 0 customers, and the inter-arrival time for the next customer is a random exponential(1/5). Next event time would be random exponential(1/15). Then, I can get one arrival if my simulated probability is less than 1/3 (5/(5+10)) and one departure otherwise. I'm counting the number of customers at each event time, and dividing that sum by the total number of events. Am I misunderstanding something?

1

There are 1 best solutions below

0
On

You're only using the average number of customers at arrival/departure times, so you aren't actually measuring the fraction of time the system has a given number of customers.

For example, suppose over the time interval $[0,100]$ there are arrivals at $t=1$ and $t=2$, then departures at $t=90$ and $t=100$. There are four events, so your method would yield

$$ \frac14\left(1+2+1\right) = 1. $$

The actual average number of customers in the system would be

$$ \frac1{100}\cdot 1 + \frac{88}{100}\cdot 2 + \frac{10}{100}\cdot 1 = \frac{187}{100}. $$