Simpact Cyan
Population based event driven simulation using mNRM
hazardfunctionformationsimple.h
1 #ifndef HAZARDFUNCTIONFORMATIONSIMPLE_H
2 
3 #define HAZARDFUNCTIONFORMATIONSIMPLE_H
4 
5 #include "hazardfunction.h"
6 #include "person.h"
7 #include <cmath>
8 
9 class HazardFunctionFormationSimple : public HazardFunction
10 {
11 public:
12  HazardFunctionFormationSimple(const Person *pPerson1, const Person *pPerson2, double tr,
13  double a0, double a1, double a2, double a3, double a4,
14  double a5, double Dp, double b);
15  ~HazardFunctionFormationSimple();
16 
17  double evaluate(double t);
18  double calculateInternalTimeInterval(double t0, double dt);
19  double solveForRealTimeInterval(double t0, double Tdiff);
20 private:
21  double getLnB() const;
22  double getB() const;
23  double getC() const;
24  double getE(double t0) const;
25 
26  const Person *m_pPerson1;
27  const Person *m_pPerson2;
28  const double m_tr, m_a0, m_a1, m_a2, m_a3, m_a4, m_a5, m_Dp, m_b;
29 };
30 
31 inline double HazardFunctionFormationSimple::getLnB() const
32 {
33  double Pi = m_pPerson1->getNumberOfRelationships();
34  double Pj = m_pPerson2->getNumberOfRelationships();
35  double tBi = m_pPerson1->getDateOfBirth();
36  double tBj = m_pPerson2->getDateOfBirth();
37 
38  double lnB = m_a0 + m_a1*Pi + m_a2*Pj + m_a3*std::abs(Pi-Pj) - m_a4*(tBi + tBj)/2.0
39  +m_a5*std::abs(-tBi+tBj-m_Dp) - m_b*m_tr;
40 
41  return lnB;
42 }
43 
44 inline double HazardFunctionFormationSimple::getB() const
45 {
46  return std::exp(getLnB());
47 }
48 
49 inline double HazardFunctionFormationSimple::getC() const
50 {
51  double C = m_a4 + m_b;
52 
53  return C;
54 }
55 
56 inline double HazardFunctionFormationSimple::getE(double t0) const
57 {
58  double Pi = m_pPerson1->getNumberOfRelationships();
59  double Pj = m_pPerson2->getNumberOfRelationships();
60  double tBi = m_pPerson1->getDateOfBirth();
61  double tBj = m_pPerson2->getDateOfBirth();
62 
63  double E = std::exp(m_a0 + m_a1*Pi + m_a2*Pj + m_a3*std::abs(Pi-Pj) + m_a4*(t0 - (tBi + tBj)/2.0)
64  +m_a5*std::abs(-tBi+tBj-m_Dp) + m_b*(t0-m_tr));
65  return E;
66 }
67 
68 #endif // HAZARDFUNCTIONFORMATIONSIMPLE_H
Abstract base class which can be used for a hazard.
Definition: hazardfunction.h:18
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...
virtual double evaluate(double t)=0
Evaluate the hazard at time t.