14.3. Interleaved Agent Simulation

In interleaved agent simulation, the simulator processes a PerceptionEvent by invoking the method onPerceive of the perceiver agent. An agent performs an action, e.g., in response to a perception, by scheduling an ActionEvent that is then processed by the simulator by invoking the agent's perform method.

Likewise, message-based communication is implemented by having the sender agent scheduling a MessageEvent that is then processed by the simulator by invoking the message reception method onReceive of the receiver agent. In this way, a MessageEvent is inserted into the simulation log and it is guaranteed that, as required above, the time when a message is received is later than the time it has been sent (in.occurrenceTime > out.occurrenceTime).

Perception and Action

For supporting perception events and actions, the OEM&S concept Event is extended in the following way:

A conceptual process model in the form of a DPMN diagram

This means that

  1. The pre-defined (abstract) object type Agent has two abstract methods for perception and action:
    1. onPerceive to be invoked with a Percept value, which is a string or a composite value,
    2. perform to be invoked with an Action value, which is a string or a composite value.
  2. There are two pre-defined event types: PerceptionEvent and ActionEvent.
  3. A PerceptionEvent has a percept attribute value and a perceiver reference. The value of a percept attribute may be a string or a composite value.
  4. When a PerceptionEvent occurs, the simulator invokes the perceive method of the perceiver agent and passes the percept attribute value.
  5. An ActionEvent has an action attribute value and a performer reference. The value of an action attribute may be a string or a composite value.
  6. When an ActionEvent occurs, the simulator invokes the perform method of the performer agent and passes the action attribute value.

Message-Based Communication

The following diagram shows the new A/OEM&S elements added to the OEM&S meta-model:

A conceptual process model in the form of a DPMN diagram

This means that

  1. The pre-defined (abstract) object type Agent has the abstract method onReceive to be invoked with a message and a sender reference.
  2. There is a pre-defined event type MessageEvent.
  3. A MessageEvent has a message attribute value, which is a string or a composite value.
  4. When a MessageEvent occurs, the simulator invokes the onReceive method of the receiver agent and passes the message attribute value.

In a distributed simulator for A/OEM&S, where all agents of a simulation scenario run as different processes (on different computers) without a shared simulator state, and, consequently, message passing would be asynchronous, it would be natural to implement both out-message events and in-message events, as described above.

Agent-Based Simulation with OESjs

Typically, a sender agent schedules a MessageEvent within its onPerceive or onReceive methods, that is, in response to a perception or to a message reception. In OESjs-Core4, this could be programmed in the following way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Doctor extends aGENT {
  constructor({ id, name, status}) {
    super( id, name);
    this.status = status;
  }
  onReceive( msg, sender) {
    switch (msg.type) {
    case "ASK": 
      const answer = this.processQuery( msg.query),
            reply = new rEPLY( answer),
            receiver = sender,
            sender = this;
      sim.schedule( new mESSAGEeVENT( reply, sender, receiver));
      break;
    case "REPLY":
      ... 
    }
  }
}

A simulation model may schedule a PerceptionEvent, which is processed by the simulator by invoking the perceive method of the perceiver agent while passing its percept attribute value. An ActionEvent is typically scheduled by an agent within its perceive or receive methods in response to a perception or to a message reception. In OESjs, this could be programmed in the following way:

1
2
3
4
5
6
7
8
9
10
11
12
13
class Doctor extends aGENT {
  constructor({ id, name, status}) {
    super( id, name);
    this.status = status;
  }
  onPerceive( percept) {
    switch (percept) {
    case "CovidSymptom":
      sim.schedule( new aCTIONeVENT("performPCR"));
      break;
    }
  }
}