Collecting statistics on agents
AnyLogic supports a convenient way of collecting statistics for population of agents.
There are several statistics types supported:
Count. Counts agents satisfying the specified
Sum. Iterates through all agents and evaluates the specified
for each agent. Returns the sum of obtained values.
Average. Iterates through all agents and evaluates the specified
for each agent. Returns average of obtained values.
Min. Iterates through all agents and evaluates the specified
for each agent. Returns the minimum obtained value.
Max. Iterates through all agents and evaluates the specified
for each agent. Returns the maximum obtained value.
can be calculated only for those agents, who meet the optional
Condition. Say, we want to calculate the average age of product adopters in agent based
model. Let's assume we have
defined by agent type
in this model. This type has a statechart with
parameter defining the person's age. In this case our statistics should look like the following:
To define new statistics function for a population of agents
- Select the population element in the graphical editor or in the
- Open the
section of the
- Click the
button to create a new section defining one statistics field.
The defined statistics field is accessed in the "function" style: by statistics
followed with parenthesis, i.e. in the example described above, to calculate the defined statistics, call
- Edit the name of the statistics function in the
field. This name is used to identify and access this statistics function.
Choose the type of statistics function using the
group of buttons.
using the controls below. While writing code in these fields, you can access an individual element of a population (an agent) as
- To add more statistics fields, please repeat steps 3-6. If you do not need some statistics any more, you can remove the corresponding section by clicking the