Runtime Concepts
GAMA initializes agents and populations, then steps scheduled agents through their update and behavior sequence. The order matters when a model depends on initialization or scheduling behavior; the sections below summarize these runtime concepts.
Simulation initializationβ
Launching an experiment creates an experiment agent, which manages its simulation agents. Each simulation has a world agent. GAMA initializes the world attributes, including shape, and executes the world speciesβ init behavior. The world then initializes its micro-populations, including any grid populations. Use the world init behavior to create other regular species agents when the model requires them.
Agents Creationβ
Except for grid agents, other agents are created using the create statement. It is used to allocate memory for each agent and to initialize all its attributes.
If no explicit initialization exists for an attribute, it will get the default value corresponding to its type.
The initialization of an attribute can be located at several places in the code; they are executed in the following order (which means that, if several ways are used, the attribute will finally have the value of the last applied one):
- in the attribute declaration, using the
initor<-facet. - using the
from:orwithfacet of thecreatestatement. - in the
initblock of the species. - in the embedded block of the
createstatement.
Agents Stepβ
In the default agent step, GAMA:
- update its variables (facet
updatein the variable declaration), - run its behaviors (reflex, state...),
- step its micro-agents (if any).
Step sequence (pseudocode, not GAML):
step of agent agent_a
{
species_a <- agent_a.species
architecture_a <- species_a.architecture
ask architecture_a to step agent_a {
ask agent_a to update species_a.variables
ask agent_a to run architecture_a.behaviors
}
ask each micro-population mp of agent_a to step {
list<agent> sub-agents <- mp.compute_agents_to_schedule
ask each agent_b of sub-agents to step //... recursive call...
}
}
The default architecture is one way to organize agent behavior. A model that needs a different step sequence can:
- redefine the
_step_action of the species, in order to explicit how the agents will behave, - implement no behavior in the species (but only
action). The execution of agents can thus be controlled from a reflex of theglobalthat can control the execution of each of them.
Schedule Agentsβ
The global scheduling of agents is then simply the application of this previous step to the experiment agent, keeping in mind that this agent has only one micro-population (of simulation agents, each instance of the model species), and that the simulation(s) inside this population contain(s), in turn, all the "regular" populations of agents of the model.
A species can provide a schedules expression to control which agents its population schedules. The expression may select a subset or define a custom order.
When a population is stepped, its schedules expression can provide a different ordered container. For example, this expression shuffles the population each time it is evaluated:
species A schedules: shuffle(A) {}
A custom scheduler species can combine populations into another scheduling expression. For example:
global {}
species scheduler schedules: shuffle(A + B + C);
species A schedules: [] {}
species B schedules: [] {}
species C schedules: [] {}
When a custom scheduler includes agents from another species, set that speciesβ own schedules expression to [] to avoid scheduling the same agents twice. The scheduler species itself is optional when another species can express the required schedule.
Another expression can schedule a selected set of agents in a chosen order:
global {}
species scheduler schedules: shuffle(A) + B;
species A schedules: [] {}
species B schedules: [] {}
A schedules expression can also filter agents. This example schedules only agents whose can_be_scheduled action returns true:
species A schedules: A where each.can_be_scheduled() {
bool enabled <- true;
bool can_be_scheduled() {
return enabled;
}
}
Avoid scheduling an agent population through a scheduler that includes the scheduler itself. This example creates recursive scheduling:
global {}
species my_scheduler schedules: [world] {}
The schedules facet on global does not unschedule the world agent.