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 = 0;
8static const int strain2 = 1;
9static const int strain3 = 2;
10
12typedef struct {
13 int S;
14 int I1;
15 int I2;
16 int I3;
17 int R;
18 double N;
20
22typedef struct {
23 double Beta1;
24 double Beta2;
25 double Beta3;
26 double gamma;
27 double psi1;
28 double psi2;
29 double psi3;
30 int S0;
31 int I1_0;
32 int I2_0;
33 int I3_0;
34 int R0;
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(S0)
55 + YAML_PARAM(R0);
56 std::string s = tab + "state:\n"
57 + YAML_STATE(S)
58 + YAML_STATE(I1)
59 + YAML_STATE(I2)
60 + YAML_STATE(I3)
61 + YAML_STATE(R)
62 + YAML_STATE(N);
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;
87 if (m != n) err("wrong number of initial-value parameters!");
88}
89
90template<>
91double strains_proc_t::event_rates (double *rate, int n) const {
92 int m = 0;
93 double total = 0;
94 RATE_CALC(params.Beta1 * state.S * state.I1 / state.N);
95 RATE_CALC(params.Beta2 * state.S * state.I2 / state.N);
96 RATE_CALC(params.Beta3 * state.S * state.I3 / state.N);
97 RATE_CALC(params.gamma * state.I1);
98 RATE_CALC(params.gamma * state.I2);
99 RATE_CALC(params.gamma * state.I3);
100 RATE_CALC(params.psi1 * state.I1);
101 RATE_CALC(params.psi2 * state.I2);
102 RATE_CALC(params.psi3 * state.I3);
103 if (m != n) err("wrong number of events!");
104 return total;
105}
106
107template<>
109 state.S = params.S0;
110 state.I1 = params.I1_0;
111 state.I2 = params.I2_0;
112 state.I3 = params.I3_0;
113 state.R = params.R0;
114 state.N = double(params.S0+params.I1_0+params.I3_0+params.I3_0+params.R0);
115 graft(strain1,params.I1_0);
116 graft(strain2,params.I2_0);
117 graft(strain3,params.I3_0);
118}
119
120template<>
122 switch (event) {
123 case 0:
124 state.S -= 1; state.I1 += 1; birth(strain1,strain1);
125 break;
126 case 1:
127 state.S -= 1; state.I2 += 1; birth(strain2,strain2);
128 break;
129 case 2:
130 state.S -= 1; state.I3 += 1; birth(strain3,strain3);
131 break;
132 case 3:
133 state.I1 -= 1; state.R += 1; death(strain1);
134 break;
135 case 4:
136 state.I2 -= 1; state.R += 1; death(strain2);
137 break;
138 case 5:
139 state.I3 -= 1; state.R += 1; death(strain3);
140 break;
141 case 6:
142 state.I1 -= 1; state.R += 1; sample_death(strain1);
143 break;
144 case 7:
145 state.I2 -= 1; state.R += 1; sample_death(strain2);
146 break;
147 case 8:
148 state.I3 -= 1; state.R += 1; sample_death(strain3);
149 break;
150 default: // #nocov
151 assert(0); // #nocov
152 break; // #nocov
153 }
154}
155
Encodes the master process.
Definition master.h:22
void birth(name_t i=0, name_t j=0, int n=1)
n births into deme j with parent in deme i
Definition master.h:142
void death(name_t i=0)
death in deme i
Definition master.h:153
void graft(name_t i=0, int m=1)
new root in deme i
Definition master.h:159
void sample_death(name_t i=0, int n=1)
sample_death in deme i
Definition master.h:175
Population process class.
Definition popul_proc.h:20
double event_rates(double *rate, int n) const
Definition strains.cc:91
std::string yaml(std::string tab) const
Definition strains.cc:41
#define GENERICS(X, TYPE)
Definition generics.h:149
#define err(...)
Definition internal.h:18
#define n
Definition lbdp_pomp.c:8
#define YAML_PARAM(X)
Definition popul_proc.h:190
#define RATE_CALC(X)
Definition popul_proc.h:189
#define YAML_STATE(X)
Definition popul_proc.h:191
#define PARAM_SET(X)
Definition popul_proc.h:187
#define N
Definition seirs_pomp.c:32
#define R0
Definition seirs_pomp.c:31
#define gamma
Definition seirs_pomp.c:25
#define R
Definition seirs_pomp.c:36
#define S0
Definition seirs_pomp.c:28
#define S
Definition seirs_pomp.c:33
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 psi1
#define Beta3
#define psi3
#define I3_0
#define I2
#define Beta2
#define Beta1
#define I1_0
#define psi2
#define I3
#define I1
Strains process parameters.
Definition strains.cc:22
Strains process state.
Definition strains.cc:12