Agent#
- class epiworldpy.Agent#
Bases:
pybind11_objectAn individual in the simulated population.
Agents are created by the model (for example, with
Model.agents_smallworld()) and accessed withModel.get_agent()orModel.get_agents(); they cannot be created directly. Each agent has a state (an index intoModel.get_states()), at most one active virus, any number of tools, and may belong to entities.Methods that change an agent (
set_virus,add_tool,change_state, …) do not act immediately: they record an event that the model applies at the end of the current simulation step.Methods
Add the agent to an entity.
Give the agent a tool.
Move the agent to a new state.
Get the entities the agent belongs to.
Get the agent's ID.
Get the number of entities the agent belongs to.
Get the number of neighbors in the contact network.
Get the number of tools the agent carries.
Get the agent's neighbors in the contact network.
Get the agent's current state.
Get the day the agent's state last changed.
Get the agent's previous state.
Get the tools the agent carries.
Get the agent's active virus.
Check whether the agent belongs to an entity, by ID.
Check whether another agent is a neighbor.
Overloaded function.
Overloaded function.
Mutate the agent's active virus.
Remove the agent from an entity.
Remove one of the agent's tools.
Remove the agent's active virus.
Infect the agent with a virus.
- add_entity(self: epiworldpy._core.Agent, model: epiworldpy._core.Model, entity: epiworldpy._core.Entity) None#
Add the agent to an entity.
The agent joins the entity at the end of the current step.
- add_tool(self: epiworldpy._core.Agent, model: epiworldpy._core.Model, tool: epiworldpy._core.Tool) None#
Give the agent a tool.
The agent receives a copy of
toolat the end of the current step.
- change_state(self: epiworldpy._core.Agent, model: epiworldpy._core.Model, new_state: SupportsInt | SupportsIndex, queue: SupportsInt | SupportsIndex = 0) None#
Move the agent to a new state.
The change takes effect at the end of the current step.
- Parameters:
model (Model) – The model the agent belongs to.
new_state (int) – Index of the new state (see
Model.get_states()).queue (int, default 0) – How to update the queuing system (see
Model.queuing_on()):2adds the agent and its neighbors to the queue,1adds only the agent,-1and-2undo those, and0leaves the queue unchanged.
- get_entities(self: epiworldpy._core.Agent) list[int]#
Get the entities the agent belongs to.
- Returns:
IDs of the entities (see
Model.get_entity()).- Return type:
list of int
- get_id(self: epiworldpy._core.Agent) int#
Get the agent’s ID.
- Returns:
The agent’s ID, which is also its index in
Model.get_agents().- Return type:
int
- get_n_entities(self: epiworldpy._core.Agent) int#
Get the number of entities the agent belongs to.
- Returns:
Number of entities.
- Return type:
int
- get_n_neighbors(self: epiworldpy._core.Agent) int#
Get the number of neighbors in the contact network.
- Returns:
Number of neighbors.
- Return type:
int
- get_n_tools(self: epiworldpy._core.Agent) int#
Get the number of tools the agent carries.
- Returns:
Number of tools.
- Return type:
int
- get_neighbors(self: epiworldpy._core.Agent, model: epiworldpy._core.Model) list[epiworldpy._core.Agent]#
Get the agent’s neighbors in the contact network.
- get_state(self: epiworldpy._core.Agent) int#
Get the agent’s current state.
- Returns:
Index of the state in
Model.get_states().- Return type:
int
- get_state_last_changed(self: epiworldpy._core.Agent) int#
Get the day the agent’s state last changed.
- Returns:
Simulation day of the last state change.
- Return type:
int
- get_state_prev(self: epiworldpy._core.Agent) int#
Get the agent’s previous state.
- Returns:
Index of the state the agent was in before its last state change.
- Return type:
int
- get_tools(self: epiworldpy._core.Agent) list[epiworldpy._core.Tool]#
Get the tools the agent carries.
- Returns:
The agent’s tools, in the order they were received.
- Return type:
list of Tool
- get_virus(self: epiworldpy._core.Agent) object#
Get the agent’s active virus.
- Returns:
The virus currently infecting the agent, or
Noneif the agent is not infected.- Return type:
Virus or None
- has_entity(self: epiworldpy._core.Agent, t: SupportsInt | SupportsIndex) bool#
Check whether the agent belongs to an entity, by ID.
- Parameters:
t (int) – ID of the entity (see
Entity.get_id()).- Returns:
Trueif the agent belongs to the entity.- Return type:
bool
- has_neighbor(self: epiworldpy._core.Agent, neighbor_id: SupportsInt | SupportsIndex) bool#
Check whether another agent is a neighbor.
- Parameters:
neighbor_id (int) – ID of the other agent.
- Returns:
Trueif the other agent is one of this agent’s neighbors.- Return type:
bool
- has_tool(*args, **kwargs)#
Overloaded function.
has_tool(self: epiworldpy._core.Agent, t: typing.SupportsInt | typing.SupportsIndex) -> bool
Check whether the agent has a tool, by ID.
- Parameters:
t (int) – ID of the tool (see
Tool.get_id()).- Returns:
Trueif the agent carries the tool.- Return type:
bool
has_tool(self: epiworldpy._core.Agent, name: str) -> bool
Check whether the agent has a tool, by name.
- Parameters:
name (str) – Name of the tool.
- Returns:
Trueif the agent carries a tool with that name.- Return type:
bool
- has_virus(*args, **kwargs)#
Overloaded function.
has_virus(self: epiworldpy._core.Agent, t: typing.SupportsInt | typing.SupportsIndex) -> bool
Check whether the agent is infected with a virus, by ID.
- Parameters:
t (int) – ID of the virus (see
Virus.get_id()).- Returns:
Trueif the agent’s active virus has that ID.- Return type:
bool
has_virus(self: epiworldpy._core.Agent, name: str) -> bool
Check whether the agent is infected with a virus, by name.
- Parameters:
name (str) – Name of the virus.
- Returns:
Trueif the agent’s active virus has that name.- Return type:
bool
- mutate_virus(self: epiworldpy._core.Agent, model: epiworldpy._core.Model) None#
Mutate the agent’s active virus.
Calls the virus’s mutation function (see
Virus.set_mutation()).- Parameters:
model (Model) – The model the agent belongs to.
- Raises:
RuntimeError – If the agent has no active virus.
- rm_entity(self: epiworldpy._core.Agent, model: epiworldpy._core.Model, entity: epiworldpy._core.Entity) None#
Remove the agent from an entity.
The agent leaves the entity at the end of the current step.
- rm_tool(self: epiworldpy._core.Agent, model: epiworldpy._core.Model, tool_idx: SupportsInt | SupportsIndex) None#
Remove one of the agent’s tools.
The tool is removed at the end of the current step.
- Parameters:
model (Model) – The model the agent belongs to.
tool_idx (int) – Position of the tool in
get_tools()(not the tool’s ID).
- rm_virus(self: epiworldpy._core.Agent, model: epiworldpy._core.Model) None#
Remove the agent’s active virus.
The agent moves to the virus’s
endstate (seeVirus.set_state()) at the end of the current step.- Parameters:
model (Model) – The model the agent belongs to.
- set_virus(self: epiworldpy._core.Agent, model: epiworldpy._core.Model, virus: epiworldpy._core.Virus) None#
Infect the agent with a virus.
The agent receives a copy of
virusand moves to the virus’sinitstate (seeVirus.set_state()) at the end of the current step.