Let the M/M/1 queue with parameter $\lambda$ and $\mu$ start at state $n_{0}$ at the time $0$, the question is to estimate the average number of customers in the system during a certain time period T.
My solution is to use a very naive approach by doing a simulation of M/M/1 queue for the time T. Here is how I solve it.
The probability for the queue to move to the next state is \begin{equation} p=\frac{\lambda}{\lambda + \mu} \end{equation} The time for the queue to stay in one state is an exponential distribution random variable with parameter $\lambda + \mu$. My method is like this:
- Generate a random variable $\Delta t_0$ with exp($\lambda + \mu$), which is representing the stay time for the queue at state $n_0$;
- Generate a uniform random variable $p_0$ between $0$ to $1$, if $p_0 < p$, let the state $n_1$ be $n_0 + 1$, else be state $n_0 - 1$;
- Repeat 1 and 2 until the time period T runs out, say the last state to be $n_k$ (i.e. $\sum_{i=0}^{k} \Delta t_k = T$);
- The average number of the customers in the queue for the time period T is equal to \begin{equation} \bar{n} = \frac{\sum_{i=0}^{k} \Delta t_kn_k}{\sum_{i=0}^{k} \Delta t_k} \end{equation}
Please help me check if this solution is correct. Also, I'm wondering that if there is any analytical solution, if so, please let me know. Thank you very much.