Skip to content

This is a simulation package, exploring the exciting lives of herbivores and carnivores on an island with limited resources. Have fun :)

License

Notifications You must be signed in to change notification settings

danhje/population-dynamics-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Population Dynamics Simulator

This is a population dynamics simulator, exploring the exciting lives of herbivores and carnivores on an island with limited resources.

Written by Aleksander Hykkerud and Daniel Hjertholm in 2012, as an exercise in the cours INF200 - Anvanced Programming at the NMBU.

In the graphic below, from top left to bottom right: Plot of population sizes, the island with its different terrain types, and two heat maps showing the density of herbivores and carnivores, respectively.

Simulation

Even thought the simulator is relatively primitive, it is able to reproduce a lot of the phenomenon that are actually observed in nature, like periodic population cycles, lag effects and the overshoot-and-collapse effect.

The course in which this simulator was developed focused on unit testing and performance optimization. Thus, almost every method is regorously tested. Optimization of code was done by first profiling with cProfile. This revealed that a single method, the method that calculated and returned the fitness of a given individual, was called about 50 million times in a typical simulation, and accounted for 60% of the total CPU time. Based on this, the method was replaced with a fitness variable, which was only re-calculated when it needed to change. This change resulted in a factor 4 decrease in the CPU time used to calculate fitness. The calculation still used about 15% of the total CPU time, but by "cythonizing" it, i.e. transpiling it to C with the use of Cython, this was further decreased to 3.7% CPU time.

The update_fitness method before cythonization:

Before Cython

The update_fitness method after cythonization:

After Cython

Profiling done using cProfile:

Profiling done using cProfile

Documentation for the project was automatically generated through the use of Sphinx and docstrings.

About

This is a simulation package, exploring the exciting lives of herbivores and carnivores on an island with limited resources. Have fun :)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages