17 #ifndef POPS_TREATMENTS_HPP
18 #define POPS_TREATMENTS_HPP
50 std::map<std::string, TreatmentApplication> mapping{
56 return mapping.at(text);
58 catch (
const std::out_of_range&) {
59 throw std::invalid_argument(
60 "treatment_application_enum_from_string:"
62 + text +
"' provided");
78 template<
typename IntegerRaster,
typename FloatRaster>
87 IntegerRaster& infected,
88 std::vector<IntegerRaster>& exposed,
89 IntegerRaster& susceptible,
90 IntegerRaster& resistant,
91 IntegerRaster& total_hosts,
92 const std::vector<std::vector<int>>& spatial_indeices) = 0;
94 IntegerRaster& susceptible,
95 IntegerRaster& resistant,
96 const std::vector<std::vector<int>>& spatial_indeices) = 0;
98 IntegerRaster& infected,
99 const std::vector<std::vector<int>>& spatial_indeices) = 0;
107 template<
typename IntegerRaster,
typename FloatRaster>
118 const FloatRaster& map,
135 IntegerRaster& infected,
136 const std::vector<std::vector<int>>& suitable_cells)
override
138 for (
auto indices : suitable_cells) {
142 infected(i, j) = infected(i, j) - (infected(i, j) *
map_(i, j));
145 infected(i, j) =
map_(i, j) ? 0 : infected(i, j);
156 template<
typename IntegerRaster,
typename FloatRaster>
161 const FloatRaster& map,
164 :
BaseTreatment<IntegerRaster, FloatRaster>(map, start, treatment_application)
177 IntegerRaster& infected,
178 std::vector<IntegerRaster>& exposed,
179 IntegerRaster& susceptible,
180 IntegerRaster& resistant,
181 IntegerRaster& total_hosts,
182 const std::vector<std::vector<int>>& suitable_cells)
override
184 for (
auto indices : suitable_cells) {
187 int new_exposed_total = 0;
188 int new_infected = 0;
189 int new_susceptible = 0;
190 int new_exposed_individual = 0;
192 new_infected = infected(i, j) - (infected(i, j) * this->
map_(i, j));
193 infected(i, j) = new_infected;
196 new_infected = this->
map_(i, j) ? 0 : infected(i, j);
197 infected(i, j) = new_infected;
199 for (
auto& raster : exposed) {
201 new_exposed_individual =
202 raster(i, j) - (raster(i, j) * this->
map_(i, j));
203 raster(i, j) = new_exposed_individual;
204 new_exposed_total += new_exposed_individual;
208 new_exposed_individual =
209 raster(i, j) - (raster(i, j) * this->
map_(i, j));
210 raster(i, j) = new_exposed_individual;
211 new_exposed_total += new_exposed_individual;
215 susceptible(i, j) - (susceptible(i, j) * this->
map_(i, j));
216 susceptible(i, j) = new_susceptible;
218 new_infected + new_susceptible + new_exposed_total + resistant(i, j);
222 IntegerRaster&, IntegerRaster&,
const std::vector<std::vector<int>>&)
override
234 template<
typename IntegerRaster,
typename FloatRaster>
239 const FloatRaster& map,
243 :
BaseTreatment<IntegerRaster, FloatRaster>(map, start, treatment_application)
261 IntegerRaster& infected,
262 std::vector<IntegerRaster>& exposed_vector,
263 IntegerRaster& susceptible,
264 IntegerRaster& resistant,
265 IntegerRaster& total_hosts,
266 const std::vector<std::vector<int>>& suitable_cells)
override
269 for (
auto indices : suitable_cells) {
272 int infected_resistant = 0;
273 int exposed_resistant_sum = 0;
274 int susceptible_resistant = susceptible(i, j) * this->
map_(i, j);
275 int current_resistant = resistant(i, j);
277 infected_resistant = infected(i, j) * this->
map_(i, j);
280 infected_resistant = this->
map_(i, j) ? infected(i, j) : 0;
282 infected(i, j) -= infected_resistant;
283 for (
auto& exposed : exposed_vector) {
284 int exposed_resistant = 0;
286 exposed_resistant = exposed(i, j) * this->
map_(i, j);
290 exposed_resistant = this->
map_(i, j) ? exposed(i, j) : 0;
292 exposed(i, j) -= exposed_resistant;
293 exposed_resistant_sum += exposed_resistant;
295 resistant(i, j) = infected_resistant + exposed_resistant_sum
296 + susceptible_resistant + current_resistant;
297 susceptible(i, j) -= susceptible_resistant;
301 IntegerRaster& susceptible,
302 IntegerRaster& resistant,
303 const std::vector<std::vector<int>>& suitable_cells)
override
305 for (
auto indices : suitable_cells) {
308 if (this->
map_(i, j) > 0) {
309 susceptible(i, j) += resistant(i, j);
328 template<
typename IntegerRaster,
typename FloatRaster>
332 std::vector<AbstractTreatment<IntegerRaster, FloatRaster>*> treatments;
339 for (
auto item : treatments) {
358 const FloatRaster& map,
359 const Date& start_date,
366 map, start, treatment_application));
368 Date end_date(start_date);
372 map, start, end, treatment_application));
389 IntegerRaster& infected,
390 std::vector<IntegerRaster>& exposed,
391 IntegerRaster& susceptible,
392 IntegerRaster& resistant,
393 IntegerRaster& total_hosts,
394 const std::vector<std::vector<int>>& suitable_cells)
396 bool changed =
false;
397 for (
unsigned i = 0; i < treatments.size(); i++) {
398 if (treatments[i]->should_start(current)) {
399 treatments[i]->apply_treatment(
408 else if (treatments[i]->should_end(current)) {
409 treatments[i]->end_treatment(susceptible, resistant, suitable_cells);
423 IntegerRaster& infected,
424 const std::vector<std::vector<int>>& suitable_cells)
426 bool applied =
false;
427 for (
unsigned i = 0; i < treatments.size(); i++)
428 if (treatments[i]->should_start(current)) {
429 treatments[i]->apply_treatment_mortality(infected, suitable_cells);
441 for (
auto& treatment : treatments) {
442 if (treatment->get_start() > step) {
448 std::remove(treatments.begin(), treatments.end(),
nullptr),
454 #endif // POPS_TREATMENTS_HPP