Short explanation of a simulation program with a future event list

Note: This program simulates a user and a server. It uses a simulation framework that could easily be used for modeling other systems.

The program contains the following classes (blue means that the class is part of the simulation framework that can be reused for simulating other systems; green means that some modifications may be required, black means that the class is application-specific):

Explanations

The SimSystem object created by the main program contains the description of the system to be simulated and also contains the list of future events, called future, and the simulation loop which is executed within the constructor of the SimSystem class. In the future event list, the events are ordered according to the scheduled execution time (simulated time).

A scheduled event, in addition to its time indicated when it should be executed, contains the following information: (a) the action, which means what kind of action should be performed when this event is executed; (b) the target, which is a reference of an object that should perform the execution of this action, and some other data. In this example, the other data is used to store an identifier, which represents the number of user request to which this event belongs.

The target object is of type EventHandler which is an abstract class. In this example, there are two types of EventHandlers; they are of type Server or User. Each EventHandler supports a method, called handleEvent(Event e) which performs the execution of the event. These methods are called by the simulation loop in the SimSystem. The SimSystem, itself, is also an EventHandler; it looks after the events that are generated for taking measurement snapshots (in this example, the queue length of the server and the question whether the server is free or busy are recorded in two arrays which are processed when the simulation terminates.

Note that the Server process, when processing the end of a service time (action SERVE_END) may generate a new event with the same identifier to be handled by another Server, if such a server was connected during the contruction process (in this example, the reference to another server is null).

The following is an overview of the actions performed when the different events are processed:


Written March 2010, revised March 2011, March 2016