Simpact Cyan
Population based event driven simulation using mNRM
hazardfunction.h
Go to the documentation of this file.
1 #ifndef HAZARDFUNCTION_H
2 
3 #define HAZARDFUNCTION_H
4 
19 {
20 public:
21  HazardFunction() { }
22  virtual ~HazardFunction() { }
23 
25  virtual double evaluate(double t) = 0;
26 
31  virtual double calculateInternalTimeInterval(double t0, double dt) = 0;
32 
38  virtual double solveForRealTimeInterval(double t0, double Tdiff) = 0;
39 
40  // NOTE: this is just for debugging/testing, not meant to be used to evaluate hazards!
41  double integrateNumerically(double t0, double dt);
42 private:
43  static double staticEvaluationFunction(double t, void *pParams);
44 };
45 
76 {
77 public:
81  TimeLimitedHazardFunction(HazardFunction &h, double tMax) : m_h(h), m_tMax(tMax) { }
83 
84  double evaluate(double t);
85  double calculateInternalTimeInterval(double t0, double dt);
86  double solveForRealTimeInterval(double t0, double Tdiff);
87 private:
88  HazardFunction &m_h;
89  double m_tMax;
90 };
91 
92 inline double TimeLimitedHazardFunction::evaluate(double t)
93 {
94  if (t < m_tMax)
95  return m_h.evaluate(t);
96  return m_h.evaluate(m_tMax);
97 }
98 
99 // something small to prevent division by zero
100 #define TIMELIMITEDHAZARDFUNCTION_SMALLNUMBER 1e-100
101 
103 {
104  if (t0 >= m_tMax) // we're in the regime where the hazard has become constant
105  return (m_h.evaluate(m_tMax) + TIMELIMITEDHAZARDFUNCTION_SMALLNUMBER)*dt;
106 
107  if (t0 + dt <= m_tMax)
108  return m_h.calculateInternalTimeInterval(t0, dt);
109 
110  double tMaxMinT0 = m_tMax - t0;
111  double TdiffMax = m_h.calculateInternalTimeInterval(t0, tMaxMinT0);
112 
113  return TdiffMax + m_h.evaluate(m_tMax)*(dt-tMaxMinT0);
114 }
115 
116 inline double TimeLimitedHazardFunction::solveForRealTimeInterval(double t0, double Tdiff)
117 {
118  if (t0 >= m_tMax) // we're in the regime where the hazard has become constant
119  return Tdiff/(m_h.evaluate(m_tMax) + TIMELIMITEDHAZARDFUNCTION_SMALLNUMBER);
120 
121  double tMaxMinT0 = m_tMax - t0;
122  double TdiffMax = m_h.calculateInternalTimeInterval(t0, tMaxMinT0);
123 
124  if (TdiffMax >= Tdiff) // we haven't reached tMax yet
125  return m_h.solveForRealTimeInterval(t0, Tdiff);
126 
127  return (Tdiff - TdiffMax)/m_h.evaluate(m_tMax) + tMaxMinT0;
128 }
129 
130 #endif // HAZARDFUNCTION_H
131 
Abstract base class which can be used for a hazard.
Definition: hazardfunction.h:18
double solveForRealTimeInterval(double t0, double Tdiff)
For the specified internal time interval Tdiff, calculate the corresponding real-world time interval...
Definition: hazardfunction.h:116
double calculateInternalTimeInterval(double t0, double dt)
Map the real-world time dt to an internal time interval.
Definition: hazardfunction.h:102
virtual double calculateInternalTimeInterval(double t0, double dt)=0
Map the real-world time dt to an internal time interval.
virtual double solveForRealTimeInterval(double t0, double Tdiff)=0
For the specified internal time interval Tdiff, calculate the corresponding real-world time interval...
Starting from a particular hazard, this modified hazard returns a constant value for times larger tha...
Definition: hazardfunction.h:75
double evaluate(double t)
Evaluate the hazard at time t.
Definition: hazardfunction.h:92
virtual double evaluate(double t)=0
Evaluate the hazard at time t.
TimeLimitedHazardFunction(HazardFunction &h, double tMax)
This constructor specifies that the base hazard h should be used for times smaller than tMax...
Definition: hazardfunction.h:81