Skip to content

agent_types

Statecharts run for every agent of a population: parameters, states, transitions.

In the model file this key holds a list of agent_type entries, each named by its name.

A scenario, an experiment or an optimizer can set a field by the path agent_types.<name>.<field>.

Typical uses

These sections add agent-based modelling. An agent_type is a statechart: attributes, states and the transitions between them. A population is a number of agents of one type, with an initial placement. Use them for individuals that decide and interact, such as people in an epidemic, drivers or machines with their own behaviour.

Behaviour and rules

A transition has exactly one trigger: a timeout, a rate, a condition, a message or a tick. A rate must be shared by all agents, own to the agent, or a product of the two. A rate that changes continuously with time is refused. A condition or rate that reads model state outside the agents is re-checked only at agent events, unless it sets scan.

A population has a count and can have a max_count. A spawn into a full population stops the run with an error. The agents live in a space that is continuous, a grid or a network. The functions that read neighbours need a space of the matching kind. Agents can be linked to each other.

A CREATE block with population set gives each entity an agent. A SEND block or a send action delivers a message that a message transition waits for. A message nobody sends is reported by a check. Each agent draws random numbers from its own stream, so one agent's draws do not depend on the others.

Fields

Field Type Required Default Unit Description
name string yes The agent type's name, the type of a population.
description string What the agents of this type are; the run does not read it.
parameters object Named numbers every agent of the type reads in its expressions.
attributes list of object The columns each agent carries, with their starting values.
states list of agent state yes The statechart's states, with the actions they run on entry and exit.
transitions list of agent transition The moves between states and what triggers each.
initial_state string The state every agent starts in.
space null or object Where the agents live: nowhere, a continuous plane, a grid or the model's network.
speed string or number "1" speed (speed_unit) An expression (self, parameters, constants) a move_to evaluates once, in the space's own units per time unit.
speed_unit string "base" Unit speed is in.
tick agent tick A fixed-step schedule, ticks at phase + k * dt (k an integer, strictly after the run start). synchronous: every agent reads the tick-start state (on_tick for all, then tick transitions for all); random: a fresh permutation per tick; sequential: index order. A population's keys override its type's.
let object Tick-local values, {name: expression}, evaluated in order once per agent per tick before on_tick; read as a bare name by on_tick and the tick transitions.
on_tick list of agent action Actions every agent runs at each tick, before its tick transitions.
python string Def statements only; {python: <fn>} actions call fn(agent, api). Parsed at validation, never run there; a run needs the caller's consent (NAGASIM_ALLOW_AGENT_PYTHON=1).

A field of a nested object is described in the JSON Schema (naga schema).

Example

{"agent_types": [{"name": "Person", "states": [{"name": "Healthy"}, {"name": "Sick"}], "initial_state": "Healthy"}]}

In the Python builder:

from nagasim import build as nb
m = nb.Model()
m.add_agent_type(name='Person', states=[{'name': 'Healthy'}, {'name': 'Sick'}], initial_state='Healthy')

Used in

Bundled models: Boids flock (continuous, heading), Nagel-Schreckenberg traffic (ring), Schelling segregation (grid), SIR on a small-world network, Sugarscape with regrowth (grid, patches), Wolf-Sheep predation with grass (grid) and 8 more.

Guides: Agent-based modelling, Semantic diff, Coming from AnyLogic, Coming from Mesa, Coming from NetLogo, How do I let an agent read the agents it is linked to? and 2 more.

See also