Actor (Agent)
abses.agents.actor.Actor ¶
Bases: GeoAgent, _LinkNodeActor, BaseModelElement, ActorProtocol
Base actor class for agent-based models in ABSESpy.
An Actor represents an autonomous agent in a social-ecological system. It combines geospatial capabilities (from mesa-geo), network functionality (links), and ABSESpy-specific features like perception and movement. Actors can be located on spatial cells, form networks with other actors, and interact with their environment through perceptions and actions.
Actors maintain their own state including position, alive status, age, and custom attributes. They can move between cells, perceive their environment, form links with other actors, and execute custom behaviors through overridable methods.
The Actor class serves as a base class for creating custom agent types. Users
should inherit from Actor and override methods like setup() and initialize()
to define agent-specific behaviors.
Attributes:
| Name | Type | Description |
|---|---|---|
breed |
The breed (type) of this actor, defaults to class name. |
|
layer |
Optional[PatchModule]
|
The spatial layer where the actor is located. |
indices |
Optional[Pos]
|
The grid indices of the cell where the actor is located. |
pos |
Optional[Pos]
|
The position of the cell where the actor is located. |
on_earth |
bool
|
Whether the actor is positioned on a spatial cell. |
at |
PatchCell | None
|
The specific cell where the actor is located. |
link |
_LinkProxy
|
Proxy for managing network links with other actors. |
move |
_Movements
|
Proxy for manipulating actor's spatial location. |
geometry |
Optional[BaseGeometry]
|
The shapely geometry representing the actor's spatial form. |
alive |
bool
|
Whether the actor is alive (not removed from the model). |
unique_id |
UniqueID
|
Unique identifier automatically assigned by Mesa. |
crs |
CRS
|
Coordinate reference system for the actor's geometry. |
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
MainModel
|
The ABSESpy model this actor belongs to. |
required |
observer
|
bool
|
Whether this actor should be observed in data collection. Defaults to True. |
True
|
**kwargs
|
Additional keyword arguments: - crs: Coordinate reference system. Defaults to model's CRS. - geometry: Shapely geometry for the actor. Defaults to None. |
{}
|
Source code in abses/agents/actor.py
geometry
property
writable
¶
The shapely geometry of the actor.
If the actor is located on a cell, returns a Point at the cell's coordinate. Otherwise, returns the actor's custom geometry if one was assigned.
move
cached
property
¶
A proxy for manipulating actor's location.
move.to(): moves the actor to another cell.move.off(): removes the actor from the current layer.move.by(): moves the actor by a distance.move.random(): moves the actor to a random cell.
age ¶
Get the age of the actor in simulation ticks.
Returns:
| Type | Description |
|---|---|
int
|
The number of ticks since the actor was born (created). |
get ¶
Gets attribute value from target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attr
|
str
|
The name of the attribute to get. |
required |
target
|
Optional[TargetName]
|
The target to get the attribute from. If None, the agent itself is the target. If the target is an agent, get the attribute from the agent. If the target is a cell, get the attribute from the cell. |
None
|
default
|
Any
|
Default value if attribute not found. |
...
|
Returns:
| Type | Description |
|---|---|
Any
|
The value of the attribute. |
Source code in abses/agents/actor.py
set ¶
Sets the value of an attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attr
|
The name of the attribute to set. |
required | |
value
|
The value to set the attribute to. |
required | |
target
|
The target to set the attribute on. If None, the agent itself is the target. 1. If the target is an agent, set the attribute on the agent. 2. If the target is a cell, set the attribute on the cell. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the attribute is not a string. |
ABSESpyError
|
If the attribute is protected. |
Source code in abses/agents/actor.py
remove ¶
Remove the actor from the model.
This is an alias for the die() method, providing a more generic interface
for removing actors from the simulation.
move_to ¶
Move actor to a location (wrapper for move.to).
This method allows shuffle_do to be used with move operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to
|
Any
|
Position to move to. Can be a PatchCell, Coordinate tuple, or "random". |
'random'
|
layer
|
Any
|
Layer to move to. If None, uses actor's current layer if available. |
None
|
Source code in abses/agents/actor.py
die ¶
Kill the actor and remove it from the simulation.
This method performs a complete cleanup of the actor by: 1. Removing all network links with other actors 2. Removing the actor from its spatial cell (if positioned) 3. Removing the actor from the model's agent registry 4. Setting the actor's alive status to False
After calling this method, the actor should no longer be used.
Source code in abses/agents/actor.py
setup ¶
Setup method called when the actor is initialized.
Override this method to define actor-specific initialization behavior. This method is called automatically when the actor is created, before the simulation starts. Use it to set initial attributes and state.
Source code in abses/agents/actor.py
moving ¶
Callback called before the actor moves to a new cell.
Override this method to implement movement validation logic. Return False to prevent the move, True to allow it, or None to use default behavior (allow the move).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cell
|
PatchCell
|
The target cell the actor is attempting to move to. |
required |
Returns:
| Type | Description |
|---|---|
Optional[bool]
|
|
Optional[bool]
|
|
Optional[bool]
|
|
Example
Source code in abses/agents/actor.py
initialize ¶
Initialize the actor at the start of simulation.
Override this method to define behavior that should occur when the simulation begins (at tick 0), as opposed to when the actor is created. This is useful for setting up initial conditions that depend on the complete model state.
Example
Source code in abses/agents/actor.py
evaluate ¶
evaluate(
candidates,
scorer,
*,
dtype=float,
how=None,
preserve_position=False,
preserve_attrs=None
)
Evaluate a scorer across candidates and optionally choose the best.
Workflow: 1) Normalize candidates to a sequence (ActorsList stays as-is) 2) For each candidate: score with optional rollback of position/attrs 3) Return scores (ndarray) or the best candidate per 'how' ('max'/'min')