Skip to content

Commit

Permalink
updated to pops-core 1.1 (#122)
Browse files Browse the repository at this point in the history
* updated to pops-core 1.1

* Update CHANGELOG.md
  • Loading branch information
ChrisJones687 authored Jun 22, 2021
1 parent 7721272 commit b316d40
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ this repository.

- Validation now exports the statistics for each output and the cumulative statistics for each year (@ChrisJones687, #121).

- Treatments now update total_hosts (@ChrisJones687, #122)

### Fixed

- Mask parameter works as intended in validate function after terra update (@ChrisJones687, #104).
Expand Down
2 changes: 1 addition & 1 deletion inst/cpp/pops-core
8 changes: 7 additions & 1 deletion inst/include/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,13 @@ class Model
// treatments
if (config_.use_treatments) {
bool managed = treatments.manage(
step, infected, exposed, susceptible, resistant, suitable_cells);
step,
infected,
exposed,
susceptible,
resistant,
total_hosts,
suitable_cells);
if (managed && config_.use_mortality) {
// treatments apply to all mortality tracker cohorts
for (auto& raster : mortality_tracker) {
Expand Down
40 changes: 33 additions & 7 deletions inst/include/treatments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "raster.hpp"
#include "date.hpp"
#include "scheduling.hpp"
#include "utils.hpp"

#include <map>
#include <vector>
Expand Down Expand Up @@ -87,6 +88,7 @@ class AbstractTreatment
std::vector<IntegerRaster>& exposed,
IntegerRaster& susceptible,
IntegerRaster& resistant,
IntegerRaster& total_hosts,
const std::vector<std::vector<int>>& spatial_indeices) = 0;
virtual void end_treatment(
IntegerRaster& susceptible,
Expand Down Expand Up @@ -175,29 +177,45 @@ class SimpleTreatment : public BaseTreatment<IntegerRaster, FloatRaster>
IntegerRaster& infected,
std::vector<IntegerRaster>& exposed,
IntegerRaster& susceptible,
IntegerRaster&,
IntegerRaster& resistant,
IntegerRaster& total_hosts,
const std::vector<std::vector<int>>& suitable_cells) override
{
for (auto indices : suitable_cells) {
int i = indices[0];
int j = indices[1];
int new_exposed_total = 0;
int new_infected = 0;
int new_susceptible = 0;
int new_exposed_individual = 0;
if (this->application_ == TreatmentApplication::Ratio) {
infected(i, j) = infected(i, j) - (infected(i, j) * this->map_(i, j));
new_infected = infected(i, j) - (infected(i, j) * this->map_(i, j));
infected(i, j) = new_infected;
}
else if (this->application_ == TreatmentApplication::AllInfectedInCell) {
infected(i, j) = this->map_(i, j) ? 0 : infected(i, j);
new_infected = this->map_(i, j) ? 0 : infected(i, j);
infected(i, j) = new_infected;
}
for (auto& raster : exposed) {
if (this->application_ == TreatmentApplication::Ratio) {
raster(i, j) = raster(i, j) - (raster(i, j) * this->map_(i, j));
new_exposed_individual =
raster(i, j) - (raster(i, j) * this->map_(i, j));
raster(i, j) = new_exposed_individual;
new_exposed_total += new_exposed_individual;
}
else if (
this->application_ == TreatmentApplication::AllInfectedInCell) {
raster(i, j) = this->map_(i, j) ? 0 : raster(i, j);
new_exposed_individual =
raster(i, j) - (raster(i, j) * this->map_(i, j));
raster(i, j) = new_exposed_individual;
new_exposed_total += new_exposed_individual;
}
}
susceptible(i, j) =
new_susceptible =
susceptible(i, j) - (susceptible(i, j) * this->map_(i, j));
susceptible(i, j) = new_susceptible;
total_hosts(i, j) =
new_infected + new_susceptible + new_exposed_total + resistant(i, j);
}
}
void end_treatment(
Expand Down Expand Up @@ -244,8 +262,10 @@ class PesticideTreatment : public BaseTreatment<IntegerRaster, FloatRaster>
std::vector<IntegerRaster>& exposed_vector,
IntegerRaster& susceptible,
IntegerRaster& resistant,
IntegerRaster& total_hosts,
const std::vector<std::vector<int>>& suitable_cells) override
{
UNUSED(total_hosts);
for (auto indices : suitable_cells) {
int i = indices[0];
int j = indices[1];
Expand Down Expand Up @@ -370,13 +390,19 @@ class Treatments
std::vector<IntegerRaster>& exposed,
IntegerRaster& susceptible,
IntegerRaster& resistant,
IntegerRaster& total_hosts,
const std::vector<std::vector<int>>& suitable_cells)
{
bool changed = false;
for (unsigned i = 0; i < treatments.size(); i++) {
if (treatments[i]->should_start(current)) {
treatments[i]->apply_treatment(
infected, exposed, susceptible, resistant, suitable_cells);
infected,
exposed,
susceptible,
resistant,
total_hosts,
suitable_cells);
changed = true;
}
else if (treatments[i]->should_end(current)) {
Expand Down

0 comments on commit b316d40

Please sign in to comment.