Written on 2019-04-08
Six years ago, I was looking for a new programming project. My dream was to create a self-sustaining “virtual world”, a little ecosystem inside my computer. This was long before I knew there actually was a field called “ecological modelling” (which I now happen to work in), but the idea intrigued me. So I set about the task with all the confidence of one year's programming experience. I failed. But a year later, I picked up the pieces and started over, eventually producing a graphical ecosystem simulator – Ecologia.
Written on and off over the course of two years, Ecologia mainly consists of around 4000 lines of Java, with some additional Python and R scripts for post-run data analysis. (The source code may be found here.) This is what it looks like in action:
Screenshot of Ecologia. The executable JAR is downloadable here.
The program simulates three trophic levels: producers (plants), herbivores and carnivores. Each tile has a grass density, that increases when the humidity is high enough and decreases through grazing, or when there is a drought. The current grass density is shown by the tile colour (green, yellow, or white). The humidity is set globally to one of five values (see the drop box on the right), but may be overridden locally if there is a water hole (blue tile) nearby.
Animals are represented by the circles – herbivores grey, carnivores red. Herbivores follow the vegetation, run away from carnivores, or simply move at random. Carnivores hunt the herbivores. Each individual animal has an energy level that is depleted with movement or (asexual) reproduction, and filled up by eating. If the energy hits zero, or the animal is too old, it dies.
Each animal also has a “genome”, a list of traits with associated values that govern things like their range of eyesight, their running speed, or their metabolic efficiency. These traits are passed down to offspring, but may be mutated along the way. Of course, the default settings for the genome, along with all other simulation settings (such as the world size or the number of water tiles) may be configured, either graphically or with a config file.
As well as watching the simulation unfold on the screen, you can also tell
Ecologia to print out a log file (at varying levels of verbosity). This can then
be used for further analysis. For example, you can use the scripts population.py
and population.R
(in the analysis/demography
subfolder) to create population
graphs over time:
Quite frankly, the primary purpose of Ecologia was to provide a fun programming project – which it did. (Incidentally, it also got me into the research group I'm working in now, but that's another story.)
However, it could also be a useful tool to teach the basics of ecology in school, specifically predator-prey dynamics. The Lotka-Volterra model commonly crops up in the higher years of secondary school biology and is well illustrated by this computer simulation (see the graph above). It is intuitive to watch and understand: the more prey there is, the more predators have to eat; the more predators there are, the more prey they kill. Or at a lower trophic level: how many herbivores there are determines the amount of grass available, and vice versa.
Simple exercises are easy to carry out: What happens in a drought? Why are there so many fewer predators than prey? How many carnivores does it take to make all the herbivores go extinct? But it can also address more challenging questions: Are Lotka-Volterra dynamics produced by top-down or bottom-up regulation? (You need to look at all three trophic levels for this.)
It also has a lesson to teach about the stability of ecosystems. Although the default settings produce relatively stable population cycles over several thousand updates, this is by no means a necessity. In fact, I had to work pretty hard to get to this stage! Under most configurations, the predators either die out immediately, or they kill off all herbivores and then die out. (Try twiddling some settings and see what happens – changing the carnivores' running speed might be a good place to start. In short, what we have here is a metastable system. Might the ecosystems we live in also be metastable? And if so, how hard must you push to get them to topple?
This is where we leave the virtual world and come slap-bang back into our own. Simulations can never replace studying the great outdoors. But if they set us thinking, or allow us to experiment more freely than we otherwise could, or show us what might happen, they have fulfilled their purpose.
Ecologia is, in a sense, child's play. But it is fun nonetheless, and perhaps just a bit useful. So if you would like to use it for a lesson, or just play around with it, go ahead! If you do, make sure to let me know – I'd love to hear.