phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
strains.cc
Go to the documentation of this file.
1// Strains: Three strains compete for a single susceptible pool. (C++)
2#include "master.h"
3#include "popul_proc.h"
4#include "generics.h"
5#include "internal.h"
6
7static const int strain1 = 1;
8static const int strain2 = 2;
9static const int strain3 = 3;
10
12typedef struct {
13 int S;
14 int I1;
15 int I2;
16 int I3;
17 int R;
19
21typedef struct {
22 double Beta1;
23 double Beta2;
24 double Beta3;
25 double gamma;
26 double chi;
27 double pop;
28 double S_0;
29 double I1_0;
30 double I2_0;
31 double I3_0;
32 double R_0;
34
37
38template<>
39std::string strains_proc_t::yaml (std::string tab) const {
40 std::string t = tab + " ";
41 std::string p = tab + "parameter:\n"
47 + YAML_PARAM(pop)
52 + YAML_PARAM(R_0);
53 std::string s = tab + "state:\n"
54 + YAML_STATE(S)
55 + YAML_STATE(I1)
56 + YAML_STATE(I2)
57 + YAML_STATE(I3)
58 + YAML_STATE(R);
59 return p+s;
60}
61
62template<>
63void strains_proc_t::update_params (double *p, int n) {
64 int m = 0;
70 if (m != n) err("wrong number of parameters!");
71}
72
73template<>
74void strains_proc_t::update_IVPs (double *p, int n) {
75 int m = 0;
76 PARAM_SET(pop);
82 if (m != n) err("wrong number of initial-value parameters!");
83}
84
85template<>
86double strains_proc_t::event_rates (double *rate, int n) const {
87 int m = 0;
88 double total = 0;
89 RATE_CALC(params.Beta1 * state.S * state.I1 / params.pop);
90 RATE_CALC(params.Beta2 * state.S * state.I2 / params.pop);
91 RATE_CALC(params.Beta3 * state.S * state.I3 / params.pop);
92 RATE_CALC(params.gamma * state.I1);
93 RATE_CALC(params.gamma * state.I2);
94 RATE_CALC(params.gamma * state.I3);
95 RATE_CALC(params.chi * state.I1);
96 RATE_CALC(params.chi * state.I2);
97 RATE_CALC(params.chi * state.I3);
98 if (m != n) err("wrong number of events!");
99 return total;
100}
101
102template<>
104 double f = params.pop/(params.S_0+params.I1_0+params.I2_0+params.I3_0+params.R_0);
105 state.S = nearbyint(f*params.S_0);
106 state.I1 = nearbyint(f*params.I1_0);
107 state.I2 = nearbyint(f*params.I2_0);
108 state.I3 = nearbyint(f*params.I3_0);
109 state.R = nearbyint(f*params.R_0);
110 graft(strain1,state.I1);
111 graft(strain2,state.I2);
112 graft(strain3,state.I3);
113}
114
115template<>
117 switch (event) {
118 case 0:
119 state.S -= 1; state.I1 += 1; birth(strain1,strain1);
120 break;
121 case 1:
122 state.S -= 1; state.I2 += 1; birth(strain2,strain2);
123 break;
124 case 2:
125 state.S -= 1; state.I3 += 1; birth(strain3,strain3);
126 break;
127 case 3:
128 state.I1 -= 1; state.R += 1; death(strain1);
129 break;
130 case 4:
131 state.I2 -= 1; state.R += 1; death(strain2);
132 break;
133 case 5:
134 state.I3 -= 1; state.R += 1; death(strain3);
135 break;
136 case 6:
137 state.I1 -= 1; state.R += 1; sample_death(strain1);
138 break;
139 case 7:
140 state.I2 -= 1; state.R += 1; sample_death(strain2);
141 break;
142 case 8:
143 state.I3 -= 1; state.R += 1; sample_death(strain3);
144 break;
145 default: // #nocov
146 assert(0); // #nocov
147 break; // #nocov
148 }
149}
150
Encodes the master process.
Definition master.h:21
void graft(name_t i=1, int m=1)
new root in deme i
Definition master.h:153
void birth(name_t i=1, name_t j=1, int n=1)
n births into deme j with parent in deme i
Definition master.h:136
void sample_death(name_t i=1, int n=1)
sample_death in deme i
Definition master.h:169
void death(name_t i=1)
death in deme i
Definition master.h:147
Population process class.
Definition popul_proc.h:16
double event_rates(double *rate, int n) const
Definition strains.cc:86
#define GENERICS(X, TYPE)
Definition generics.h:133
#define err(...)
Definition internal.h:18
#define chi
Definition lbdp_pomp.c:7
#define n
Definition lbdp_pomp.c:9
#define YAML_PARAM(X)
Definition popul_proc.h:136
#define RATE_CALC(X)
Definition popul_proc.h:135
#define YAML_STATE(X)
Definition popul_proc.h:137
#define PARAM_SET(X)
Definition popul_proc.h:134
#define gamma
Definition seirs_pomp.c:29
#define R
Definition seirs_pomp.c:41
#define S
Definition seirs_pomp.c:38
static const int strain2
Definition siir.cc:8
static const int strain1
Definition siir.cc:7
popul_proc_t< strains_state_t, strains_parameters_t, 9 > strains_proc_t
Definition strains.cc:35
master_t< strains_proc_t, 3 > strains_genealogy_t
Definition strains.cc:36
static const int strain3
Definition strains.cc:9
#define I2_0
#define Beta3
#define S_0
#define I3_0
#define I2
#define Beta2
#define Beta1
#define I1_0
#define I3
#define I1
#define R_0
Strains process parameters.
Definition strains.cc:21
Strains process state.
Definition strains.cc:12