Font size

Standard agent contacts network

The interaction of agents in agent based models can be implemented in many different ways. If relations between agents are more or less persistent, an agent needs to remember one or several other agents. The meaning of these relations can be e.g.: friend, colleague, parent, child, owner, etc.

Lists of connections are used when agent sends message to its contacts, see Agent communication.

For "flat" relation types such as friends, social contacts, etc. AnyLogic has built-in support. Any agent can have a number of connections — references to other agents in the same environment. If you need to create more networks of connections, you can add more links to agents.

The standard connections are setup automatically by the environment.

Standard network types

Several types of agent networks are directly supported by AnyLogic. They are:

  • Random (Agent.NETWORK_RANDOM) — agents are connected randomly with a given average number of connections per agent.
  • Distance based (Agent.NETWORK_ALL_IN_RANGE) — any two agents are connected if distance between them is less than a given maximum (in continuous space only).
  • Ring lattice (Agent.NETWORK_RING_LATTICE) — agent connections form a ring where an agent is connected to a given number of closest agents.
  • Small world (Agent.NETWORK_SMALL_WORLD) — can be considered as ring lattice where some links have been "re-wired" to long-distance agents.
  • Scale free (Agent.NETWORK_SCALE_FREE) — some agents are "hubs" with a lot of connections and some are "hermits" with few connections. Scale free network is constructed according to Barabasi, A. L. and R. Albert. 1999. Emergence of scaling in random networks. Science 286(5439): 509-512. For details please refer to Wikipedia.

The network types and parameters are set at the environment.

To define the network type

  1. Open the Space and network section of the properties of the environment agent type where your agents live (e.g. Main).
  2. Choose the required network type from the Network type drop-down list.
  3. If you wish this network to be constructed when the model starts, check the Apply on startup checkbox.
  4. Below, specify the network parameter(s) that apply.
Demo model: Agent Network and Layouts Demo Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).

Managing connections dynamically

The connections can be managed manually via agent functions. The API related to connections is the following:

Function Description
List<Agent> getConnections() Returns the list of all connected agents, or null if there have been no connections established.
int getConnectionsNumber() Returns the number of connected agents.
Agent getConnectedAgent(int index) Returns the connected agent with the given index.
connectTo(Agent a) Adds a given agent to the connections of this agent and vice versa.
boolean isConnectedTo(Agent a) Tests whether this agent is connected to a given agent. Returns true if the agent is connected to the agent specified as the function argument, and false — otherwise.
boolean disconnectFrom(Agent a) Disconnects this agent from a given other agent, returns false if the agents were not connected.
disconnectFromAll() Disconnects the agent from all other agents.
int disconnectByCondition(condition) Disconnects this agent from other agents that satisfy the given condition. Returns the number of disconnected agents.


vipClients.disconnectByCondition( p -> p.expenses < 10000 );

Here we disconnect the vipClients agent from the agents whose expenses value is less than 10000.

The network type can be set dynamically during simulation via the environment API, for example if agents live in Main:

main.setNetworkRingLattice( 5 ); //this will just set the default type of network, the agents will not get (re)connected
main.applyNetwork(); //this will (re)connect the agents according to the network type currently set.
How can we improve this article?