AnyLogic
Expand
Font size

Event processing at the simulation engine

AnyLogic simulates the model as a sequence of time steps and event steps.

During a time step:

  • The model clock is advanced.
  • The "discrete" state of the model (the statechart, port, event, etc. states) remains unchanged.
  • Active equations, if any, are being solved numerically and the variables are changed correspondingly.
  • Expected change events are tested for occurrence.

During an event step:

  • No model time elapses.
  • The actions of states, transitions, events, ports, etc. corresponding to this event are executed.
  • The state of the model may change.
  • Some scheduled events may be deleted, and the new events may be scheduled in the AnyLogic Engine event queue.

Engine events

AnyLogic engine events are events that occur at runtime. They are not to be confused with static and dynamic events, which are part of the AnyLogic modeling language.

There are multiple types of engine events:

  • Current — events that can be executed right now
  • Chosen — one of the enabled events that is selected to be executed next
  • Enabled — other current events (those that could potentially be executed next)
  • Scheduled — events that are scheduled to run at a specific known time in the future
  • Pending — events that may occur in the future, but the time is not known

Engine events reside in the engine event queue. Any event in the engine event queue can be associated with:

  • An active static/dynamic event
  • A transition triggered by rate, timeout, or expiration

In addition, current events can be associated with something that has just happened as a result of another event execution:

  • A transition being triggered by a port, or by a message or condition event.

Time step

If there are no current events, AnyLogic takes a time step to the next event (or events) in the queue, that is, advances its clock. During a time step a condition event may occur. The discrete part of the AnyLogic engine does not know when a condition event associated with a transition occurs: it depends on the set of equations being solved numerically by a continuous part of the engine. Once this happens, the clock is advanced to the time reported by the continuous time equation solver and the event step is executed.

Event step

Multiple events can be scheduled to occur at the same moment of time. If there are multiple current events, AnyLogic selects one and executes it. This is repeated until there are no more current events. This allows multiple event steps to be executed sequentially, while a time step is always followed by an event step. Concurrent events can be interdependent or truly concurrent. Serializing concurrent events is called interleaving a model.

The execution of a timer event is actually the execution of the timer’s action code. The execution of a transition event is the execution of a set of actions associated with the transition. As a result of the event execution, the discrete state of the model may change: statecharts may change their states, other transitions may start waiting, and other timers may be activated. Thus, some events may be deleted from the event queue and other events may be added to it.

An example of the AnyLogic event queue processing is demonstrated below.

AnyLogic event queue: example

Pending events are not demonstrated.

AnyLogic: Event queue processing: Step 1

In the first time step, the clock advances to the points representing events A and B at the beginning of the event queue. Active equations are being solved. The event queue remains unchanged.

AnyLogic: Event queue processing: Step 2

In the first event step, event B is selected and occurs. No time has passed. The state of the model changes. Events A, E, and G are deleted from the event queue. Events J and K are scheduled.

AnyLogic: Event queue processing: Step 3

In the next time step, the clock advances to events C and D. Active equations are being solved. Suddenly the change event Q is detected.

AnyLogic: Event queue processing: Step 4

In the next event step, event Q is selected and occurs. No time has passed. The state of the model changes. Events C and K are deleted from the event queue. Event L is scheduled.

AnyLogic: Event queue processing: Step 5

In the next time step, the clock advances to event D…

How can we improve this article?