Skip to content

Add seir vaccination example#353

Open
BittuAgarwal1237 wants to merge 14 commits intomesa:mainfrom
BittuAgarwal1237:add-seir-vaccination-example
Open

Add seir vaccination example#353
BittuAgarwal1237 wants to merge 14 commits intomesa:mainfrom
BittuAgarwal1237:add-seir-vaccination-example

Conversation

@BittuAgarwal1237
Copy link

Summary

Adds a SEIR epidemic model with a government vaccination policy meta-agent.

Motive

There's no population-level epidemic spreading example in mesa-examples. The existing virus_antibody model works at the biological/cellular level, but nothing shows how a disease spreads through a population on a grid and how a policy intervention affects that. This fills that gap.

Implementation

PersonAgents move through four states --Susceptible, Exposed, Infected, Recovered, based on contact with infected neighbors. A GovernmentAgent monitors the infection rate each step and triggers vaccination campaigns when it crosses a threshold, directly moving some susceptible people to recovered. Activation is explicit and bottom-up: people act first, then the government responds. No legacy schedulers used.

Usage Examples

pip install mesa[rec]
python -m solara run app.py

Sliders let you adjust transmission rate, incubation period, infection duration, vaccination threshold, and campaign size. The grid shows agent states in color and two charts track SEIR curves and when vaccination campaigns are active.

@jackiekazil @tpike3 @EwoutH
Screenshot 2026-03-03 175709

@EwoutH
Copy link
Member

EwoutH commented Mar 15, 2026

Thanks for the PR. Could you try to fix the pre-commit issues?

@BittuAgarwal1237
Copy link
Author

done!!! @EwoutH @tpike3

@codebreaker32
Copy link
Collaborator

You have probably pushed two different models.

Merge branch 'main' of https://github.com/BittuAgarwal1237/mesa-examples into add-seir-vaccination-example
@BittuAgarwal1237 BittuAgarwal1237 force-pushed the add-seir-vaccination-example branch from 6670806 to 6cf3e34 Compare March 19, 2026 09:15
@BittuAgarwal1237
Copy link
Author

Fixed! Removed the hierarchical organization model from this branch -it belongs in a separate PR. This PR now contains only the SEIR model @codebreaker32

@codebreaker32
Copy link
Collaborator

Please remove it from README.md as well

@BittuAgarwal1237
Copy link
Author

done @codebreaker32

Comment on lines +8 to +12
States:
S - Susceptible: healthy, can get infected
E - Exposed: infected but not yet contagious
I - Infected: contagious, can spread to neighbors
R - Recovered: immune, cannot be infected again
Copy link
Collaborator

Choose a reason for hiding this comment

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


def agent_portrayal(agent):
return {
"color": STATE_COLORS.get(agent.state, "grey"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using raw dict is deprecated, Use AgentPortrayalStyle

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I looked into AgentPortrayalStyle but it doesn't seem to be available in the current Mesa dev version (4.0.0.dev0). Happy to update once it's added to the codebase, for now keeping the dict-based portrayal. Let me know if there's another approach you'd prefer!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

done!!! thanks


def step(self):
# 1. All people act first
for person in self.population:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use agents_by_type here?

person.step()

# 2. Government monitors and responds
self.government.step()
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should use agents_by_type and then can use shuffle_do for Random Activation

```bash
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's no requirements.txt?

## Overview

This model simulates how a disease spreads through a population on a grid, and how a government responds when things get bad enough.

Copy link
Collaborator

Choose a reason for hiding this comment

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

could you cite the original paper as well?

### [Humanitarian Aid Distribution Model](https://github.com/mesa/mesa-examples/tree/main/examples/humanitarian_aid_distribution)

This model simulates a humanitarian aid distribution scenario using a needs-based behavioral architecture. Beneficiaries have dynamic needs (water, food) and trucks distribute aid using a hybrid triage system.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add your model here

@BittuAgarwal1237
Copy link
Author

Updated all the feedback - used State Enum, switched to agents_by_type with shuffle_do, fixed README (removed requirements.txt, added paper citation, added model to main README). Model tested locally and running fine!
@EwoutH @codebreaker32

@BittuAgarwal1237 BittuAgarwal1237 force-pushed the add-seir-vaccination-example branch from c7d2aed to 3cdbce1 Compare March 21, 2026 17:01
@BittuAgarwal1237
Copy link
Author

done the changes @codebreaker32

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.

3 participants