roadrunner  2.6.0
Fast simulator for SBML models
GillespieIntegrator.h
1 // == PREAMBLE ================================================
2 
3 // * Licensed under the Apache License, Version 2.0; see README
4 
5 // == FILEDOC =================================================
6 
14 #ifndef GILLESPIEINTEGRATOR_H_
15 #define GILLESPIEINTEGRATOR_H_
16 
17 // == INCLUDES ================================================
18 
19 #include "Integrator.h"
20 #include "rrRoadRunnerOptions.h"
21 #include "rrExecutableModel.h"
22 #include "tr1proxy/rr_random.h"
23 
24 // == CODE ====================================================
25 
26 namespace rr
27 {
28 
29  class ExecutableModel;
30 
36  {
37  public:
38  using Integrator::Integrator;
39 
41 
42  ~GillespieIntegrator() override;
43 
49  void syncWithModel(ExecutableModel* m) override;
50 
51  // ** Meta Info ********************************************************
52 
58  std::string getName() const override;
59 
65  std::string getDescription() const override;
66 
72  std::string getHint() const override;
73 
74  Solver* construct(ExecutableModel* executableModel) const override;
75 
76  // ** Getters / Setters ************************************************
77 
82  IntegrationMethod getIntegrationMethod() const override;
83 
88  void setValue(const std::string& setting, Setting value) override;
89 
94  void resetSettings() override;
95 
96  // ** Integration Routines *********************************************
97 
102  double integrate(double t0, double tf) override;
103 
108  void restart(double timeStart) override;
109 
110  // ** Listeners ********************************************************
111 
116  IntegratorListenerPtr getListener() override;
117 
122  void setListener(IntegratorListenerPtr) override;
123 
124  private:
125  std::mt19937 engine;
126  //unsigned long seed;
127  double timeScale;
128  double stoichScale;
129  int nReactions;
130  int floatingSpeciesStart; // starting index of floating species
131  double* reactionRates;
132  double* reactionRatesBuffer;
133  int stateVectorSize;
134  double* stateVector;
135  double* stateVectorRate;
136  std::vector<unsigned char> eventStatus;
137  std::vector<unsigned char> previousEventStatus;
138 
139  void testRootsAtInitialTime();
140  void applyEvents(double timeEnd, std::vector<unsigned char> &prevEventStatus);
141 
142  double urand();
143  void setEngineSeed(Setting seedSetting);
144 
145  inline double getStoich(uint species, uint reaction)
146  {
147  return mModel->getStoichiometry(species, reaction);
148  }
149 
156  void initializeFromModel();
157  };
158 } /* namespace rr */
159 
160 #endif /* GILLESPIEINTEGRATOR_H_ */
RoadRunner's Gillespie SSA integrator.
Base class for all code generation systems; allows compiling and evaluating the model.
Definition: rrExecutableModel.h:118
virtual double getStoichiometry(int index)=0
Get the current stiochiometry value with the given index.
RoadRunner's implementation of the Gillespie SSA.
Definition: GillespieIntegrator.h:36
std::string getHint() const override
Get the hint for this integrator.
Definition: GillespieIntegrator.cpp:139
void restart(double timeStart) override
Reset time to zero and reinitialize model.
Definition: GillespieIntegrator.cpp:385
double integrate(double t0, double tf) override
Main integration routine.
Definition: GillespieIntegrator.cpp:190
Solver * construct(ExecutableModel *executableModel) const override
Constructs a new Solver of a given type.
Definition: GillespieIntegrator.cpp:439
std::string getName() const override
Get the name for this integrator.
Definition: GillespieIntegrator.cpp:127
std::string getDescription() const override
Get the description for this integrator.
Definition: GillespieIntegrator.cpp:131
IntegrationMethod getIntegrationMethod() const override
Always stochastic for Gillespie.
Definition: GillespieIntegrator.cpp:143
IntegratorListenerPtr getListener() override
Gets the integrator listener.
Definition: GillespieIntegrator.cpp:411
void resetSettings() override
Reset all integrator settings to their respective default values.
Definition: GillespieIntegrator.cpp:173
void setListener(IntegratorListenerPtr) override
Sets the integrator listener.
Definition: GillespieIntegrator.cpp:407
void syncWithModel(ExecutableModel *m) override
Called whenever a new model is loaded to allow integrator to reset internal state.
Definition: GillespieIntegrator.cpp:103
Integrator is an abstract base class that provides an interface to specific integrator class implemen...
Definition: Integrator.h:60
virtual void setValue(const std::string &key, Setting value)
Pull down the setValue from superclass.
Definition: Solver.cpp:125
Store a roadrunner option (or setting) as a Variant type.
Definition: Setting.h:78
Base class for all integrators and steady state solvers.
Definition: Solver.h:39
ExecutableModel * mModel
non-owning pointer to model
Definition: Solver.h:208
Base class for all code generators in RoadRunner.