3.2.11.7. causality/Stochsim.hpp

3.2.11.7.1. Class causality::MassActionKinetics

class causality::MassActionKinetics

A helper class for performing stochastic simulations where events are drawn according to the law of mass action. Importantly, if the underlying derivation graph is enlarged then syncSize() must be called before calling draw().

3.2.11.7.1.1. Synopsis

MassActionKinetics(std::shared_ptr<dg::DG> dg_, std::function<std::pair<double, bool>(dg::DG::Vertex)> inputRate, std::function<std::pair<double, bool>(dg::DG::HyperEdge)> reactionRate, std::function<std::pair<double, bool>(dg::DG::Vertex)> outputRate)
void syncSize()
std::pair<std::optional<Action>, double> draw(const Marking &m)

3.2.11.7.1.2. Details

MassActionKinetics(std::shared_ptr<dg::DG> dg_, std::function<std::pair<double, bool>(dg::DG::Vertex)> inputRate, std::function<std::pair<double, bool>(dg::DG::HyperEdge)> reactionRate, std::function<std::pair<double, bool>(dg::DG::Vertex)> outputRate)

Construct a new instance, based on the given derivation graph. The return value of the rate callbacks must be 1) the rate and 2) a boolean telling whether the library should cache the rate. If true no more calls with the same argument will be made.

Throws:

LogicError if !dg_.

Throws:

LogicError if neither dg_->hasActiveBuilder() nor dg_->isLocked().

Throws:

LogicError if !inputRate.

Throws:

LogicError if !reactionRate.

Throws:

LogicError if !outputRate.

void syncSize()

Enlarges the internal data structures to the current size of the underlying derivation graph.

std::pair<std::optional<Action>, double> draw(const Marking &m)
Returns:

an action, randomly selected according to the low of mass action based on the given population/marking and the rates. The second returned component is the sum of reactivity for the given reactions/hyperedges.

If no events are possible, then the second component is 0.0 and the first component has no value.

Use rngReseed() to seed the pseudo-random bit generator used for the selection.

Throws:

LogicError if m is not a marking on the underlying derivation graph.

Requires syncSize() to have been called since the last time the underlying derivation graph has changed size.