A cross-platform, multi-threaded population simulation in which organisms make decisions using a neural network and evolve through horizontal gene transfer, replication and mutation.
Created as the final assignment for the university module Data Structures and Algorithms 2. Grade: A+
This project uses CMake to simplify the build process across different platforms. Make sure CMake is installed before proceeding.
CMake will locate the required dependencies automatically - just ensure Boost and SFML are installed (e.g. on Windows, place their files under Program Files
) before proceeding.
The build must then be configured with CMake before using the the target build system to compile the project. For example, on Windows (with Visual Studio installed), in the top-level project directory:
mkdir build
cd build
cmake ../src
cmake --build . --config Release
Or on Linux (with GCC and Make installed):
mkdir build
cd build
cmake ../src -DCMAKE_BUILD_TYPE=Release
make
On Windows, the .sln
file generated by cmake ../src
can also be opened in Visual Studio for building there.
Once the build process is complete, copy the resulting executable genetic_simulation
or genetic_simulation.exe
(e.g. from the build
or build/Release
directory) to the top-level project directory, so that the program will be able to locate the config and data files it requires. On Windows, you may have to place the SFML .dll
files in the same directory as the executable to allow it to find these.
The program can be run with the -h
switch, which will print command-line usage information. Additionally, it reads configuration information from the file config.ini
, which it looks for by default in the current directory or in a config
folder in the current directory. See the included file config/config.ini
for all of the supported options which may be used to configure the simulation.
When running, the simulation viewport can be moved with the arrow keys, and zoomed in and out with W
and S
. Pressing F
will switch between viewing mode (limited, constant number of timesteps per second) or fast-forward mode (as fast as possible, zooming and panning not permitted).
The moving circles in the simulation are organisms, whose color represents their fitness, where red is low and green is high. Stationary dark green circles are food, and similar light blue circles are water. When an organism transfers genes from another organism, its outline will flash dark blue before fading back to its normal colour.
The default configuration attempts to provide a stable set of options to allow the population to evolve successfully, but note that even with the random seed fixed the precise scheduling of the threads may affect gene flow and thus the flow of the simulation.