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.
- Awaited 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.
AnyLogic engine events are events that occur at runtime. Please do not confuse them with static/dynamic events that are a part of AnyLogic modeling language. There are several types of engine events:
- current – events that can be executed at the time now
- chosen – one of the enabled events that is chosen to be executed next
- enabled – other current events (those that potentially could be executed next)
- scheduled – events scheduled at some particular 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 present in the engine event queue may be associated with:
- an active static/dynamic event
- a transition triggered by rate or on a timeout or expiry
In addition, current events may be associated with something that has just happened as a result of other event execution:
- a transition being triggered by a port, or by message or condition event.
If there are no current events, AnyLogic makes a time step to the nearest event (or events) in the queue, i.e., advances its clock. During a time step a condition event may occur. The discrete part of AnyLogic engine does not know when a condition event associated with a transition occurs: it depends on the equation set 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.
Several events may be scheduled to occur at the same moment of time. If there are several current events, AnyLogic chooses one and executes it. This is repeated until there are no current events. Thus, several event steps may be made in succession, whereas a time step is always followed by an event step. Simultaneous events may depend on each other or be truly concurrent. The serialization of 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 begin 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.
The example of AnyLogic event queue processing is shown in the figure below.
How can we improve this article?