AnyLogic
Expand
Font size

Agent

Agents may represent very diverse things: vehicles, units of equipment, projects, products, ideas, organizations, investments, pieces of land, people in different roles, etc.

Agents are main building blocks of AnyLogic model. Agent is a unit of model design that can have behavior, memory (history), timing, contacts, etc.

Within an agent you can define variables, events, statecharts, System Dynamics stock and flow diagrams, you can also embed other agents, add process flowcharts. You can define as many agent types in your model as there are different types of agents.

Design of an agent typically starts with identifying its attributes, behavior, and interface with the external world. In case of large number of agents with dynamic connections (such as social networks) agents can communicate by calling functions.

The agent internal state and behavior can be implemented in a number of ways. The state of the agent can be represented by a number of variables, by the statechart state, etc. The behavior can be so to say passive (e.g. there are agents that only react to message arrivals or to function calls and do not have their own timing), or active, when internal dynamics (timeouts or system dynamics processes) of the agent causes it to act. In the latter case agents most probably would have event and/or statechart objects inside.

Embedded agents

Agents may embed other agents to any desired depth. Embedded objects are instances of other agent types, embedded by each instance of this agent type. Embedding is the step to create the model hierarchy. By default embedded objects are displayed simply as icon. But if you have drawn an icon for this agent type, this icon will be shown instead of the default one. Besides of shapes marked as icon shapes, icon also includes public ports and system dynamic variables.

Populations

Agent type can represent a single agent or a population of agents. A population represents a collection of agents of the same type.

At the top of the properties page of the agent population you can see the name of the agent type.

Creating agents

Agent is an instance of an agent type. Agent types are developed by the user. You create agents using the New Agent wizard that opens when you drag the Agent element from the Agent palette on the diagram. On the first page of the wizard you choose whether you want to create a population of agents, just one agent, or only define the agent type and do not create any agents of this type as yet.

Below, you can see the properties of an agent type.

Properties

General

Name — The name of the agent type.

Since AnyLogic generates Java class for each agent type, you should follow Java naming guidelines. Please start name with an uppercase letter.

Ignore — If selected, the agent type is excluded from the model.

Parameters preview

Parameters preview properties are available only when this agent type has any parameters.

Here you can rearrange parameters of this agent. Agents of this type will list parameters in their property view in this well-defined order.

Agent actions

On startup — Code to be executed after all agents throughout the whole model are constructed, connected, and initialized, and before anything else is done. This is a place for some additional initialization and starting agent’s activities such as events. The order of execution of On startup code of different agents is not guaranteed.

On destroy — Code to be executed on destroying agent of this type (e.g. when the user terminates the experiment and the root object is destroyed, On destroy code of embedded agents are executed in some order).

On arrival to target destination — Code to be executed when the agent arrives at the destination.

On before step — Code to be executed for this agent before a step is taken in agent-based model with synchronization. On before step actions are executed for agents in some deterministic order.

On step — Code to be executed for this agent on taking a step in agent-based model with synchronization. On step actions are executed for agents in some deterministic order.

Agent in flowcharts
This section of properties is visible if the Flowchart block property in the Advanced section is not selected.

Use in flowcharts as — Here you choose the role for this agent in the flowcharts. The possible options are: Agent, Resource Unit, Material Item, Transporter, Pedestrian, Rail Car, Train, Car.
Depending on the chosen role, you will obtain access to role-specific API which extends beyond the API of a generic agent type.
By selecting Agent here, you enable the agent to pass through the Process Modeling Library flowcharts.
By choosing Pedestrian, you enable the agent to move through Pedestrian Library flowchart blocks and expose pedestrian-specific functions: getComfortableSpeed(), getDiameter(), getTargetX(), etc.
If you choose Transporter, you can use this agent as a transporter in Material Handling Library flowcharts and obtain transporter-specific functions like getFleet(), getUtilization(), getCargoPosition(), and so on.
If you do not expect agents of this type to go through any flowcharts in your model, just leave the default Agent option selected.

On enter flowchart block — Here you can write the code to be executed when this agent enters the flowchart.

On exit flowchart block — Here you can write the code to be executed when this agent exits the flowchart.

