C API Documentation
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:
39  virtual ~GillespieIntegrator();
40 
46  virtual void syncWithModel(ExecutableModel* m);
47 
48  // ** Meta Info ********************************************************
49 
55  std::string getName() const;
56 
61  static std::string getGillespieName();
62 
68  std::string getDescription() const;
69 
74  static std::string getGillespieDescription();
75 
81  std::string getHint() const;
82 
87  static std::string getGillespieHint();
88 
89  // ** Getters / Setters ************************************************
90 
95  IntegrationMethod getIntegrationMethod() const;
96 
101  void setValue(std::string setting, const Variant& value);
102 
108 
109  // ** Integration Routines *********************************************
110 
115  double integrate(double t0, double tf);
116 
121  void restart(double timeStart);
122 
123  // ** Listeners ********************************************************
124 
129  IntegratorListenerPtr getListener();
130 
135  void setListener(IntegratorListenerPtr);
136 
137  private:
138  ExecutableModel *model;
139  cxx11_ns::mt19937 engine;
140  //unsigned long seed;
141  double timeScale;
142  double stoichScale;
143  int nReactions;
144  int floatingSpeciesStart; // starting index of floating species
145  double* reactionRates;
146  double* reactionRatesBuffer;
147  int stateVectorSize;
148  double* stateVector;
149  double* stateVectorRate;
150  // m rows x n cols
151  // offset = row*NUMCOLS + column
152  int stoichRows;
153  int stoichCols;
154  double* stoichData;
155  std::vector<unsigned char> eventStatus;
156  std::vector<unsigned char> previousEventStatus;
157 
158  void testRootsAtInitialTime();
159  void applyEvents(double timeEnd, std::vector<unsigned char> &previousEventStatus);
160 
161  double urand();
162  void setEngineSeed(unsigned long seed);
163  unsigned long getSeed() const;
164 
165  inline double getStoich(uint species, uint reaction)
166  {
167  return stoichData[species * stoichCols + reaction];
168  }
169 
176  void initializeFromModel();
177  };
178 
179 
180  // ** Registration *********************************************************
181 
182 
184  public:
189  virtual std::string getName() const {
191  }
192 
197  virtual std::string getDescription() const {
199  }
200 
205  virtual std::string getHint() const {
207  }
208 
213  virtual Integrator* construct(ExecutableModel *model) const {
214  return new GillespieIntegrator(model);
215  }
216  };
217 
218 } /* namespace rr */
219 
220 #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
RoadRunner's implementation of the Gillespie SSA.
Definition: GillespieIntegrator.h:36
static std::string getGillespieDescription()
Get the description for this integrator.
std::string getName() const
Get the name for this integrator.
void resetSettings()
Reset all integrator settings to their respective default values.
static std::string getGillespieHint()
Get the hint for this integrator.
void setValue(std::string setting, const Variant &value)
Sets the value of an integrator setting (e.g. absolute_tolerance)
IntegratorListenerPtr getListener()
Gets the integrator listener.
double integrate(double t0, double tf)
Main integration routine.
void restart(double timeStart)
Reset time to zero and reinitialize model.
std::string getHint() const
Get the hint for this integrator.
virtual void syncWithModel(ExecutableModel *m)
Called whenever a new model is loaded to allow integrator to reset internal state.
void setListener(IntegratorListenerPtr)
Sets the integrator listener.
std::string getDescription() const
Get the description for this integrator.
IntegrationMethod getIntegrationMethod() const
Always stochastic for Gillespie.
static std::string getGillespieName()
Get the name for this integrator.
Definition: GillespieIntegrator.h:183
virtual std::string getDescription() const
Gets the description associated with this integrator type.
Definition: GillespieIntegrator.h:197
virtual Integrator * construct(ExecutableModel *model) const
Constructs a new integrator of a given type.
Definition: GillespieIntegrator.h:213
virtual std::string getName() const
Gets the name associated with this integrator type.
Definition: GillespieIntegrator.h:189
virtual std::string getHint() const
Gets the hint associated with this integrator type.
Definition: GillespieIntegrator.h:205
Definition: Integrator.h:62
Handles constructing an integrator and contains meta information about it.
Definition: Integrator.h:161
Definition: Variant.h:75
Base class for all code generators in RoadRunner.