roadrunner  2.6.0
Fast simulator for SBML models
EventQueue.h
1 /*
2  * EventQueue.h
3  *
4  * Created on: Aug 16, 2013
5  * Author: andy
6  */
7 
8 #ifndef EVENTQUEUE_H_
9 #define EVENTQUEUE_H_
10 
11 #include "rrOSSpecifics.h"
12 #include <deque>
13 #include <queue>
14 #include <list>
15 #include <ostream>
16 
17 
18 namespace rrllvm {
19 
20  class LLVMExecutableModel;
21 
25  class Event
26  {
27  public:
28  Event(LLVMExecutableModel&, uint id);
29  Event(const Event& other);
30  Event& operator=(const Event& rhs);
31  ~Event();
32 
33 
34  void assign() const;
35 
36  bool isExpired() const;
37 
41  bool isCurrent() const;
42 
43  double getPriority() const;
44 
45  bool isPersistent() const;
46 
47  bool useValuesFromTriggerTime() const;
48 
49  bool isTriggered() const;
50 
54  bool isRipe() const;
55 
56 
57  LLVMExecutableModel& model;
58  uint id;
59  double delay;
60  double assignTime;
61  uint dataSize;
62 
72  double* data;
73 
74 
75  friend bool operator<(const Event& a, const Event& b);
76 
77  };
78 
79  std::ostream& operator <<(std::ostream& os, const Event& data);
80 
85  class EventQueue
86  {
87  public:
88  typedef std::list<rrllvm::Event> _Sequence;
89  typedef std::less<_Sequence::value_type> _Compare;
90  typedef _Sequence::const_iterator const_iterator;
91  typedef _Sequence::iterator iterator;
92  typedef _Sequence::const_reference const_reference;
93 
97  bool eraseExpiredEvents();
98 
102  bool hasCurrentEvents();
103 
110  bool applyEvents();
111 
115  uint size() const;
116 
120  const_reference top();
121 
127  void push(const Event& e);
128 
132  double getNextPendingEventTime();
133 
134  /*
135  * Save this EventQueue in binary format to out
136  */
137  void saveState(std::ostream& out);
138 
139  /*
140  * Load the events stored in in and add them to this queue and the executable model model
141  */
142  void loadState(std::istream& in, LLVMExecutableModel& model);
143 
144  friend std::ostream& operator<< (std::ostream& stream, const EventQueue& queue);
145 
146  private:
147 
153  _Sequence sequence;
154  _Compare comp;
155  };
156 
157  std::ostream& operator<< (std::ostream& stream, const EventQueue& queue);
158 
159 
160 
161 
162 } /* namespace rrllvm */
163 
164 
165 
166 #endif /* EVENTQUEUE_H_ */
Definition: rrEvent.h:12
The EventQueue class is when events are queued to execute, but have not yet executed.
Definition: EventQueue.h:86
bool hasCurrentEvents()
are any events current (delay == 0 and triggered or persistant)
Definition: EventQueue.cpp:206
void push(const Event &e)
insert a new event into the queue.
Definition: EventQueue.cpp:276
uint size() const
number of events in the queue
Definition: EventQueue.cpp:271
const_reference top()
event with lowest time to assignment and highest priority.
Definition: EventQueue.cpp:281
bool applyEvents()
assign all of the top most events with the same priority and remove them from the queue.
Definition: EventQueue.cpp:213
double getNextPendingEventTime()
the time the next event is sceduled to be assigned.
Definition: EventQueue.cpp:287
bool eraseExpiredEvents()
remove expired events from the queue.
Definition: EventQueue.cpp:186
bool isRipe() const
is this event ready to be applied
Definition: EventQueue.cpp:148
double * data
data block where assignment rules evaluations are stored if useValuesFromTriggerTime is set.
Definition: EventQueue.h:72
bool isCurrent() const
delay is zero and either persistent or triggered.
Definition: EventQueue.cpp:98
LLVM executable model.
Definition: LLVMExecutableModel.h:59