On seize resource — Here you can write the code to be executed when this agent seizes the resource while being in the flowchart.

On release resource — Here you can write the code to be executed when this agent releases the resource while being in the flowchart.

Dimensions and movement
This section of properties is visible if the Flowchart block property in the Advanced section is not selected.

Length — [Visible if the Use in flowcharts as property in the Agent in flowcharts section is set to Material Item or Transporter] The length of the material item or transporter.

Width — [Visible if the Use in flowcharts as property in the Agent in flowcharts section is set to Material Item or Transporter] The width of the material item / transporter.

Height — [Visible if the Use in flowcharts as property in the Agent in flowcharts section is set to Material Item or Transporter] The height of the material item / transporter.

Initial speed — The speed of the agent.

Rotate animation towards movement — If selected, the agent shape will be automatically turned towards the target during the agent movement.

Rotate vertically (incline on ramps) — If selected, the agent shape will also automatically incline forward/backward during the agent movement along inclined planes.

Space and network

Agents in the space — Here you can select checkboxes in the list of agents that will live in this space.

Space type — [Enabled if there is no GIS map on the agent type diagram and GIS Space type is not set] The group of buttons, specifying the type of space:

  • Continuous — Continuous space. The space dimensions are specified using the Width and Height properties. The continuous space allows the user to set and retrieve the current agent location, to move the agent with the specified speed from one location to another, etc. Location of an agent in continuous space is defined by coordinates (x,y,z) of Java type double.
  • Discrete — Discrete space. The space is defined with a rectangular array of cells. Cells can be fully or partially occupied by the agents (at most one agent in one cell). AnyLogic support for this kind of space includes agent distribution over the cells, moving to a neighboring cell or jumping to arbitrary cell, finding out who are the agent’s neighbors, etc.
  • When you add a GIS map onto the agent's graphical diagram, the space automatically switches to GIS. GIS space allows placing agents into geospatial environment defined with a GIS map.

Layout type — [Enabled if Discrete or Continuous Space type is chosen] Defines the layout type (the way agents are initially located in the space).
AnyLogic supports the following standard continuous layouts:

  • User-defined — assumes you will take care of the agent locations yourself in e.g. Startup code of the Main object.
  • Random — an agent location is chosen randomly and uniformly within the space dimensions.
  • Arranged — the agents are arranged within the space dimensions.
  • Ring — the agents are uniformly distributed on a ring whose diameter is smaller than the smallest space dimension.
  • Spring mass — the agents are located as a spring mass system where agents are masses and their connections are springs. This is network-dependent layout type.

Width — [Invisible if Continuous space type and User-defined layout is chosen] The horizontal dimension of the area visualizing the space on presentation (in pixels). In discrete space, cell width is calculated by dividing the specified Width by number of Columns in the space.

Height — [Invisible if Continuous space type and User-defined layout is chosen] The vertical dimension of the area visualizing the space on presentation (in pixels). In discrete space, cell height is calculated by dividing the specified Height by number of Rows in the space.

Columns — [Visible if Discrete Space type is chosen] The number of columns in discrete space.

Rows — [Visible if Discrete Space type is chosen] The number of rows in discrete space.

Neighborhood type — [Visible if Discrete Space type is chosen] Sets a neighborhood model, that determines the way the agent neighbors are defined in the discrete space. There are two options:

  • Moore (8 neighbors) — The neighbors are counted in all 8 cells (to the north, south, east, west, northeast, southeast, southwest).
  • Euclidean (4 neighbors) — The neighbors are counted in 4 cells (to the north, south, east, west) only.

Connection network type — [Enabled if Continuous, or Discrete Space type is chosen] The network type, defining how the agents are connected. This standard network does not mean the agents cannot have other connections. You are free to define any kind of relationships between agents and store and manage the corresponding references.
AnyLogic supports the following types of agent networks:

  • User-defined — assumes you will take care of the agent connections yourself in e.g. On startup code of the Main object.
  • Random — agents are connected randomly with a given average number of connections per agent.
  • Distance-based — any two agents are connected if distance between them is less than a given maximum (in continuous space only).
  • Ring lattice — agent connections form a ring where an agent is connected to a given number of closest agents.
  • Small world — can be considered as ring lattice where some links have been “re-wired” to long-distance agents.
  • 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.

