A collection of agent-based models exploring cooperation, altruism, and eco-evolutionary dynamics.
The current website-ready evolved-cooperation examples in this repo are:
spatial_altruism/: a minimal spatial altruism modelcooperative_hunting/: a spatial predator-prey-grass cooperative-hunting model
A third, simpler evolutionary model remains available in cooperation/ as a
possible later website example.
This repo uses a project-local Conda environment stored at .conda/ so it travels with the workspace and VS Code can auto-select it.
- Interpreter path:
/home/doesburg/Projects/EvolvedCooperation/.conda/bin/python - VS Code setting: see
.vscode/settings.json(we setpython.defaultInterpreterPath, point VS Code at the local Conda executable, and use a repo-specific terminal profile instead of fixed-script launch entries) - Matplotlib cache/config path for VS Code runs:
.vscode/.envsetsMPLCONFIGDIR=.matplotlib - Ruff editor linting: install Ruff into the project environment with
./.conda/bin/python -m pip install ruff - Pylance note:
.vscode/settings.jsondisablesreportMissingModuleSourceso compiled Matplotlib modules do not produce false-positive import warnings in editor diagnostics
The workspace is configured so VS Code uses the repo-local .conda deterministically:
Terminal => New Terminalopensbash (.conda), which sources the normal shell startup and then activates/home/doesburg/Projects/EvolvedCooperation/.conda.Run => Run Without Debugginguses.vscode/launch.jsonplus.vscode/run_active_python.pyto inspect the active editor file.- If the active file lives inside a Python package in the repo, the helper runs it with module semantics (
runpy.run_module(...)), which matchespython -m ...from the repo root and satisfies module-only guards. - If the active file is not inside a package, the helper falls back to normal script execution (
runpy.run_path(...)). - The launch config still forces
${workspaceFolder}/.conda/bin/python, so runs do not depend on whichever interpreter VS Code happened to remember previously.
Activate the environment in a terminal when running commands manually:
source /home/doesburg/miniconda3/etc/profile.d/conda.sh
conda activate "$(pwd)/.conda"
# or run without activation using the interpreter directly:
./.conda/bin/python -m pip install -r requirements.txt
./.conda/bin/python -m spatial_altruism.altruism_modelIf you see a “bad interpreter” error, regenerate entry scripts (pip, etc.) with:
./.conda/bin/python -m pip install --upgrade --force-reinstall pip setuptools wheelThe most actively documented ecology model in the repo lives in
cooperative_hunting/.
- Main runtime:
cooperative_hunting/cooperative_hunting.py - Active parameters:
cooperative_hunting/config/cooperative_hunting_config.py - Detailed model notes and theory mapping:
cooperative_hunting/README.md
Current mechanics in that model:
- predators carry a heritable continuous hunt investment trait
hunt_investment_trait in [0,1] - hunt contribution is
predator_energy * hunt_investment_trait - predator cooperation cost is paid directly as
predator_cooperation_cost_per_unit * hunt_investment_trait - the config file now uses descriptive canonical parameter names, while legacy short aliases remain accepted for backward compatibility
- optional plasticity has been removed from the active code path, so the stored trait is the value used for hunting and cost
Browser replay preview:
Click the full-window animation preview to open the GitHub Pages replay viewer.
On 2026-04-06, the repo-level website root was turned into a multi-demo landing page.
Stepwise impact:
docs/index.htmlnow acts as a landing page that lists the available replay demos instead of embedding one specific simulation.- The cooperative-hunting browser replay now lives at
docs/cooperative-hunting/index.html. - The spatial-altruism browser replay continues to live at
docs/spatial-altruism/index.html. - README links now point directly to each demo route instead of assuming the root site always hosts the cooperative-hunting replay.
On 2026-04-10, the landing page gained a conceptual display that clarifies the eco-evolutionary feedback loop around learning and plasticity.
Stepwise impact:
docs/index.htmlnow includes a full-widthWhy the feedback loop matterssection beneath the demo cards.- The new display presents the loop as a four-step sequence: evolution shapes learning capacities, learning reshapes ecological structure, ecological structure reshapes selection gradients, and plasticity closes the loop.
- The landing page now also contrasts unstable and stable environments so the selection logic behind higher versus lower plasticity is visible at a glance.
docs/style.cssnow includes responsive home-page styles for that explanatory display while staying in the existing card-based visual system.
On 2026-04-06, the repo gained an explicit GitHub Pages deployment workflow for the interactive viewers.
Stepwise impact:
.github/workflows/deploy-pages.ymlnow publishes the repo-leveldocs/site on pushes tomain.docs/index.htmlnow labels both demo entry points asOpen Interactive Viewerso the viewer routes are explicit.- The public routes remain
docs/cooperative-hunting/index.htmlanddocs/spatial-altruism/index.html; the workflow only changes how those pages are deployed. - If the repository Pages setting is not already using
GitHub Actions, switch it there so this workflow becomes the active publisher.
Project convention for this model:
- prefer editing parameters inside the config file rather than passing CLI parameter overrides
- run from repo root with
./.conda/bin/python
Minimal run example:
./.conda/bin/python -m cooperative_hunting.cooperative_huntingCurrent website examples under evolved cooperation:
Spatial Altruism->spatial_altruism/altruism_model.pyCooperative Hunting->cooperative_hunting/cooperative_hunting.py
Strong next candidate for later addition:
Cooperative vs Greedy Grazing->cooperation/cooperation_model.py
On 2026-04-06, the package directory for the predator-prey-grass model was renamed from predpreygrass_cooperative_hunting/ to cooperative_hunting/.
Stepwise impact:
- The Python package now lives at
cooperative_hunting/. - Module entrypoints now use
./.conda/bin/python -m cooperative_hunting...from the repo root. - Internal asset paths moved from
assets/predprey_cooperative_hunting/toassets/cooperative_hunting/. - Utility output paths now write to
cooperative_hunting/images/. - The package rename initially affected the Python/package layer; the public viewer route was renamed separately on 2026-04-07.
On 2026-04-07, the cooperative-hunting browser viewer and website slug were renamed from predator-prey-cooperative-hunting to cooperative-hunting.
Stepwise impact:
- The repo-level replay page moved from
docs/predator-prey-cooperative-hunting/index.htmltodocs/cooperative-hunting/index.html. - GitHub Pages links now point to
/cooperative-hunting/. - The
humanbehaviorpatterns.orgpage and replay paths now use/evolved-cooperation/cooperative-hunting/. - The public viewer title and landing-page label now read
Cooperative Hunting, while the descriptive copy still explains that it is a predator-prey-grass ecology.
- Description: Patch-based grid simulation of altruism vs selfishness, ported from NetLogo to Python/NumPy.
- Browser replay preview:
- Features:
- Each cell can be empty (black), selfish (green), or altruist (pink)
- Simulates benefit/cost of altruism, fitness, and generational updates
- Fully vectorized NumPy implementation for fast simulation
- Pygame UI for interactive exploration
- Matplotlib plots for population dynamics
- Grid search for parameter sweeps
- Sampled browser replay and README GIF preview
- Files:
spatial_altruism/altruism_model.py: Core simulation logicspatial_altruism/altruism_pygame_ui.py: Pygame-based interactive UIspatial_altruism/config/altruism_config.py: Active runtime configurationspatial_altruism/config/altruism_website_demo_config.py: Frozen website replay configurationspatial_altruism/images/: Plotting scripts and generated image or Plotly outputsspatial_altruism/utils/export_github_pages_demo.py: Website replay and preview GIF exporterspatial_altruism/utils/altruism_grid_search.py: Parallel grid search for extended coexistence sweepsspatial_altruism/data/grid_search_results_extended.csv: Results from the parallel grid search
- Usage:
- Run core model:
# edit spatial_altruism/config/altruism_config.py first if needed ./.conda/bin/python -m spatial_altruism.altruism_model - Run Pygame UI:
./.conda/bin/python -m spatial_altruism.altruism_pygame_ui
- Run grid search:
./.conda/bin/python -m spatial_altruism.utils.altruism_grid_search
- Regenerate website replay bundle:
./.conda/bin/python -m spatial_altruism.utils.export_github_pages_demo
- Run core model:
- Requirements:
- Python 3.8+
- numpy
- pygame (for UI)
- matplotlib (for plotting)
- torch (for surface fitting)
- Description: Evolutionary model of greedy vs cooperative cows competing for regrowing grass.
- Features:
- Agents move, eat, reproduce, and die based on energy and grass availability
- Cooperative cows avoid eating low grass, greedy cows eat regardless
- Grass regrows at different rates depending on height
- Pygame UI for visualization
- Files:
cooperation/cooperation_model.py: Core simulation logiccooperation/cooperation_pygame_ui.py: Pygame-based interactive UIcooperation/Cooperation.nlogox: Original NetLogo model
- Usage:
- Run CLI demo:
./.conda/bin/python cooperation/cooperation_model.py
- Run Pygame UI:
./.conda/bin/python cooperation/cooperation_pygame_ui.py
- Run CLI demo:
- Requirements:
- Python 3.8+
- numpy
- pygame
- matplotlib
- Description: Spatial predator-prey ecology where predators evolve a continuous cooperation trait that affects group hunting success, payoff sharing, and private cooperation cost.
- Files:
cooperative_hunting/cooperative_hunting.py: core simulation and runtime entry pointcooperative_hunting/config/cooperative_hunting_config.py: active runtime parameterscooperative_hunting/utils/matplot_plotting.py: Matplotlib plotting helpers for baseline runscooperative_hunting/utils/sweep_dual_parameter.py: parameter sweep toolingcooperative_hunting/utils/tune_mutual_survival.py: coexistence tuning utilitiescooperative_hunting/README.md: detailed interpretation and experiment guide
- Usage:
- Edit parameters in
cooperative_hunting/config/cooperative_hunting_config.py - Run:
./.conda/bin/python -m cooperative_hunting.cooperative_hunting
- Edit parameters in
- Current status:
- uses raw inherited
hunt_investment_traitdirectly for hunt effort and cooperation cost - supports equal-split or contribution-weighted prey sharing
- includes headless analysis, pygame live rendering, and sweep/tuning helpers
- uses raw inherited
Install dependencies:
pip install numpy pygame matplotlib torchFor Pygame visualization, you may need:
conda install -y -c conda-forge gcc=14.2.0- Original NetLogo models from Uri Wilensky and the EACH unit (Evolution of Altruistic and Cooperative Habits)
- See
spatial_altruism/README.mdandcooperation/Cooperation.nlogoxfor more details

