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 chi1;
27 double chi2;
28 double chi3;
29 double pop;
30 double S_0;
31 double I1_0;
32 double I2_0;
33 double I3_0;
34 double R_0;
36
39
40template<>
41std::string strains_proc_t::yaml (std::string tab) const {
42 std::string t = tab + " ";
43 std::string p = tab + "parameter:\n"
51 + YAML_PARAM(pop)
56 + YAML_PARAM(R_0);
57 std::string s = tab + "state:\n"
58 + YAML_STATE(S)
59 + YAML_STATE(I1)
60 + YAML_STATE(I2)
61 + YAML_STATE(I3)
62 + YAML_STATE(R);
63 return p+s;
64}
65
66template<>
67void strains_proc_t::update_params (double *p, int n) {
68 int m = 0;
76 if (m != n) err("wrong number of parameters!");
77}
78
79template<>
80void strains_proc_t::update_IVPs (double *p, int n) {
81 int m = 0;
82 PARAM_SET(pop);
88 if (m != n) err("wrong number of initial-value parameters!");
89}
90
91template<>
92double strains_proc_t::event_rates (double *rate, int n) const {
93 int m = 0;
94 double total = 0;
95 RATE_CALC(params.Beta1 * state.S * state.I1 / params.pop);
96 RATE_CALC(params.Beta2 * state.S * state.I2 / params.pop);
97 RATE_CALC(params.Beta3 * state.S * state.I3 / params.pop);
98 RATE_CALC(params.gamma * state.I1);
99 RATE_CALC(params.gamma * state.I2);
100 RATE_CALC(params.gamma * state.I3);
101 RATE_CALC(params.chi1 * state.I1);
102 RATE_CALC(params.chi2 * state.I2);
103 RATE_CALC(params.chi3 * state.I3);
104 if (m != n) err("wrong number of events!");
105 return total;
106}
107
108template<>
110 double f = params.pop/(params.S_0+params.I1_0+params.I2_0+params.I3_0+params.R_0);
111 state.S = nearbyint(f*params.S_0);
112 state.I1 = nearbyint(f*params.I1_0);
113 state.I2 = nearbyint(f*params.I2_0);
114 state.I3 = nearbyint(f*params.I3_0);
115 state.R = nearbyint(f*params.R_0);
116 graft(strain1,state.I1);
117 graft(strain2,state.I2);
118 graft(strain3,state.I3);
119}
120
121template<>
123 switch (event) {
124 case 0:
125 state.S -= 1; state.I1 += 1; birth(strain1,strain1);
126 break;
127 case 1:
128 state.S -= 1; state.I2 += 1; birth(strain2,strain2);
129 break;
130 case 2:
131 state.S -= 1; state.I3 += 1; birth(strain3,strain3);
132 break;
133 case 3:
134 state.I1 -= 1; state.R += 1; death(strain1);
135 break;
136 case 4:
137 state.I2 -= 1; state.R += 1; death(strain2);
138 break;
139 case 5:
140 state.I3 -= 1; state.R += 1; death(strain3);
141 break;
142 case 6:
143 state.I1 -= 1; state.R += 1; sample_death(strain1);
144 break;
145 case 7:
146 state.I2 -= 1; state.R += 1; sample_death(strain2);
147 break;
148 case 8:
149 state.I3 -= 1; state.R += 1; sample_death(strain3);
150 break;
151 default: // #nocov
152 assert(0); // #nocov
153 break; // #nocov
154 }
155}
156
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:92
#define GENERICS(X, TYPE)
Definition generics.h:133
#define err(...)
Definition internal.h:18
#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:40
#define S
Definition seirs_pomp.c:37
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:37
master_t< strains_proc_t, 3 > strains_genealogy_t
Definition strains.cc:38
static const int strain3
Definition strains.cc:9
#define I2_0
#define Beta3
#define S_0
#define chi2
#define chi3
#define I3_0
#define I2
#define Beta2
#define Beta1
#define I1_0
#define chi1
#define I3
#define I1
#define R_0
Strains process parameters.
Definition strains.cc:21
Strains process state.
Definition strains.cc:12