Skip to content

mads-risager/stochastic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stochastic

A C++ stochastic simulation library that provides a simple API to define species, reactions, and vessels. It supports customizable observers and batch simulations.

Usage

To simulate a reaction, see the following example:

#include <iostream>
#include <random>
#include "stochastic.hpp"


int main() {
    double end_time = 10.0;
    std::mt19937 rng(42);

    auto v = stochastic::Vessel{"A + B -> 2B"};
    auto A = v.add("A", 10);
    auto B = v.add("B", 1);
    double rate = 0.1;
    v.add((A + B) >> rate >>= B + B);


    auto observer = [](const stochastic::Observation &ob) {
        std::cout << ob.time << " A=" << ob.state.at("A")
                << " B=" << ob.state.at("B") << '\n';
    };

    stochastic::gillespie(v, end_time, observer, rng);
}

See the examples directory for more usage examples.

Building

To build the library using CMake, run the following commands:

cmake -S . -B build
cmake --build build

Testing

To run the tests, first build the library, then the following command:

ctest --test-dir build

About

A C++ stochastic simulation library.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors