This example demonstrates agent-level interruptions in Mesa using event-based scheduling instead of step-based counters.
Many Mesa models implement long-running actions (e.g. jail sentences,
cooldowns, delays) using counters inside step(). This example shows
how such behavior can be modeled more naturally using scheduled events.
- Agent actions with duration (jail sentence)
- Event-based interruption and resumption
- No polling or step counters
- Minimal logic inside
step()
- Agents normally perform actions when FREE
- At scheduled times, one agent is arrested
- Arrested agents do nothing while IN_JAIL
- Release is handled automatically via a scheduled event
agents.py– Agent logic with interruption and releasemodel.py– Model-level scheduling of arrestsrun.py– Minimal script to run the model
python run.py