The event queue: the simulation engine

Updated: 2025-10-08

The event queue:

At the heart of any discrete-event simulation lies the event queue, a structure that defines how and when entity actions are executed within the model. This discrete-event approach is what distinguishes it from other programming languages.

You can think of it as if each entity had its own program, as you would do in C or Python, but jumping between entities according to the temporal order dictated by this queue. If we simulate 10 entities, there are 10 programs running “at the same time” (or almost).

What is the event queue?

It is a time-ordered list of scheduled actions, each associated with a simulated time instant (AC1). The queue ensures actions are executed in the correct order according to when they must occur.

The most important thing: it is ordered by time. For example:

Time 15 - Serve entity 14 at step 88
Time 45 - Serve entity 22 at step 16
Time 77 - Serve entity 16 at step 25

Example: Evolution of the event queue

Let’s consider the classic case of a bank where customers enter through the door and are served at a counter. Entities are created with GENERATE and spend time being served via ADVANCE.

Imagine we are at instant T = 5, with the following queue:

T 5: Entity 5: Waiting in the counter queue
T 7: GENERATE: Create an item, a customer who will enter through the door
T 8: Entity 9: Heading to the counter queue
T 16: Entity 3: Heading to the counter queue

Right now, we have one entity—#5—which is next in the queue. We will remove that element from the queue to process it. Now we know that time is 5! Not because time has “passed”, but because our next task is scheduled for T=5.

Let’s assume, for example, that Entity 5 is at the “step” (position in its program) that indicates an ADVANCE 10 to be served.

In that case, the solution is to schedule itself in the queue at T=15 (5+10) and pause its execution while it is being served.

Now the event queue will look like this:

T 7: GENERATE: Create an item
T 8: Entity 9: Heading to the counter queue
T 15: Entity 5: Go to the exit
T 16: Entity 3: Heading to the counter queue

We are now at the next event. Time must be updated again: “AC1” now takes the value 7. As we said, it’s not that time has passed; it’s that the event queue makes time jump because there is nothing to do until T=7.

We remove the element from the queue and find a GENERATE 20,5. Therefore, we must compute what time is defined by 20,5; something between 20 and 25. Suppose the result is 22. That is, another person will enter in 22 time units. The queue now takes this form after the GENERATE advances and performs 2 tasks:

1.- The GENERATE itself advances 20 (parameter A) (7+20=27).
2.- It creates a new entity (#10) so it can carry out its tasks 22 time units later (7+22=29).

T 8: Entity 9: Heading to the counter queue
T 15: Entity 5: Go to the exit
T 16: Entity 3: Heading to the counter queue
T 27: GENERATE: Create an item
T 29: Entity 10: Heading to the counter queue

Now it would be time to advance system time again and serve the next element: Entity 9.

This event queue will remain alive until one of the program-ending conditions is met.

In GPSS-Plus, this event queue also has additional characteristics to support tasks in the graphical world and to add “ON_*” type events.

In the GPSS-Plus event queue, we have 5 types of elements:

  • GENERATE – Introduce new entities into the system.
  • Entities – The ones that move through the model and consume resources.
  • Dead times – Visible pauses that allow step-by-step simulation or speed adjustment.
  • Virtual entities – Not visible; execute events such as ON_ENTER, ON_TIMER, etc.
  • System TIMER – Like a GENERATE, but it produces virtual entities at fixed intervals.

Resource queues:

Other existing queues are those belonging to resources; each resource can have one or two depending on the case.

These lists are ordered by arrival order, and their management depends exclusively on the resource itself.

For example, a FACILITY has two lists: the list of occupying entities and the list of entities waiting in queue.

When an entity attempts to SEIZE, if the resource is busy, it moves to the waiting list. If there are no entities in the resource, it will seize it by entering the occupants list.

When it performs RELEASE, it leaves that list and forces the resource to look for an entity in its pending queue to enter. If there is one, it will move it into the occupants list and schedule its entry into the event queue at that same instant, so that entity will take control of the engine as soon as the departing one stops its activity.

Conclusion

The event queue not only defines the order and time at which actions occur, but also acts as the core of the system. It ensures blocks execute correctly and that the simulation is consistent and accurate. Understanding this concept is essential to design efficient models and fully leverage GPSS-Plus capabilities.

In GPSS-Plus it is easy to view this queue: just open the menu window and click the “Event Queue” button.