Skip to content

rscherrer/reschoice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

reschoice

This is the source code for an individual-based simulation of evolutionary branching under various degrees of resource choice.

Build Tests Coverage

Description

This is a simulation of the evolution of a population of individuals through time, where what evolves is the trait values of individuals. Those trait values allow individuals to feed more-or-less efficiently on two types of resources spread across two habitats, with a utilization trade-off between the two resources. Under some parameter values those conditions should promote evolutionary branching into two separate clusters of individuals, each better adapted at feeding on one of the two resources. Notably, every generation, individuals go through multiple feeding rounds during which they make decisions on which resource to feed on, and those decisions are informed by the expected payoff each resource may bring to the individual. See manuscript for more details.

Installation

This program must be compiled. It is written in C++ and can be built using any modern C++ compiler and build system. Here we provide an example setup to build the program on several platforms using CMake.

Usage

This program has a command-line interface. Assuming the name of the compiled executable is reschoice, use the following command in the terminal from the working directory to run a simulation with default parameter values:

./reschoice

To run a simulation with custom parameters, use:

./reschoice parameters.txt

where parameters.txt is a text file containing a list of parameter names and values.

Parameters

The parameter file should look like this:

popsize 10
xstart 0
tradeoff 1
alpha 0.1
beta 1
delta 0.4
hsymmetry 0
nrounds 10
mutrate 0.0001
mutsdev 0.02
dispersal 0.01
tend 100
tsave 10
seed 12345
savepars 1
savedat 1
verbose 1
choose 1
memsave 1

In the parameter file, each line should contain a parameter name followed by its value. Lines starting with # will be treated as comments. Click here for a description of the available parameters and their meaning.

Output

The user can choose which variables to save from the simulation. Those have to be encoded in the whattosave.txt file provided that parameter choose is set to 1 within the parameters.txt file, as explained here. Output data are saved into binary files with the .dat extension. Those files can be read by any utility capable of reading binary, provided that the data type and byte size is known (e.g. doubles taking 8 bytes). We recommend using the R package readsim for that, as it was specifically designed to read and assemble into tables the kind of data generated by this program.

Tests

This program was tested using the Boost.Test library. All the tests can be found in the tests/ folder. Here we show how we tested the program locally using our own custom setup.

About

This code is written in C++20. It was developed on Ubuntu Linux 24.04 LTS, making mostly use of Visual Studio Code 1.99.0 (C/C++ Extension Pack 1.3.1). CMake 3.28.3 was used as build system, with g++ 13.3.0 as compiler. GDB 15.0.50.20240403 was used for debugging. Tests (see here) were written with Boost.Test 1.87, itself retrieved with Git 2.43.0 and vcpkg 2025.04.09. Memory use was checked with Valgrind 3.22.0. Code coverage was analyzed with gcov v13.3.0, LCOV 2.0-1 and the Coverage Gutters extension for Visual Studio Code 2.13.0. Profiling was performed with gprof 2.42. (See the dev/ folder and this page for details about the checks performed.) During development, occasional use was also made of ChatGPT and GitHub Copilot.

Links

Sister repositories include:

Permissions

Copyright (c) Raphaël Scherrer, 2025 (open source license will be added upon publication). This program is inspired by the thesis work of Joris Damhuis, which can be found at this link. This code comes with no guarantee whatsoever.