[back to assignments]

# Queue Simulator

## CS 350 - March 2, 2009

### Objectives

The purpose of this project was to design a discrete event simulator for a queueing system. The simulator consisted of two parts: (1) a controller, and (2) a simulated system with inter-arrival and service time of events that were dependent upon user-chosen probability distributions. The simulator was required to make use of a linked-list for infinitely long queues and had to accurately simulate event actions based on queue state, arrival rate, and service rate of the queueing system.

### Methods

I coded a simple queueing simulator that is capable of modeling M/M/1, M/M/1/K, M/G/1, M/D/1, and M/x/1 queueing systems. My queue simulator allowed the user to define the event inter-arrival rate and service rate for each simulation, and also allowed users to select a queue size (zero to infinity) and a running time for the simulation. For M/G/1 and M/x/1 simulations, users had the ability to input standard deviations for both inter-arrival and total queue service times.

### Probability Distributions

I implemented probability functions which served to model the inter-arrival and service times associated with the five simulated queueing systems. These probability functions were polled during the simulation in order to give an accurate distribution of random variables according to each model.

The probability distributions modeled are:

 Mnemonic Distribution Type Random Function M Exponential distribution (Markovian) V = - ln(1-U)/lambda D Constant value (Deterministic) Always returns the mean U Uniform distribution drand48() N Normal distribution Central Limit Theorem

#### Simulator Results

'%' Represents Percentage Dropped
 SystemParameters AnalyticalM/M/1/KK = 5 SimulatedM/M/1/KK = 5 AnalyticalM/M/1 SimulatedM/M/1 λ = 100Ts = 0.005 Tq: 0.01 Tw: 0.005 w: 0.5 q: 1 %: 0.00000 Tq: 0.0099 Tw: 0.0048 w: 0.4827 q: 0.9888 %: 0.0079 Tq: 0.01 Tw: 0.005 w = 0.5 q = 1 %: 0.00000 Tq: 0.0101 Tw: 0.005 w: 0.5160 q: 1.0240 %: 0.0000 λ = 100Ts = 0.01 Tq: 0.035 Tw: 0.025 w: 2.2 q: 3 %: 0.15 Tq: 0.0353 Tw: 0.0252 w: 2.1996 q: 3.0609 %: 0.1431 Tq: 1 Tw: 0.99 w: 100 q: 105 %: 0 Tq: 1.0146 Tw: 1.004 w: 100.246 q: 101.246 %: 0.0000 λ = 50Ts = 0.03 Tq: 0.15 Tw: 0.12 w: 3.5 q: 4 %: 0.35 Tq: 0.1344 Tw: 0.1047 w: 3.4207 q: 4.3886 %: 0.3413 Tq: 0.15 Tw: 0.12 w: 3.5 q: 38 %: 0 Tq: 15.539 Tw: 15.51 w: 765.467 q: 766.467 %: 0.0000

 SystemParameters AnalyticalM/G/1σ = 0 SimulatedM/D/1 AnalyticalM/G/1 σ = ¼Ts SimulatedM/x/1, wherex=Uniform Ts ± ¼√3 * Ts SimulatedM/x/1, wherex=Normal σ = ¼Ts λ = 100Ts = 0.005 Tq: 0.01 Tw: 0.005 w = 0.5 q = 1 %: 0.0000 Tq: 0.0076 Tw: 0.003 w: 0.2576 q: 0.7567 %: 0.0000 Tq: 0.01 Tw: 0.005 w = 0.5 q = 1 %: 0.0000 Tq: 0.0080 Tw: 0.0030 w: 0.3021 q: 0.8125 %: 0.0000 Tq: 0.0098 Tw: 0.005 w: 0.4453 q: 0.9712 %: 0.0000 λ = 95Ts = 0.01 Tq: 0.20 Tw: 0.19 w = 18.05 q = 19 %: 0.0000 Tq: 0.0766 Tw: 0.066 w: 6.2271 q: 7.1625 %: 0.0000 Tq: 0.22 Tw: 0.21 w = 18 q = 19 %: 0.0000 Tq: 0.1199 Tw: 0.1099 w: 10.5206 q: 11.4800 %: 0.0000 Tq: 0.3883 Tw: 0.377 w: 35.8761 q: 36.8672 %: 0.0000

### Final Thoughts

Judging by simulator results vs. analytical results, my simulator performed well in modeling the behaviors of different queueing systems. This project has been immensely beneficial to my understanding of how queueing systems function, and I'll doubtlessly be referring back to this work in the near future as I search for an adequate queueing system for use in my semester research project.

### Code

Queue Simulator
[To be posted to the public once grades are returned]