Agent Dataclass Reference
Agent module for the AMR Hub ABM simulation.
agent
Module to represent an agent in the AMR Hub ABM simulation.
This module defines the Agent class, which represents an individual agent in the
simulation. The Agent class includes attributes for the agent's location, heading,
tasks, and infection status, as well as methods for moving the agent, performing
tasks, and recording the agent's state over time. The module also defines related
classes and enumerations, such as AgentType, InfectionStatus, and Record, to
support the functionality of the Agent class.
Agent
dataclass
Representation of an agent in the AMR Hub ABM simulation.
Source code in src/amr_hub_abm/agent/agent.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
heading_degrees
property
writable
Get the heading of the agent in degrees.
Returns:
| Type | Description |
|---|---|
float
|
Heading of the agent in degrees [0, 360). |
__post_init__()
Post-initialization to setup the trajectory record and validate parameters.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the trajectory length is negative. |
Source code in src/amr_hub_abm/agent/agent.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
__repr__()
Return a string representation of the agent.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the agent, including its index, location, heading, interaction radius, type, and infection status. |
Source code in src/amr_hub_abm/agent/agent.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
add_task(time, time_needed, location, event_type, additional_info=None)
Add a task to the agent's task list and log the addition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
int
|
The time at which the task is added. |
required |
location
|
Location
|
The location associated with the task. |
required |
event_type
|
str
|
The type of task to add. |
required |
additional_info
|
dict | None
|
Additional information required for certain task types. |
None
|
Raises:
| Type | Description |
|---|---|
SimulationModeError
|
If the event_type is invalid. |
Source code in src/amr_hub_abm/agent/agent.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
attempt_task_insertion(next_task, next_task_move_time, current_time, engine, task_durations)
Attempt to insert a task to occupy an empty chair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_task
|
Task
|
The next task for which to attempt insertion of an occupy_content task. |
required |
next_task_move_time
|
float
|
The time at which the next task is scheduled to move to the next stage. |
required |
current_time
|
int
|
The current time step in the simulation. |
required |
engine
|
SpatialQuery
|
The SpatialQuery instance for resolving spatial queries. |
required |
Source code in src/amr_hub_abm/agent/agent.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
perform_task(current_time, engine, *, record=False)
Perform the agent's current task if it's due.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_time
|
int
|
The current time step in the simulation. |
required |
engine
|
SpatialQuery
|
The engine instance used to resolve geometry queries and bounds. |
required |
record
|
bool
|
Whether to record the agent's state at the current time step. |
False
|
Source code in src/amr_hub_abm/agent/agent.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
enums
Module defining enumerations for agent types and infection statuses.
AgentType
Bases: IntEnum
Enumeration of possible agent types.
Source code in src/amr_hub_abm/agent/enums.py
6 7 8 9 10 11 | |
InfectionStatus
Bases: IntEnum
Enumeration of possible infection statuses.
Source code in src/amr_hub_abm/agent/enums.py
14 15 16 17 18 19 20 | |
kinematics
Module defining agent kinematics configuration for the AMR Hub ABM simulation.
AgentKinematicsConfig
dataclass
Agent kinematics parameters read from the simulation configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
movement_speed
|
float
|
Agent movement speed, in units per time step. |
required |
stochasticity
|
float
|
Degrees of randomness applied to an agent's heading at each step. |
required |
interaction_radius
|
float
|
Distance within which an agent is considered to have reached a target. |
required |
max_movement_attempts
|
int
|
Maximum number of attempts to find a movement step that avoids wall intersections. |
required |
Source code in src/amr_hub_abm/agent/kinematics.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
from_config(config_data)
classmethod
Build an AgentKinematicsConfig from parsed YAML configuration data.
There are deliberately no fallback defaults here: agent kinematics must be defined explicitly in the simulation config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_data
|
dict[str, Any]
|
The parsed simulation configuration. |
required |
Returns:
| Type | Description |
|---|---|
AgentKinematicsConfig
|
The agent kinematics parameters read from the config. |
Raises:
| Type | Description |
|---|---|
InvalidDefinitionError
|
If one or more required agent kinematics keys are missing from the config. |
Source code in src/amr_hub_abm/agent/kinematics.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
output
Module containing functions related to agent output.
Record
dataclass
Representation of a record of an agent's state at a given time step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
total_time
|
int
|
The total number of time steps for which to record the agent's state. |
required |
Source code in src/amr_hub_abm/agent/output.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
__post_init__()
Simply initialises the numpy arrays of the class to be empty.
This includes the building, floor, position, heading, and infection status. All of these are stored as integers and floats (and not strings) for memory efficiency
Source code in src/amr_hub_abm/agent/output.py
36 37 38 39 40 41 42 43 44 45 46 47 48 | |
push(time, building_idx, floor, pos_x, pos_y, heading, infection_status)
Push a new record of the agent's state at a given time step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
int
|
The time step for which to record the agent's state. |
required |
building_idx
|
int
|
The index of the building in which the agent is located. |
required |
floor
|
int
|
The floor number on which the agent is located. |
required |
pos_x
|
float
|
The x-coordinate of the agent's position. |
required |
pos_y
|
float
|
The y-coordinate of the agent's position. |
required |
heading
|
float
|
The heading of the agent in radians. |
required |
infection_status
|
InfectionStatus
|
The infection status of the agent. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the time step exceeds the total_time for the record. |
Source code in src/amr_hub_abm/agent/output.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
record_state(agent, current_time)
Push a record of the agent's current state to the trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_time
|
int
|
The current time step in the simulation for which to record the agent's state. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the current_time exceeds the trajectory_length of the agent. |
Source code in src/amr_hub_abm/agent/output.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
plotter
Module containing plotting functions for agents.
plot_agent(agent, ax, *, show_tags=True)
Plot the agent on the given axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
The axes on which to plot the agent. |
required |
show_tags
|
bool
|
Whether to show tags with the agent's type and index. |
True
|
Source code in src/amr_hub_abm/agent/plotter.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
plot_agents_in_room(room, ax, agents, *, trajectory=False)
Plot agents located inside a room.
Source code in src/amr_hub_abm/agent/plotter.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
plot_trajectory(agent, ax, current_time=None)
Plot the agent's trajectory on the given axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
The axes on which to plot the agent's trajectory. |
required |
Source code in src/amr_hub_abm/agent/plotter.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
utils
Collection of utility functions for the agent module.
add_agent_occupancy(agent, content, current_time, engine)
Add the agent's occupancy to the specified content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Agent
|
The agent whose occupancy is to be added. |
required |
content
|
Content
|
The content to which the agent will occupy. |
required |
current_time
|
int
|
The current time in the simulation, used for logging purposes. |
required |
engine
|
SpatialQuery
|
The engine instance used to resolve geometry queries. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether occupancy was acquired. |
Source code in src/amr_hub_abm/agent/utils.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
remove_agent_occupancy(agent, current_time, engine)
Remove the agent's occupancy from any content they are currently occupying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Agent
|
The agent whose occupancy is to be removed. |
required |
current_time
|
int
|
The current time in the simulation, used for logging purposes. |
required |
engine
|
SpatialQuery
|
The engine instance used to resolve geometry queries. |
required |
Source code in src/amr_hub_abm/agent/utils.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |