I was experimenting with Agent based models and came across a really great talk Jackie Kazil | Agent based modelling in Python. This lead me to look at the Python module that was being discussed Mesa | Agent-based modelling in Python 3+.
The Mesa project has many examples which I thought were a great place to get started. I decided to try to build a model that was similar to the Wolf Sheep model in this example: https://github.com/projectmesa/mesa/tree/main/examples/wolf_sheep.
So I cloned the repo and the rest of this blog post is based on my associated github repo.
I decided to use the concepts and framework for a simple workforce model, consisting of three agent types:
- GP Fellows (fully qualified and practicing)
- GP trainees (working towards qualification)
I made a few assumptions which were:
- The GP Fellows train trainees over 5 years
- The Trainees then become Fellows after 5 years.
- The GP Fellow may or may not take on another trainee.
The model tests and demonstrates several Mesa concepts and features:
- Multiple agent types (GP Fellow, Trainee and Patient)
- Overlay arbitrary text (Age and Sex of the Provider) on agent’s shapes while drawing on CanvasGrid
- Agents inheriting a behaviour (random movement) from an abstract parent
- Writing a model composed of multiple files.
- Dynamically adding and removing agents from the schedule
To install the dependencies use pip and the requirements.txt in this directory. e.g.
pip install -r requirements.txt
To run the model interactively, run
mesa runserver in this directory. e.g.
Then open your browser to http://127.0.0.1:8521/ and press Reset, then Run.
This lists the key files that were modified from the base Wolf and Sheep model that this is inherited from.