Event Scheduling

Multiple events may take place at the same time during simulation. In this case AnyLogic arranges the events according to the Selection mode for simultaneous events that is set for the current experiment:

While the Random selection mode is self-explanatory, i.e. the execution order is not regulated, the FIFO and LIFO modes may require clarification, since the order of the events depends on the way AnyLogic initializes the model and processes the schedules of the events.

To better understand FIFO and LIFO selection modes, keep the following in mind:

Let us consider two examples to illustrate the ordering principles. In these examples, each model starts at the T = 0 moment of time and progresses through a series of T = 1, T = 2, etc. moments. Every such moment represents the time (measured in the specfied model time units) that has passed since the model launch.

Example A

We will assume that a model has the following conditions:

FIFO mode

In the FIFO mode events run in the following order : A, B, A, B, A, B, A, B.

Simulation time

Actions

Events Schedule

T = 0

A schedules itself for T = 1

T = 1: A

B schedules itself for T = 1

T = 1: A, B

T = 1

A (first queue element) runs and schedules itself for T = 2

T = 1: B
T = 2: A

B runs and schedules itself for T = 2

T = 2: A, B

T = 2

A (first queue element) runs and schedules itself for T = 3

T = 2: B
T = 3: A

B runs and schedules itself for T = 3

T = 3: A, B

LIFO mode

In the LIFO mode events run in the alternating order: B, A, A, B, B, A, A, B.

Simulation time

Actions

Events Schedule

T = 0

A schedules itself for T = 1

T = 1: A

B schedules itself for T = 1

T = 1: A, B

T = 1

B (last queue element) runs and schedules itself for T = 2

T = 1: A
T = 2: B

A runs and schedules itself for T = 2

T = 2: B, A

T = 2

A (last queue element) runs and schedules itself for T = 3

T = 2: B
T = 3: A

B runs and schedules itself for T = 3

T = 3: A, B

Example B

We will assume that our model has the following conditions:

FIFO mode

The events end up running in this order: E5, E3, E4, E1, E2.

Simulation time

Actions

Events Schedule

T = 0

E1 schedules itself for T = 1

T = 1: E1

E2 schedules itself for T = 1

T = 1: E1, E2

E3 schedules itself for T = 2

T = 1: E1, E2
T = 2: E3

The data set is updated (AU) and schedules its next update for T = 1

T = 1: E1, E2, AU
T = 2: E3

T = 1

E1 (first queue element) runs. It creates the C agent instance, which initializes E4 and E5:

  • E4 schedules itself for T = 2.
  • E5 schedules itself for T = 3.

E1 has finished processing, so it schedules itself for T = 2.

T = 1: E2, AU
T = 2: E3, E4, E1
T = 3: E5

E2 runs and schedules itself for T = 2

T = 1: AU
T = 2: E3, E4, E1, E2
T = 3: E5

The data set is updated (AU) and schedules its next update for the T = 2

T = 2: E3, E4, E1, E2, AU
T = 3: E5

T = 2

E3 runs (first queue element) and schedules itself for T = 3

T = 2: E4, E1, E2, AU
T = 3: E5, E3

E4 runs and schedules itself for T = 3

T = 2: E1, E2, AU
T = 3: E5, E3, E4

E1 runs and schedules itself for T = 3

T = 2: E2, AU
T = 3: E5, E3, E4, E1

E2 runs and schedules itself for T = 3

T = 2: AU
T = 3: E5, E3, E4, E1, E2

The data set is updated (AU) and schedules its next update for the T = 3

T = 3: E5, E3, E4, E1, E2, AU

LIFO Mode

The events end up alternating running in these orders:

Simulation time

Actions

Events Schedule

T = 0

E1 schedules itself for T = 1.

T = 1: E1

E2 schedules itself for T = 1.

T = 1: E1, E2

E3 schedules itself for T = 2.

T = 1: E1, E2
T = 2: E3

The data set is updated (AU) and schedules its next update for the T = 1.

T = 1: E1, E2, AU
T = 2: E3

T = 1

The data set is updated (AU - last in queue), and schedules its next update for the T = 2.

T = 1: E1, E2
T = 2: E3, AU

E2 runs and schedules itself for T = 2.

T = 1: E1
T = 2: E3, AU, E2

E1 runs. It creates the C agent instance, which initializes E4 and E5:

  • E4 schedules itself for T = 2.
  • E5 schedules itself for T = 3.

E1 has finished processing, so it schedules itself for T = 2.

T = 2: E3, AU, E2, E4, E1
T = 3: E5

T = 2

E1 runs (last queue element) and schedules itself for T = 3.

T = 2: E3, AU, E2, E4
T = 3: E5, E1

E4 runs and schedules itself for T = 3.

T = 2: E3, AU, E2
T = 3: E5, E1, E4

E2 runs and schedules itself for T = 3.

T = 2: E3, AU
T = 3: E5, E1, E4, E2

The data set is updated, and schedules its next update for T = 3.

T = 2: E3
T = 3: E5, E1, E4, E2, AU

E3 runs and schedules itself for T = 3.

T = 3: E5, E1, E4, E2, AU, E3