COPASI API  4.16.103
CProcessQueue.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2014 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 #ifndef COPASI_CProcessQueue
12 #define COPASI_CProcessQueue
13 
14 #include <map>
15 #include <set>
16 
18 #include "copasi/model/CEvent.h"
19 
20 class CExpression;
21 class CMathModel;
22 class CMathEvent;
23 
25 {
26 private:
27  class CKey
28  {
29  friend std::ostream &operator<<(std::ostream &os, const CProcessQueue & o);
30 
31  // Operations
32  public:
33  /**
34  * Default constructor
35  */
36  CKey();
37 
38  /**
39  * Copy constructor
40  * @param const CKey & src
41  */
42  CKey(const CKey & src);
43 
44  /**
45  * Specific constructor
46  * @param const C_FLOAT64 & executionTime
47  * @param const bool & equality
48  * @param const size_t & cascadingLevel
49  */
50  CKey(const C_FLOAT64 & executionTime,
51  const bool & equality,
52  const size_t & cascadingLevel);
53 
54  /**
55  * Destructor
56  */
57  ~CKey();
58 
59  /**
60  * A less than sort operator for sorting the entries in the queue
61  * @param const CKey & rhs
62  * @return bool lessThan
63  */
64  bool operator < (const CKey & rhs) const;
65 
66  /**
67  * Retrieve the execution time.
68  * @return const C_FLOAT64 & executionTime
69  */
70  inline const C_FLOAT64 & getExecutionTime() const {return mExecutionTime;}
71 
72  friend std::ostream &operator<<(std::ostream &os, const CKey & o);
73 
74  // Attributes
75  private:
76  /**
77  * The time the entry is scheduled to be executed.
78  */
80 
81  /**
82  * Cascading level
83  */
85 
86  /**
87  * A Boolean value indication whether we have equality or inequality.
88  * Equalities have to be handled prior to inequalities
89  */
90  bool mEquality;
91  };
92 
93  friend std::ostream &operator<<(std::ostream &os, const CKey & o);
94 
95  class CAction
96  {
97  public:
98  enum Type
99  {
103  };
104 
105  // Operations
106  private:
107  /**
108  * Default constructor (hidden)
109  */
110  CAction();
111 
112  public:
113  /**
114  * Copy constructor
115  * @param const CAction & src
116  */
117  CAction(const CAction & src);
118 
119  /**
120  * Specific constructor
121  * @param CMathEvent * pEvent
122  * @param CProcessQueue * pProcessQueue
123  */
124  CAction(CMathEvent * pEvent,
125  CProcessQueue * pProcessQueue);
126 
127  /**
128  * Specific constructor
129  * @param const CVector< C_FLOAT64 > & values
130  * @param CMathEvent * pEvent
131  * @param CProcessQueue * pProcessQueue
132  */
133  CAction(const CVector< C_FLOAT64 > & values,
134  CMathEvent * pEvent,
135  CProcessQueue * pProcessQueue);
136 
137  /**
138  * Destructor (hidden)
139  */
140  ~CAction();
141 
142  /**
143  * Process the action
144  * @return bool stateChanged
145  */
146  bool process();
147 
148  /**
149  * Retrieve the event id
150  * @return CMathEvent * pEvent
151  */
152  inline CMathEvent * getEvent() const {return mpEvent;}
153 
154  /**
155  * Retrieve the type of action
156  * @return const Type & type
157  */
158  const Type & getType() const;
159 
160  friend std::ostream &operator<<(std::ostream &os, const CAction & o);
161 
162  // Attributes
163  public:
164  /**
165  * The type of the actions
166  */
168 
169  /**
170  * The new value if the entry is an assignment.
171  */
173 
174  /**
175  * The event associated with this action
176  */
178 
179  /**
180  * A pointer to the process queue to which a subsequent assignment must be added if
181  * the entry is a calculation.
182  */
184  };
185 
186  friend std::ostream &operator<<(std::ostream &os, const CAction & o);
187 
188  // Type definitions
189 public:
190  typedef std::multimap< CKey, CAction >::iterator iterator;
191 
192  typedef std::pair < std::multimap< CKey, CAction >::iterator, std::multimap< CKey, CAction >::iterator > range;
193 
194  typedef iterator(*resolveSimultaneousAssignments)(const std::multimap< CKey, CAction > & /* assignments */,
195  const C_FLOAT64 & /* time */,
196  const bool & /* equality */,
197  const size_t & /* cascadingLevel */);
198 
199  /**
200  * This is the type for an event call back function
201  */
202  typedef void (*EventCallBack)(void*, CEvent::Type type);
203 
204  // Operations
205 public:
206  /**
207  * Default constructor
208  */
209  CProcessQueue();
210 
211  /**
212  * Copy constructor
213  */
214  CProcessQueue(const CProcessQueue & src);
215 
216  /**
217  * Destructor
218  */
219  ~CProcessQueue();
220 
221  /**
222  * Add an assignment to the process queue.
223  * @param const C_FLOAT64 & executionTime
224  * @param const bool & equality
225  * @param const CVector< C_FLOAT64 > & values
226  * @param CMathEvent * pEvent
227  * @return bool success
228  */
229  bool addAssignment(const C_FLOAT64 & executionTime,
230  const bool & equality,
231  const CVector< C_FLOAT64 > & values,
232  CMathEvent * pEvent);
233 
234  /**
235  * Add a calculation to the process queue.
236  * @param const C_FLOAT64 & executionTime
237  * @param const bool & equality
238  * @param CMathEvent * pEvent
239  * @return bool success
240  */
241  bool addCalculation(const C_FLOAT64 & executionTime,
242  const bool & equality,
243  CMathEvent * pEvent);
244 
245  /**
246  * Clear the process queue.
247  * @param CMathModel * pMathModel
248  */
249  void initialize(CMathModel * pMathModel);
250 
251  /**
252  * Process the queue.
253  * @param const C_FLOAT64 & time
254  * @param const bool & priorToOutput
255  * @param resolveSimultaneousAssignments pResolveSimultaneousAssignments
256  * @return bool stateChanged
257  */
258  bool process(const C_FLOAT64 & time,
259  const bool & priorToOutput,
260  resolveSimultaneousAssignments pResolveSimultaneousAssignments);
261 
262  /**
263  * Retrieve the next execution time scheduled in the process queue
264  * @return const C_FLOAT64 & processQueueExecutionTime
265  */
266  const C_FLOAT64 & getProcessQueueExecutionTime() const;
267 
268  /**
269  * Set whether to continue on simultaneous events
270  * @param const bool & continueSimultaneousEvents
271  */
272  void setContinueSimultaneousEvents(const bool & continueSimultaneousEvents);
273 
274  /**
275  * Retrieve whether to continue on simultaneous events.
276  * @return const bool & continueSimultaneousEvents
277  */
278  const bool & getContinueSimultaneousEvents() const;
279 
280  /**
281  * Sets an event call back. The call back function must be a static function
282  * that receives a "this" pointer as first argument.
283  * The function is called when the actual assignment takes place,
284  * or when the assignment would take place in case the event
285  * has no assignment.
286  * The function is called with an integer argument:
287  * 1: An assignment has happened
288  * 2: A cut plane was crossed
289  */
290  void setEventCallBack(void* pTask, EventCallBack ecb);
291 
292  /**
293  * This prints debugging info to stdout
294  */
295  void printDebug() const {std::cout << *this; };
296 
297  friend std::ostream &operator<<(std::ostream &os, const CProcessQueue & o);
298 
299 private:
300  /**
301  * Destroy a unique eventId
302  * @@param const size_t & eventId;
303  */
304  void destroyEventId(const size_t & eventId);
305 
306  /**
307  * Retrieve the currently pending actions
308  * @return CProcessQueue::iterator itAction
309  */
311 
312  /**
313  * Execute the actions
314  * @param CProcessQueue::iterator itAction
315  * @return bool stateChanged
316  */
317  bool executeAction(CProcessQueue::iterator itAction);
318 
319  /**
320  * Check whether the executions of assignment lead to newly found roots
321  * @return bool rootsFound
322  */
323  bool rootsFound();
324 
325  /**
326  * Check whether a range is not empty
327  * @param const range & range
328  * bool notEmpty
329  */
330  static bool notEmpty(const range & range);
331 
332  // Attributes
333 private:
334  /**
335  * An ordered list of calculations in the queue.
336  */
337  std::multimap< CKey, CAction > mActions;
338 
339  /**
340  * The limit of execution steps allowed for call to process
341  */
343 
344  /**
345  * A counter of the execution steps for the current process
346  */
348 
349  /**
350  * The current time
351  */
353 
354  /**
355  * Indicate whether we processing equality or inequality
356  */
357  bool mEquality;
358 
359  /**
360  * The cascading level of events
361  */
363 
364  /**
365  * A flag indicating that simultaneous assignments have been found.
366  */
368 
369  /**
370  * A set of currently active event ids
371  */
372  std::set< size_t > mEventIdSet;
373 
374  /**
375  * A pointer to the math model the process queue belongs to.
376  */
378 
379  /**
380  *
381  */
383 
384  /**
385  *
386  */
388 
389  /**
390  *
391  */
393 
394  /**
395  *
396  */
398 
399  /**
400  *
401  */
403 
404  /**
405  * A pointer to a call back method for resolving simultaneous event assignments
406  */
408 
409  /**
410  * A flag indicating to continue when simultaneous events are encountered.
411  */
413 
414  /**
415  * the object to which the call back function belongs
416  */
418 
419  /**
420  * the pointer to the call back function
421  */
423 };
424 
425 #endif // COPASI_CProcessQueue
void initialize(CMathModel *pMathModel)
C_FLOAT64 mTime
iterator getAction()
CVector< C_FLOAT64 > * mpRootValuesAfter
const C_FLOAT64 & getProcessQueueExecutionTime() const
C_FLOAT64 mExecutionTime
Definition: CProcessQueue.h:79
friend std::ostream & operator<<(std::ostream &os, const CProcessQueue &o)
CVector< C_FLOAT64 > mRootValues1
static bool notEmpty(const range &range)
const Type & getType() const
Type
Definition: CEvent.h:155
bool addAssignment(const C_FLOAT64 &executionTime, const bool &equality, const CVector< C_FLOAT64 > &values, CMathEvent *pEvent)
size_t mExecutionLimit
std::pair< std::multimap< CKey, CAction >::iterator, std::multimap< CKey, CAction >::iterator > range
std::set< size_t > mEventIdSet
size_t mCascadingLevel
EventCallBack mpEventCallBack
CTSSATask * pTask
void printDebug() const
void(* EventCallBack)(void *, CEvent::Type type)
bool operator<(const CKey &rhs) const
void setContinueSimultaneousEvents(const bool &continueSimultaneousEvents)
void setEventCallBack(void *pTask, EventCallBack ecb)
friend std::ostream & operator<<(std::ostream &os, const CKey &o)
CMathModel * mpMathModel
CVector< C_INT > mRootsFound
bool executeAction(CProcessQueue::iterator itAction)
CMathEvent * getEvent() const
bool process(const C_FLOAT64 &time, const bool &priorToOutput, resolveSimultaneousAssignments pResolveSimultaneousAssignments)
CVector< C_FLOAT64 > mRootValues2
CVector< C_FLOAT64 > * mpRootValuesBefore
void destroyEventId(const size_t &eventId)
const bool & getContinueSimultaneousEvents() const
bool mContinueSimultaneousEvents
iterator(* resolveSimultaneousAssignments)(const std::multimap< CKey, CAction > &, const C_FLOAT64 &, const bool &, const size_t &)
#define C_FLOAT64
Definition: copasi.h:92
void * mpCallbackTask
size_t mExecutionCounter
bool addCalculation(const C_FLOAT64 &executionTime, const bool &equality, CMathEvent *pEvent)
CProcessQueue * mpProcessQueue
() void(yyvaluep))
Header file of class CEvent.
CVector< C_FLOAT64 > mValues
bool mSimultaneousAssignmentsFound
const C_FLOAT64 & getExecutionTime() const
Definition: CProcessQueue.h:70
resolveSimultaneousAssignments mpResolveSimultaneousAssignments
std::multimap< CKey, CAction > mActions
std::multimap< CKey, CAction >::iterator iterator
friend std::ostream & operator<<(std::ostream &os, const CAction &o)