Collecting statistics on agents

AnyLogic supports a convenient way of collecting statistics for population of agents.

There are several statistics types supported: Count, Sum, Average, Min and Max.

Sum, Average, Min and Max 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 Bass Diffusion model. Let's assume we have people defined by agent type Person in this model. This type has a statechart with PotentialAdopter and Adopter states and age 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

  1. Select the population element in the graphical editor or in the Projects view.
  2. Open the Statistics section of the Properties view.
  3. Click the Add statistics button to create a new section defining one statistics field.

  1. Edit the name of the statistics function in the Name field. This name is used to identify and access this statistics function.
  2. Choose the type of statistics function using the Type group of buttons.
  3. Specify Expression and/or Condition using the controls below. While writing code in these fields, you can access an individual element of a population (an agent) as item.
  4. 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 button.
The defined statistics field is accessed in the "function" style: by statistics Name followed with parenthesis, i.e. in the example described above, to calculate the defined statistics, call peopleStat() statistics function.