Connections per agent — [Enabled if Connection network type is Random, Small world, or Ring lattice] The average (or exact) number of connections per agent. Applies to random, ring lattice and small world networks.

Connection range — [Enabled if Connection network type is Distance based] Defines the radius of the connection area for the agent. The agent will be connected to all agents, who are within a radius of defined Connection range.

Neighbor link fraction — [Enabled if Connection network type is Small world] Parameter for Small world network type.

M — [Enabled if Connection network type is Scale free] Parameter for Scale free network type: either M and M0 (start number of hubs). For details, please refer to Wikipedia.

Enable synchronous steps — If selected, agent-based modeling is synchronous. Synchronous modeling assumes discrete time steps and agents (and maybe space) executing their actions synchronously at these time steps.

Synchronous steps are applied only to the agents and agent populations that are selected in the Agents in the space list above.
By adding such synchronization you do not restrict the dynamics of your model with discrete time steps. Your agents as well as other objects are still able to schedule events, execute state transitions and run other processes — this will go in parallel with steps execution.
You can customize the step duration using the Step duration property. Space actions are defined using the On before step and On after step properties below.

Step duration (in model time units) — [Enabled if Enable synchronous steps is selected] This property enables the user to set some custom step duration in the case of synchronous modeling (the default step duration is 1 model time unit).

Advanced Java

Imports section — import statements needed for correct compilation of the class code. When Java code is generated, these statements are inserted before definition of the Java class.

Implements (comma-separated list of interfaces) — Comma-separated list of interfaces implemented by the class.

Additional class code — Arbitrary member variables, constants, and functions are defined here. This code will be inserted into the class definition. You can access these class data members anywhere within this agent. The functions can be called on some agent activity; e.g., on event occurrence or on triggering statechart transition. You can place any Java code here, however, we recommend to use the Java class element instead of defining nested classes here, and use option lists instead of defining Java enumerations.

Parameterized type — If selected, you can define generic parameters for this agent type in the Type parameter field below.

Advanced

Extends other agent — One agent type may extend some other agent type. This feature gives you an ability to expose the functionality common for agents of different types into one place, “base agent type”. All agent types that extend the same “base agent type” will share this functionality.

Flowchart block — When you develop your own library in AnyLogic, you define flowchart blocks as agents. Here you can mark the agent type that will define a flowchart block for your library. If the option is selected, it will hide the redundant fields from the properties of the flowchart blocks of this agent type (namely, Dimensions and movement, Initial position and Statistics properties sections). It will also hide the Agent in flowcharts and Dimensions and movement properties sections of the agent type itself.

Log to database — If selected, all information about agents of this agent type (their parameter values, statistics on movement and time spent in different states, etc.) will be saved into the model execution log (if logging is turned on in the model’s Database properties).

Create datasets for dynamic variables — If selected, AnyLogic creates datasets for all dynamic variables (stock, flow, and dynamic variables), contained in this agent type and collects the well-defined number (specified in the Limit the number of data samples up to first ... items property) of latest samples of these variables in these datasets. Samples collection will start at either First update time (absolute), or at the Update date if you select Use calendar dates to define the first update time. Samples are collected with the specified Recurrence time that you can set up below.
If this option is not set, the user needs to create dataset for each dynamic variable by himself.

Recurrence time — [Enabled if Create datasets for dynamic variables is set] Defines the recurrence time for collecting samples of dynamic variables.

Limit the number of data samples — [Enabled if Create datasets for dynamic variables is set] Defines the number of samples stored in each dataset automatically created by AnyLogic for dynamic variable.

Create toString() function with parameters — toString() function is used to display information about the agent in the inspect window during model run. By clicking this button you will create toString() function in your agent type. If your agent type has any parameters, this function will automatically return the names of these parameters and their values. To customize the output, specify whatever you want this function to return in the Function body field of the function's properties. For more information on functions in AnyLogic, refer to the Function article.

The function will appear on the agent's graphical editor beyond the visible area. You will find it to the left of the axis origin.
How can we improve this article?