Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wesdoyle/python_epidemic_simulation
A crude simulation of an epidemic in Python with pygame visualization
https://github.com/wesdoyle/python_epidemic_simulation
epidemic-simulations pygame simulation
Last synced: about 17 hours ago
JSON representation
A crude simulation of an epidemic in Python with pygame visualization
- Host: GitHub
- URL: https://github.com/wesdoyle/python_epidemic_simulation
- Owner: wesdoyle
- License: mit
- Created: 2020-04-05T22:01:30.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-12T03:25:37.000Z (6 months ago)
- Last Synced: 2025-01-24T05:04:50.553Z (8 days ago)
- Topics: epidemic-simulations, pygame, simulation
- Language: Python
- Homepage:
- Size: 20.5 MB
- Stars: 18
- Watchers: 3
- Forks: 239
- Open Issues: 41
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Python Epidemic Simulation
## Summary
### This is not a scientifically correct or rigorous simulation. It is used for programming learning purposes only!
This is a crude simulation of an edpidemic using Python and `pygame`.
The simulation consists of a 2-dimensional space in which a configurable number of epidemiological hosts move and transmit a contagious state with variable linear velocity.
Each host exists in a state of `unexposed`, `infected`, or `recovered`.
## Demos
### No Preventative Measures
![No measures](./example_gifs/simul_no_measures.gif)### Shelter In Place - Partial Adherence
![Shelter in place](./example_gifs/simul_shelter.gif)### Limit Travel - Partial Adherence
![Limit travel](./example_gifs/simul_limit_travel.gif)### Vaccinate, Shelter - Partial Adherence, Variable Drip
![Reduce travel](./example_gifs/simul_shelter_vaccine.gif)## Key simulation concepts:
### Basic Laws
The laws below govern the simulation:
- When initialized, a configured percentage of adherent hosts follow preventative measures.
- Unless limited by preventative measures, hosts initialize traveling in a random direction in a specified range of speed.
- If an `unexposed` and `infected` host come into contact, the `unexposed` host becomes `infected`
- `infected` hosts, while contagious, gradually recover over time
- All hosts survive
- After a configurable period of time, an `infected` host becomes `recovered`
- `recovered` hosts are not contagious### Preventative Measures
Several preventative measures can be simulated. A configurable percentage of the population adopting preventative measure can be chosen. Given a percentage of `PREVENTATIVE_MEASURE_ADHERENCE`, a random sample of the population is chosen to behave accordingly.
#### Shelter In Place
The `SHELTER_IN_PLACE` preventative measure sets the velocity of adhering hosts to 0 (permanent)
#### Vaccination
The `VACCINATE_POP` preventative measure provides the adhering hosts with a recovery multiplier. The vaccination for any host provides is a random value between 0 and `VACCINATION_DRIP`, which is added to the recovery constant for any host.
`VACCINATION_DRIP` is intended to simulate the idea that of the percentage of units that adhere, each vaccinates at a variable time. Vaccination effect takes place immediately, even if a host is in unexposed state.#### Limit Travel
The `LIMIT_TRAVEL` preventative measure sets the initial velocity of adhering hosts to 50%
## Running
### Manually run the simulation
Python 3 is required.
- Install dependencies:
- `pip install -r requirements.txt`- Customize parameters
- Edit any of the provided values in `constants.py` to change boundary conditions.
- the `PreventativeMeasure.SELECTED` array provides the active `PreventativeMeasures`- Run the simulation
- `python universe.py`
A `Makefile` is provided for convenience.## Credits
Thank you to [Vue Minh Khue's example](https://github.com/khuevu/pygames/tree/master/bouncingball), from which I adapted basic 2-dimensional particle interactions for simulating collisions between circular objects in `pygame`.## Improvements
Improvements, additions, and corrections to the simulation are welcome. Please create a pull request if you would like to contribue.