3.2.11.5. causality/Stochsim.hpp

3.2.11.5.1. Class causality::DrawMassActionFunction

class causality::DrawMassActionFunction

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.5.1.1. Synopsis

DrawMassActionFunction(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.5.1.2. Details

DrawMassActionFunction(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. Each of the rate functions may be an empty std::function (i.e., default constructed), which means a default rate is used: input rate 0.0, reaction rate 1.0, output rate 0.0.

Throws:

LogicError if !dg_.

Throws:

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

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.