Messaging

Last updated on 16th July 2024

Messaging Semantics

The Simudyne SDK adopts the Pregel approach to graph processing. This means that all computation is driven by messages. At every action in the sequence, every agent will process its action only if it has received a message.

In addition to this, Pregel adopts a pure message passing model that eliminates the need of shared memory and remote read, so all sharing of information between agents is done by message passing.

Message Types

All messages sent must extend Message. There are a number of ways in which you may do so, each suitable for different scenarios.

Empty Messages

For messages that have no value one can extend Message.Empty. This is useful if your message type alone is sufficient to convey the required semantics.

Single Primitive Type Messages

For messages that contain only a single primitive value, the Simudyne SDK provides Integer, Long, Float, Double, and Boolean message classes that can be extended. They all provide a getBody() method that returns the primitive value. Use this whenever you need to send only one field.

Complex Data Types

For messages that require sending complex data types extend Message.Object<T>. This will allow you to send a message who's body is the object. It also allows the receiver access to methods on the object.

Messages with Arbitrary Fields

If your message needs to send an arbitrary amount of data, but no explicit type exists, consider extending Message.

For organising custom message classes, see Message Organisation.

When running the model in distributed mode, all message types need to be registered with the model. This isn't necessary if running the model locally.

Registering messages

(Java)

public class MyClass extends AgentBasedModel<GlobalState> {
  ...
  registerMessageTypes(Boolean.class, Messages.Vacancy.class);
  ...
}

Advanced Message Manipulation

There are other lower level ways of manipulating messages and action sequencing - please refer to System Messages