JSim – Queue Simulator

      Comments Off on JSim – Queue Simulator

JSim is a Java-based discrete event simulator of an M/M/s queue system. The source includes a library of classes that can be used to modify the application to simulate other types of queue systems as well.

JSim source files can be downloaded from https://sourceforge.net/projects/jsim/. A brief description of the main classes and function can be found next:

SimulationWorker

SimulationWorker is the main class that handles the simulation. You can modify this class to create the queue system of your choice. The following description is for a standard M/M/1 system (v0.2).

JSim allows you to create random variables based on several distributions, including Exponential, Normal, and Uniform  In a M/M/1 queue system, you will need two random variables taken from Exponential distributions for the arrival and service times. To instantiate the objects, you need to pass random seed and mean time to the constructor of the ExpoRandom class.

RandomNumber ta = new ExpoRandom(seed1, lambda);
RandomNumber ts = new ExpoRandom(seed2, mu);

All JSim events are subclass of SimEvent. The main two events that you need are the ArrivalEvent and DepartureEvent. At this point, you need to associate the random number variables created above with these two events by setting the arrival and services rates.

ArrivalEvent.arrivalRate(ta);
DepartureEvent.serviceRate(ts);

SimQueue class collects the simulation statistics, so you need to create an instance of this class.

SimQueue qs = SimQueue.instance();

A Scheduler is a class that manages the scheduling the execution of the simulation events. To kick start the simulation you need to create an ArrivalEvent at time. Unless you want to simulation to indefinitely, you must also create an EndEvent. Both events must be added to the Scheduler inside a try-catch block to protect against adding an event at time that precedes the current simulation time.

sc = Scheduler.instance();
try {
   sc.addEvent(new ArrivalEvent(new Time(0)));
   sc.addEvent(new EndEvent(new Time(simTime)));
}

Once the simulation is run, the subsequent arrival and departure event are added to the Scheduler by the ArrivalEvent and DepartureEvent classes. The Scheduler will execute these events in the proper chronological order. To run the simulation, use

Scheduler.run();

After the simulation concludes, you can use the SimQueue instance, created earlier, to retrieve the statistics.