Agents & Network/Graph

Last updated on 22nd April 2024

Agents

An agent is an abstract representation of a real-world entity. This could be a person, place, business, organization, country, etc.

Agents have behaviours and interact with other agents. These sets of non-linear interactions, over time, can produce emergent phenomena, like herding in a financial market or the spread of an infectious disease across a population.

Agents in the Simudyne SDK are autonomous components capable of interacting with other agents and reacting to changes in their environment.

Interactions between agents are accomplished via a message passing framework. Agents communicate with one another by sending and receiving messages that share information or trigger state changes within the agents.

Agents contain the necessary functionality to store information, send and receive messages, create or remove connections to other agents, and even spawn other agents.

Below is an example of a skeleton structure of an Agent class with a dummy message pass phase set up between simple agents:

SimpleAgent.java

import simudyne.core.abm.Action;
import simudyne.core.abm.Agent;
import simudyne.core.annotations.Variable;

public class SimpleAgent extends Agent<Globals> {

    @Variable
    public int variable1;

    @Variable
    public int variable2;
    
    public static Action<SimpleAgent> sendMessage =
            Action.create(SimpleAgent.class, simpleAgent -> {
              simpleAgent.getLinks(Links.SimpleAgentLink.class).send(Messages.BroadcastMessage.class, msg -> {
                  msg.value = simpleAgent.variable1;
              });
            });

    public static Action<SimpleAgent> receiveMessage =
            Action.create(SimpleAgent.class, simpleAgent -> {
               simpleAgent.getMessagesOfType(Messages.BroadcastMessage.class).forEach(msg -> {
                   simpleAgent.variable2 += msg.value;
               });
            });
}

Networks

Networks between agents are representative of real-world relationships and communication.

Agents can have very simple or complex networks that define their relationships.

In the Simudyne SDK, these relationships are represented as a network built of Links. Links are a fundamental component of an ABM as they form the structure of the network.

When two agents are connected via Links, they are able to pass messages across those links, or store information on the link that both parties can access.

The Simudyne SDK implements numerous graph generation algorithms for building specific network / link structures between agents in the system. Multiple different complex network structures can exist simultaneously, connecting populations of agents in a manner that best represents reality.

Links can also be added and removed during runtime, resulting in a dynamic network as the system evolves.

Below is an example of a simple model class where agents are generated and then connected to one another using one of the Simudyne SDK graph generation functions:

SimpleModel.java

import simudyne.core.abm.AgentBasedModel;
import simudyne.core.abm.GlobalState;
import simudyne.core.abm.Group;
import simudyne.core.annotations.Input;

public class SimpleModel extends AgentBasedModel<Globals> {

    public static final class Globals extends GlobalState {

        @Input(name = "Number Simple Agents")
        public long nbSimpleAgents = 100;

        @Input(name = "Starting Value")
        public int valueStart = 100;

        @Input(name = "Send Value ")
        public int value = 1;

    }

    @Override
    public void init() {
        registerAgentTypes(SimpleAgent.class);
        registerLinkTypes(Links.SimpleAgentLink.class);
    }

    @Override
    public void setup() {

        Group<SimpleAgent> simpleAgentGroup = generateGroup(SimpleAgent.class, getGlobals().nbSimpleAgents, simpleAgent -> {
            simpleAgent.variable1 = getGlobals().valueStart;
        });

        simpleAgentGroup.fullyConnected(simpleAgentGroup, Links.SimpleAgentLink.class);

        super.setup();
    }

    @Override
    public void step() {
        super.step();

        run(SimpleAgent.sendMessage, SimpleAgent.receiveMessage);

    }
}

More on Agent creation, connections, and communication can be found in the Agents section