Skip to the content of the web site.

M/D/1

This is a simulation of a M/D/1 system. Events arrive with a mean arrival rate of LAMBDA per unit time and they are serviced at rate of MU per unit time. These parameters may be set in the code; the current values are those used in the course slides with a unit time of seconds.

First, we generate the arrival times of all of the processes. As these are to be independent, they must follow a Poisson distribution with a parameter LAMBDA. As such, the distribution of the intervals between the arrivals will follow an exponential distribution with the same parameter, LAMBDA.

In order to generate a random variable that follows an exponential distribution with a parameter LAMBDA, it is necessary generate a random number tex:$$x$$ on tex:$$(0, 1]$$ (drand48() generates one in tex:$$[0, 1)$$, so 1 - drand48() gives us the desired value) and then calculate tex:$$-\frac{ln(x)}{\lambda}$$.

Next, we validate that the data is actually approximately Poisson as expected. Thus, for each time interval, we count the number of arrivals that occur in it and tabulate these. The proportion that have tex:$$n$$ arrivals should have the distribution tex:$$\frac{\lambda^n}{n!}e^{-\lambda}$$. The table that is printed compares the actual distribution with the theoretical.

Next, we run the simulation.

Finally, we look at all the events and calculate the average time spent in the system and compare this value with the expected mean time in the system.

One such run is shown here:

% gcc -lm simulation.c
% ./a.out 
0       0.242882 0.242521
1       0.343803 0.343572
2       0.240641 0.243363
3       0.115986 0.114921
4       0.041835 0.040701
5       0.011477 0.011532
6       0.002795 0.002723
7       0.000468 0.000551
8       0.000099 0.000098

Expected mean time in the system:  6.226805
Actual average time in the system: 6.507858

You will note the distribution is very close to the expected Poisson distribution (for example, 24.29% of the one-second intervals had no arrivals occurring during that second and this is very close to the expected 24.25% of the one-second intervals). Similarly, the calculate of the mean time in the system using the formula tex:$$\frac{2 - \rho}{2\mu(1 - \rho)}$$ is also reasonably close to the average time in the system for the simulation.