Skip to content

Add energy expenditure example - #485

Closed
lahari936 wants to merge 1 commit into
mesa:mainfrom
lahari936:energy-expenditure-example
Closed

lahari936 wants to merge 1 commit into
mesa:mainfrom
lahari936:energy-expenditure-example

Conversation

@lahari936

Copy link
Copy Markdown

Add a minimal needs-based behavior example: agents pay energy every step, pay more when they move, switch to resting once their reserve drops below a threshold, and are removed when it reaches zero.

Written against the current Mesa API (mesa.discrete_space, CellAgent, rng seeding) and laid out like the other examples in this repo, with a DataCollector, SolaraViz sliders and plots, and tests covering the energy and population invariants.

Starting energy is drawn per agent rather than shared, so the population declines over many steps instead of expiring all at once.

Closes #446

Thanks for opening a PR! Please click the Preview tab and select a PR template:

Add a minimal needs-based behavior example: agents pay energy every step,
pay more when they move, switch to resting once their reserve drops below a
threshold, and are removed when it reaches zero.

Written against the current Mesa API (mesa.discrete_space, CellAgent, rng
seeding) and laid out like the other examples in this repo, with a
DataCollector, SolaraViz sliders and plots, and tests covering the energy
and population invariants.

Starting energy is drawn per agent rather than shared, so the population
declines over many steps instead of expiring all at once.

Closes mesa#446

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 23, 2026 11:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new discrete-space Mesa example demonstrating needs-based behavior driven by an internal “energy” state, including a minimal model, SolaraViz UI, and accompanying documentation/tests.

Changes:

  • Adds the new examples/energy_expenditure example package with an energy-spending agent, model, and data collection.
  • Adds a SolaraViz visualization (app.py) with sliders and plots for population and mean energy.
  • Updates the repo-level README.md to list and link the new example.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
README.md Adds the Energy Expenditure example to the examples index.
examples/energy_expenditure/README.md Documents model behavior, observables, and how to run the app/tests.
examples/energy_expenditure/requirements.txt Declares the per-example Mesa dependency (with viz extra).
examples/energy_expenditure/app.py SolaraViz UI (params + portrayal + plots) for the new model.
examples/energy_expenditure/energy_expenditure/agent.py Implements energy-based move/rest/die behavior as a CellAgent.
examples/energy_expenditure/energy_expenditure/model.py Defines the model, grid setup, agent creation, and DataCollector reporters.
examples/energy_expenditure/energy_expenditure/init.py Package marker for the example’s importable module.
examples/energy_expenditure/test_energy_expenditure.py Adds invariant-focused tests for energy monotonicity and population/cell cleanup behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@falloficaruss

Copy link
Copy Markdown
Collaborator

Thank you for the PR!
Can you please describe more on the use of this model?

@lahari936

lahari936 commented Aug 30, 2026 via email

Copy link
Copy Markdown
Author

@lahari936 lahari936 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The model is the smallest complete demo of needs-based behavior: each agent carries one number, energy. Existing costs metabolism every step, moving costs move_cost on top, and below rest_threshold the agent stops moving and rests. That single comparison is the whole decision rule — nothing tells the agent to survive, yet it trades mobility for lifespan exactly when it can no longer afford to wander.

Alive, Resting and Mean Energy make that visible at the population level; starting energy is drawn per agent, so you get a decline curve with a clear wave from mostly-moving to mostly-resting rather than everyone expiring on the same step.

Wolf-Sheep has energy too, but tangled with predation, reproduction and grass regrowth. Here energy is the only state, so the mechanism stays legible and the threshold rule sits in one method — easy to swap for a utility function or behavior tree while the grid, data collection and viz stay untouched.

Nothing replenishes energy, so extinction is certain; that's deliberate, to keep it to one concept. Happy to add a food source and foraging drive if you'd rather it show a steady state, or to fold this explanation into the example's README.

@falloficaruss

Copy link
Copy Markdown
Collaborator

Using LLMs for writing code is fine but you must not just act as a proxy between the reviewer and the LLM.
You may want to read: Guideline on AI and LLM usage

Nevertheless going through the example I think needs based behavior is already covered by Humanitarian Aid Distribution model.

@lahari936

lahari936 commented Aug 30, 2026 via email

Copy link
Copy Markdown
Author

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add energy-based agent example (needs-based behavior)

3 participants