mesa
mesa copied to clipboard
Enable DiscreteEventScheduler to handle system-level events and task interruptions
The current implementation of the DiscreteEventScheduler
(as of #1890) could be improved by allowing task interruptions and resumptions, and integrating system-level event handling.
Motivation
System-level events, such as policy changes or environmental shifts, can be crucial for simulating real-world scenarios. By enabling agents to interrupt and resume tasks and react to system-wide changes, we allows new systems to be modelled.
Description
The current implementation of the DiscreteEventScheduler
in Mesa works great for simulations where agents operate based on discrete events. However, for more complex scenarios, especially those requiring dynamic interruption and resumption of tasks, as well as system-level event responses, the scheduler could benefit from additional functionalities.
Proposed Enhancements:
-
Enhanced Event Scheduling:
- Modify
schedule_event
to check an agent's current task status before scheduling new tasks. - Implement logic to handle scenarios where an agent is already engaged in a task (e.g., delay or reschedule the new task).
- Modify
-
Basic Interruption Handling:
- Introduce a method in
DiscreteEventScheduler
to interrupt an agent's current task. - Update the agent's status to reflect the interruption and, optionally, reschedule the interrupted task for a later time.
- Introduce a method in
-
System-Level Event Integration:
- Implement a feature to schedule system-wide events that can affect multiple or all agents.
- These events could trigger task interruptions or other significant changes in agent behavior.
-
Resumption Logic:
- Develop a mechanism within agents to resume interrupted tasks.
- This would involve checking their status at the beginning of their
step
method and deciding whether to continue a previous task or start a new one.
There is probably more that could fit in there. I think the most important is to think about the concepts of tasks in Mesa, a thing that an agent is currently working on, has some future benefit and can be interrupted by different things.