Task Dataclass
Task module for the AMR Hub ABM framework.
task
Module for AMR Hub ABM tasks.
Design notes
Taskis a plain dataclass with an explicitlocationfield. Subclasses exist only where there is genuine behaviour (door buffering, content lookup), not just to set a location.- Subclass-specific behaviour is expressed through lifecycle hooks
(
on_start_moving,on_started,on_completed) instead ofisinstancechecks in the base class. update_progressis a small explicit state machine: one handler perTaskProgressstate.create_taskis a factory that owns per-type defaults (durations etc.), soAgent.add_taskno longer needs a long if/elif chain.- The spatial engine (
SpatialQuery) is threaded through as an explicitengineparameter rather than being accessed via the agent. This keeps the task layer decoupled from the agent's attributes and allows swapping CPU/GPU backends transparently.
Task
dataclass
Representation of a task assigned to an agent.
A task is a small state machine driven by update_progress. Subclasses
customise behaviour via the lifecycle hooks prepare,
on_start_moving, on_started and on_completed rather than by
being special-cased in the base class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_needed
|
int
|
The time required to complete the task. |
required |
time_due
|
int
|
The time by which the task should be completed. |
required |
location
|
Location | None
|
Where the task is performed. Simple task types (goto, workstation,
attend patient) pass this directly; subclasses that derive their own
location (door access, occupy content) may leave it None and set it
in |
None
|
progress
|
TaskProgress
|
Current progress. Defaults to NOT_STARTED. |
NOT_STARTED
|
priority
|
TaskPriority
|
Priority level. Defaults to MEDIUM. |
MEDIUM
|
Source code in src/amr_hub_abm/task/task.py
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 | |
__post_init__()
Validate timing attributes.
Source code in src/amr_hub_abm/task/task.py
128 129 130 131 132 133 134 135 | |
__repr__()
Representation of the task.
Source code in src/amr_hub_abm/task/task.py
298 299 300 301 302 303 304 | |
on_completed(agent, current_time, engine)
Handle the transition to COMPLETED.
Source code in src/amr_hub_abm/task/task.py
172 173 174 175 | |
on_dispatch(agent)
Claim resources immediately before the task begins moving.
Returns:
| Type | Description |
|---|---|
bool
|
Whether the task acquired any resources needed to start. |
Source code in src/amr_hub_abm/task/task.py
154 155 156 157 158 159 160 161 162 163 164 | |
on_start_moving(agent, engine)
Handle the transition to MOVING_TO_LOCATION.
Source code in src/amr_hub_abm/task/task.py
166 167 | |
on_started(agent, current_time)
Handle the transition to IN_PROGRESS.
Source code in src/amr_hub_abm/task/task.py
169 170 | |
prepare(agent)
Resolve any late-bound state before the task is first scheduled.
Called while the task is NOT_STARTED (e.g. TaskOccupyContent
resolves currently available content here).
Returns:
| Type | Description |
|---|---|
bool
|
Whether the task is ready for scheduling. |
Source code in src/amr_hub_abm/task/task.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
time_spent(current_time)
Calculate the time spent on the task so far.
Raises:
| Type | Description |
|---|---|
TimeError
|
If the task is COMPLETED or IN_PROGRESS but the corresponding timestamps are missing. |
Source code in src/amr_hub_abm/task/task.py
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 | |
update_progress(current_time, agent, engine)
Advance the task state machine by one tick.
Dispatches to a handler per TaskProgress state. Completion is
checked first since it can occur from any active state.
Source code in src/amr_hub_abm/task/task.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
TaskAttendPatient
dataclass
Bases: Task
An 'attend patient' task. Carries the patient so the UI/agent can refer to it.
Source code in src/amr_hub_abm/task/task.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
__post_init__()
Validate patient and set location.
Source code in src/amr_hub_abm/task/task.py
319 320 321 322 323 324 325 | |
TaskDoorAccess
dataclass
Bases: Task
A 'door access' task: position the agent just beyond the door midpoint.
Source code in src/amr_hub_abm/task/task.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
__post_init__()
Validate door and compute midpoint location.
Source code in src/amr_hub_abm/task/task.py
339 340 341 342 343 344 345 | |
on_start_moving(agent, engine)
Offset the target to the correct side of the door for the destination.
Source code in src/amr_hub_abm/task/task.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
TaskOccupyContent
dataclass
Bases: Task
An 'occupy content' task: find matching content in a room and sit on it.
Source code in src/amr_hub_abm/task/task.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
__post_init__()
Validate that a room is provided.
Source code in src/amr_hub_abm/task/task.py
396 397 398 399 400 401 | |
on_completed(agent, current_time, engine)
Occupy the content once the task finishes.
Source code in src/amr_hub_abm/task/task.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
on_dispatch(agent)
Reserve the selected content before starting travel.
Source code in src/amr_hub_abm/task/task.py
434 435 436 437 438 439 440 441 442 | |
prepare(agent)
Resolve an available content instance and set the task location.
Source code in src/amr_hub_abm/task/task.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
TaskPriority
Bases: IntEnum
Enumeration of possible task priority levels.
Source code in src/amr_hub_abm/task/task.py
76 77 78 79 80 81 | |
TaskProgress
Bases: IntEnum
Enumeration of possible task progress states.
Source code in src/amr_hub_abm/task/task.py
48 49 50 51 52 53 54 55 | |
TaskType
Bases: IntEnum
Enumeration of possible task types.
Source code in src/amr_hub_abm/task/task.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
TaskWorkstation
dataclass
Bases: Task
A 'workstation' task: occupy a workstation in a room.
Source code in src/amr_hub_abm/task/task.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |
__post_init__()
Validate that a room is provided.
Source code in src/amr_hub_abm/task/task.py
467 468 469 | |
prepare(agent)
Set the task location to the workstation location.
Source code in src/amr_hub_abm/task/task.py
471 472 473 474 | |
task_builders
Module for collection of TaskBuilder functions.
TaskBuilderContext
dataclass
Context for building tasks.
Source code in src/amr_hub_abm/task/task_builders.py
29 30 31 32 33 34 35 36 37 38 39 40 41 | |
build_attend_patient_task(context)
Build a TaskAttendPatient task.
Source code in src/amr_hub_abm/task/task_builders.py
70 71 72 73 74 75 76 77 78 79 80 | |
build_door_access_task(context)
Build a TaskDoorAccess task.
Source code in src/amr_hub_abm/task/task_builders.py
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 | |
build_occupy_content_task(context)
Build a TaskOccupyContent task.
Source code in src/amr_hub_abm/task/task_builders.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
build_task_context(time, time_needed, location, additional_info=None)
Build a TaskBuilderContext from the legacy additional_info dict.
This adapter can be removed once callers pass TaskBuilderContext directly.
Source code in src/amr_hub_abm/task/task_builders.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
build_workstation_task(context)
Build a TaskWorkstation task.
Source code in src/amr_hub_abm/task/task_builders.py
111 112 113 114 115 116 117 118 119 120 121 | |
task_duration
Module defining task duration configurations for the AMR Hub ABM simulation.
TaskDurationConfig
dataclass
Task duration parameters read from the simulation configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_needed_attend_patient
|
int
|
Timesteps needed for a healthcare worker to attend to a patient. |
required |
time_needed_door_access
|
int
|
Timesteps needed for a healthcare worker to access a door (e.g., open/close). |
required |
time_needed_workstation
|
int
|
Timesteps needed for a healthcare worker to use a workstation. |
required |
time_needed_occupy_content
|
int
|
Timesteps needed for a healthcare worker to occupy content (e.g. a bed, a chair, etc.). |
required |
Source code in src/amr_hub_abm/task/task_duration.py
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 | |
task_duration_mapping
property
from_config(config_data)
classmethod
Build a TaskDurationConfig from parsed YAML configuration data.
There are deliberately no fallback defaults here: task durations 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 |
|---|---|
TaskDurationConfig
|
The task duration parameters read from the config. |
Source code in src/amr_hub_abm/task/task_duration.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 | |
tasklist
Module containing functions for managing tasks in the AMR Hub ABM framework.
perform_in_progress_task(agent, current_time, engine)
Perform an in-progress task and return True if a task was performed.
Source code in src/amr_hub_abm/task/tasklist.py
52 53 54 55 56 57 58 59 60 | |
perform_moving_to_task_location(agent, current_time, engine)
Move the agent towards the location of its next task.
Source code in src/amr_hub_abm/task/tasklist.py
63 64 65 66 67 68 69 70 71 72 73 | |
perform_suspended_task(agent, current_time, engine)
Perform a suspended task and return True if a task was performed.
Source code in src/amr_hub_abm/task/tasklist.py
76 77 78 79 80 81 82 83 84 85 86 | |
perform_to_be_started_task(agent, current_time, engine)
Perform a to-be-started task and return True if a task was performed.
Source code in src/amr_hub_abm/task/tasklist.py
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 | |
select_task_based_on_progress(tasklist, progress, *, allow_multiple=False)
Select a task based on its progress.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasklist
|
list[Task]
|
The list of tasks to filter. |
required |
progress
|
TaskProgress
|
The progress status to filter tasks by. |
required |
allow_multiple
|
bool
|
Whether to allow multiple tasks with the same progress status. |
False
|
Returns:
| Type | Description |
|---|---|
Task | None
|
The selected task with the specified progress status, or None if no such task exists. |
Source code in src/amr_hub_abm/task/tasklist.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 | |