Common behaviors
Basic agents (including the world and grid cells) are provided with a simple behavioral structure, based on reflexes. Species can define any number of reflexes within their body.
reflex
Attributes
Definition
A reflex is a sequence of commands that can be executed, at each time step, by the agent. If no attribute when are defined, it will be executed every time step. If there is an attribute when, it is executed only if the boolean expression evaluates to true. It is a convenient way to specify the behavior of the agents. Example:
reflex { //Executed every time step
do action: write {
arg message value: 'Executing the unconditional reflex';
}
}reflex when: flip (0.5){ //Only executed when flip returns true
do action: write {
arg message value: 'Executing the conditional reflex';
}
}init
Attributes
- when: a boolean expression
Definition
A special form of reflex that is evaluated only once when the agent is created, after the initialization of its variables, and before it executes any reflex. Only one instance of init is allowed in each species (except in case of inheritance, see this section). Useful for creating all the agents of a model in the definition of the world, for instance.
EMF-based behaviors
EMF (Etho Modeling Framework) is task based behavior model. Species can define any number of tasks within their body. At any given time, only one task having the highest priority value is executed.
task
Sub elements
Besides a sequence of commands like reflex, a task contains the following sub elements:
- priority: Mandatory. The activation level of the task.
- durationMin: Optional. The minimal duration of the task. Until it is reached, the task cannot be interrupted.
- durationMax: Optional. The maximal duration of the task. Beyond this duration, the task is automatically halted.
- whileCondition: Optional. The "while" watchdog : a condition tested every step to ensure that the task can still be executed. If false, the task is stopped (except if the min duration is not reached)
- untilCondition: Optional. The "until" watchdog, a condition tested every step to ensure that the task can still be executed. If true, the task is stopped (except if the min duration is not reached)
- endAction: Optional. The action to execute in case of failure/interruption of the task. No repeat is allowed.
Definition
Like reflex, a task is a sequence of commands that can be executed, at each time step, by the agent. If an agent owns several tasks, the scheduler choses a task to execute basing on its current priority value. For an example of task, please have a look the definition of "foodCarrier" species in this Task exemple.
FSM-based behaviors
FSM (Finite State Machine) is a finite state machine based behavior model. During its life cycle, agent possesses several states. At any given time step, an agent is in one state.
state
Attributes
- initial: a boolean expression, indicates the initial state of agent.
- final: a boolean expression, indicates the final state of agent.
Sub elements
- enter: a sequence of commands to execute upon entering the state.
- exit: a sequence of commands to execute right before exiting the state.
- transition: specifies the next state of the life cycle.
Definition
A state like a reflex can contains several commands that can be executed, at each time step, by the agent. For an exemple of state, please have a look at the definition of "ant" species in this FSM exemple.