Skip to content

Add Task system proof-of-concept: ant colony with interruptible tasks#445

Open
samuelmohel wants to merge 15 commits intomesa:mainfrom
samuelmohel:main
Open

Add Task system proof-of-concept: ant colony with interruptible tasks#445
samuelmohel wants to merge 15 commits intomesa:mainfrom
samuelmohel:main

Conversation

@samuelmohel
Copy link
Copy Markdown

@samuelmohel samuelmohel commented Mar 27, 2026

What this adds

A proof-of-concept implementation of the Task system proposed in
mesa/mesa#2526 (EwoutH).

Adds a model-agnostic Task and TaskQueue class with:

  • Explicit duration (step-based)
  • Priority queue - highest priority task always executes first
  • Interruptible and resumable task state
  • Pluggable reward functions (linear, threshold, exponential)

Demonstrated via an ant colony where cave-in pheromone signals
interrupt ongoing dig tasks in real time.

Files

  • tasks.py - reusable Task/TaskQueue classes, zero dependency on ant logic
  • model.py - AntColonyModel + AntAgent
  • app.py - SolaraViz visualization
  • metadata.toml - example metadata

Related

Preview

shot

@DashamiJituri
Copy link
Copy Markdown

Hi @samuelmohel — I've been working on a related prototype (PR #432, needs-based Wolf-Sheep) and your TaskQueue implementation answers a question I had been sitting with.
In my model I emulated duration by tracking ticks_remaining as a manual counter on the agent — which works but is fragile when the agent gets removed mid-task. Your interruptible flag handles that cleanly.
On your design question about integer step-counts vs DiscreteEventScheduler float time — I'd lean toward accepting both via a union type (int | float), where integer duration maps directly to tick counts and float duration is resolved against model.time. That way Task stays compatible with both the standard scheduler and DEVS without forcing the user to choose upfront.
Happy to test this against my Wolf-Sheep model if it would help validate the approach.

@samuelmohel
Copy link
Copy Markdown
Author

Thanks @DashamiJituri that's a clean solution. The int | float union with integer mapping to tick counts and float resolving against model time keeps the API simple while covering both schedulers. One thing I'd add: Task would need to store the start_time at activation so float-duration tasks can compute remaining = (start_time + duration) - model.time correctly when resumed after interruption otherwise resumable tasks with float duration lose their progress reference. Would be great to test against your Wolf-Sheep model, especially to see how the interruptible flag behaves when an agent is removed mid-task. I'll open a follow-up branch with the union type implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants