COPASI API  4.16.103
CStochMethod.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/trajectory/CStochMethod.h,v $
3 // $Revision: 1.35 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2012/06/04 17:58:00 $
7 // End CVS Header
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
20 // Properties, Inc. and EML Research, gGmbH.
21 // All rights reserved.
22 
23 #ifndef COPASI_CStochMethod
24 #define COPASI_CStochMethod
25 
26 #include <set>
27 #include <vector>
30 
31 class CModel;
32 class CMetab;
33 class CTrajectoryProblem;
34 
35 /**
36  * Integer Balances for internal use
37  */
39 {
40 public:
41  size_t mIndex;
43 };
44 
45 class CRandom;
46 
48 {
49  friend CTrajectoryMethod *
51 
52 protected:
53 
54  /**
55  * The propensities for the reactions
56  */
57  std::vector<C_FLOAT64> mAmu;
58 
59  /**
60  * The sum of the propensities
61  */
63 
64  /**
65  * The stored propensities for the reactions before the last update
66  */
67  std::vector<C_FLOAT64> mAmuOld;
68 
69  /**
70  * indicates if the correction N^2 -> N*(N-1) should be performed
71  */
73 
74  /**
75  * Indicates whether the model has global quantities with assignment rules.
76  * If it has, we will use a less efficient way to update the model
77  * state to handle this.
78  */
80 
81  /**
82  * Initialization.
83  */
84  virtual void initMethod(C_FLOAT64 start_time) = 0;
85 
86  /**
87  * Do one iteration of the simulation
88  * @return Current simulation time or -1 if error.
89  */
90  virtual C_FLOAT64 doSingleStep(C_FLOAT64 time, C_FLOAT64 endtime) = 0;
91 
92  /**
93  * Calculate the propensities for all reactions
94  * @return mFail
95  * @see mFail
96  */
98 
99  /**
100  * Calculate one of the propensities
101  * @return mFail
102  * @see mFail
103  */
104  C_INT32 calculateAmu(size_t reaction_index);
105 
106  /**
107  * Generate the index of a putative reaction.
108  * @return The reaction index
109  */
110  size_t generateReactionIndex();
111 
112  /**
113  * Generate the putative time taken before any reaction takes place
114  * @return The time before the reaction
115  */
117 
118  /**
119  * Generate the putative time taken before a special reaction takes place
120  * @return The time before the reaction
121  */
122  C_FLOAT64 generateReactionTime(size_t reaction_index);
123 
124  /**
125  * Update the particle numbers according to which reaction ocurred
126  * @return mFail
127  * @see mFail
128  */
129  C_INT32 updateSystemState(size_t reaction_index, const C_FLOAT64 & time);
130 
131  /**
132  * Set up the dependency graph and the balances
133  */
135 
136 private:
137 
138  /**
139  * This checks if a model is suitable for stochastic simulation.
140  * It returns a suggestion which method to use
141  * @param model The model to check
142  * @return 1: direct method, 2: next reaction method, -1: no stochastic simulation possible
143  */
144  static C_INT32 checkModel(CModel * pmodel);
145 
146  /**
147  * Get the set of metabolites on which a given reaction depends.
148  * @param reaction_index The index of the reaction being executed.
149  * @return The set of metabolites depended on.
150  */
151  std::set<std::string> *getDependsOn(size_t reaction_index);
152 
153  /**
154  * Get the set of metabolites which change number when a given
155  * reaction is executed.
156  * @param reaction_index The index of the reaction being executed.
157  * @return The set of affected metabolites.
158  */
159  std::set<std::string> *getAffects(size_t reaction_index);
160 
161  /**
162  * max number of single stochastic steps to do in one step()
163  */
164  size_t mMaxSteps;
165 
166  /**
167  * maximal increase of a particle number in one step.
168  */
170 
171  /**
172  * This is set to maxint - mMaxSteps*mMaxBalance
173  */
175 
177 
178 protected:
179  /**
180  * Default constructor.
181  * @param const CCopasiContainer * pParent (default: NULL)
182  */
183  CStochMethod(const CCopasiContainer * pParent = NULL);
184 
185 public:
186  /**
187  * Copy constructor.
188  * @param const CStochMethod & src,
189  * @param const CCopasiContainer * pParent (Default: NULL)
190  */
191  CStochMethod(const CStochMethod & src,
192  const CCopasiContainer * pParent = NULL);
193 
194  /**
195  * Destructor.
196  */
197  ~CStochMethod();
198 
199  /**
200  * This methods must be called to elevate subgroups to
201  * derived objects. The default implementation does nothing.
202  * @return bool success
203  */
204  virtual bool elevateChildren();
205 
206  /**
207  * This instructs the method to calculate a time step of deltaT
208  * starting with the current state, i.e., the result of the previous
209  * step.
210  * The new state (after deltaT) is expected in the current state.
211  * The return value is the actual timestep taken.
212  * @param "const double &" deltaT
213  * @return Status status
214  */
215  virtual Status step(const double & deltaT);
216 
217  /**
218  * This instructs the method to prepare for integration
219  * starting with the initialState given.
220  * @param "const CState *" initialState
221  */
222  virtual void start(const CState * initialState);
223 
224  /**
225  * Check if the method is suitable for this problem
226  * @return bool suitability of the method
227  */
228  virtual bool isValidProblem(const CCopasiProblem * pProblem);
229 
230 private:
231  /**
232  * Intialize the method parameter
233  */
234  void initializeParameter();
235 
236 protected:
237 
238  /**
239  * The random number generator
240  */
242 
243  /**
244  * A pointer to the instance of CModel being used.
245  */
247 
248  /**
249  * The graph of reactions and their dependent reactions. When a reaction is
250  * executed, the propensities for each of its dependents must be updated.
251  */
253 
254  /**
255  * The balances of the reactions as integers
256  */
257  std::vector < std::vector <CStochBalance> > mLocalBalances;
258 
259  /**
260  * the substrates of each reaction with their multiplicities
261  */
262  std::vector < std::vector <CStochBalance> > mLocalSubstrates;
263 
264  /**
265  * The particle numbers
266  */
267  std::vector <C_INT64> mNumbers;
268 
270 
271  /**
272  * index of first metab in a CState
273  */
275 
276  /**
277  * tests if the model contains a global value with an assignment rule that is
278  * used in calculations
279  */
280  static bool modelHasAssignments(const CModel* pModel);
281 };
282 
283 //#include "CStochDirectMethod.h"
284 //#include "CStochNextReactionMethod.h"
285 
286 #endif // COPASI_CStochMethod
size_t generateReactionIndex()
bool mMaxStepsReached
Definition: CStochMethod.h:176
std::vector< C_FLOAT64 > mAmu
Definition: CStochMethod.h:57
virtual void initMethod(C_FLOAT64 start_time)=0
virtual C_FLOAT64 doSingleStep(C_FLOAT64 time, C_FLOAT64 endtime)=0
std::set< std::string > * getAffects(size_t reaction_index)
C_INT32 updatePropensities()
std::set< std::string > * getDependsOn(size_t reaction_index)
std::vector< std::vector< CStochBalance > > mLocalBalances
Definition: CStochMethod.h:257
std::vector< C_FLOAT64 > mAmuOld
Definition: CStochMethod.h:67
bool mDoCorrection
Definition: CStochMethod.h:72
void initializeParameter()
virtual bool elevateChildren()
CModel * mpModel
Definition: CStochMethod.h:246
Definition: CState.h:305
#define C_INT64
Definition: copasi.h:88
std::vector< std::vector< CStochBalance > > mLocalSubstrates
Definition: CStochMethod.h:262
CDependencyGraph mDG
Definition: CStochMethod.h:252
#define C_INT32
Definition: copasi.h:90
static C_INT32 checkModel(CModel *pmodel)
Definition: CMetab.h:178
size_t mNumReactions
Definition: CStochMethod.h:269
C_INT32 mMultiplicity
Definition: CStochMethod.h:42
bool mHasAssignments
Definition: CStochMethod.h:79
virtual void start(const CState *initialState)
C_INT32 updateSystemState(size_t reaction_index, const C_FLOAT64 &time)
static CTrajectoryMethod * createMethod(CCopasiMethod::SubType subType=CCopasiMethod::deterministic)
size_t mMaxSteps
Definition: CStochMethod.h:164
CStochMethod(const CCopasiContainer *pParent=NULL)
#define C_FLOAT64
Definition: copasi.h:92
C_INT32 calculateAmu(size_t reaction_index)
C_INT64 mMaxIntBeforeStep
Definition: CStochMethod.h:174
void setupDependencyGraphAndBalances()
Definition: CModel.h:50
CRandom * mpRandomGenerator
Definition: CStochMethod.h:241
C_FLOAT64 generateReactionTime()
C_FLOAT64 mA0
Definition: CStochMethod.h:62
std::vector< C_INT64 > mNumbers
Definition: CStochMethod.h:267
C_INT32 mMaxBalance
Definition: CStochMethod.h:169
virtual bool isValidProblem(const CCopasiProblem *pProblem)
virtual Status step(const double &deltaT)
size_t mFirstMetabIndex
Definition: CStochMethod.h:274
static bool modelHasAssignments(const CModel *pModel)