An open API service indexing awesome lists of open source software.

https://github.com/rscherrer/reschoice

Simulation of evolutionary branching under optimal resource choice
https://github.com/rscherrer/reschoice

behavior branching ecology evolution foraging individual-based modeling resources selection simulation speciation

Last synced: about 1 month ago
JSON representation

Simulation of evolutionary branching under optimal resource choice

Awesome Lists containing this project

README

          

# reschoice

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

![Build](https://img.shields.io/badge/build-passing-brightgreen)
![Tests](https://img.shields.io/badge/tests-passing-brightgreen)
![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)
[![DOI](https://img.shields.io/badge/DOI-10.32942/X2T36C-blue)](https://doi.org/10.32942/X2T36C)
[![Zenodo](https://img.shields.io/badge/Zenodo-10.5281/zenodo.18497296-blue)](https://doi.org/10.5281/zenodo.18497296)

## 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](doc/SETUP.md) 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:

```shell
./reschoice
```

To run a simulation with custom parameters, use:

```shell
./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](doc/PARAMETERS.md) 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](doc/OUTPUT.md). 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](https://www.r-project.org/) package [readsim](https://github.com/rscherrer/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](https://www.boost.org/doc/libs/1_85_0/libs/test/doc/html/index.html) library. All the tests can be found in the `tests/` folder. [Here](doc/TESTS.md) 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](https://code.visualstudio.com/) 1.99.0 ([C/C++ Extension Pack](https://marketplace.visualstudio.com/items/?itemName=ms-vscode.cpptools-extension-pack) 1.3.1). [CMake](https://cmake.org/) 3.28.3 was used as build system, with [g++](https://gcc.gnu.org/) 13.3.0 as compiler. [GDB](https://www.gnu.org/savannah-checkouts/gnu/gdb/index.html) 15.0.50.20240403 was used for debugging. Tests (see [here](doc/TESTS.md)) were written with [Boost.Test](https://www.boost.org/doc/libs/1_85_0/libs/test/doc/html/index.html) 1.87, itself retrieved with [Git](https://git-scm.com/) 2.43.0 and [vcpkg](https://github.com/microsoft/vcpkg) 2025.04.09. Memory use was checked with [Valgrind](https://valgrind.org/) 3.22.0. Code coverage was analyzed with [gcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html) v13.3.0, [LCOV](https://github.com/linux-test-project/lcov) 2.0-1 and the [Coverage Gutters](https://github.com/ryanluker/vscode-coverage-gutters) extension for Visual Studio Code 2.13.0. Profiling was performed with [gprof](https://ftp.gnu.org/old-gnu/Manuals/gprof-2.9.1/html_mono/gprof.html) 2.42. (See the `dev/` folder and [this page](dev/README.md) for details about the checks performed.) During development, occasional use was also made of [ChatGPT](https://chatgpt.com/) and [GitHub Copilot](https://github.com/features/copilot).

## Links

* [reschoice](https://github.com/rscherrer/reschoice): source code
* [reschoice-r](https://github.com/rscherrer/reschoice-r): analysis code and results
* [reschoice-ms](https://github.com/rscherrer/reschoice-ms): manuscript

Some parts of the code presented here have since been made into the following libraries:

* [readpars](https://github.com/rscherrer/readpars): parameter file reader
* [binprint](https://github.com/rscherrer/binprint): save binary output files

## Notes

* A version of this repository has been archived at Zenodo and can be accessed via the following [link](https://doi.org/10.5281/zenodo.18497296).
* The associated manuscript is publicly available on the preprint server EcoEvoRxiv, accessible [here](https://doi.org/10.32942/X2T36C).

## Permissions

Copyright (c) Raphaël Scherrer and Joris Damhuis, 2025. This code is licensed under the MIT license. See [license file](LICENSE.txt) for details. This program is inspired by the thesis work of Joris Damhuis, which can be found at this [link](https://github.com/J-Damhuis/Eco-Evolutionary-Dynamics). This code comes with no guarantee whatsoever.