Skip to content

Commit

Permalink
add movements, works only for 1 host
Browse files Browse the repository at this point in the history
  • Loading branch information
petrasovaa committed Nov 21, 2023
1 parent 88e1373 commit ccb7f3f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 14 deletions.
18 changes: 16 additions & 2 deletions include/pops/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ class Model
const Network<RasterIndex>& network,
std::vector<std::vector<int>>& suitable_cells)
{
UNUSED(movements);

StandardSingleHostPool host_pool(
model_type_from_string(config_.model_type),
susceptible,
Expand Down Expand Up @@ -274,6 +272,7 @@ class Model
spread_rate,
quarantine,
quarantine_areas,
movements,
network);
}

Expand All @@ -289,6 +288,7 @@ class Model
SpreadRateAction<StandardMultiHostPool, RasterIndex>& spread_rate,
QuarantineEscapeAction<IntegerRaster>& quarantine,
const IntegerRaster& quarantine_areas,
const std::vector<std::vector<int>> movements,
const Network<RasterIndex>& network)
{
// Soil step is the same as simulation step.
Expand Down Expand Up @@ -356,6 +356,20 @@ class Model
config_.cols};
move_pest.action(host_pool, pest_pool, generator_provider_);
}
if (config_.use_movements) {
HostMovement<
StandardMultiHostPool,
IntegerRaster,
FloatRaster,
RasterIndex>
host_movement{
static_cast<unsigned>(
step), // Step is int, but indexing happens with unsigned.
last_index,
movements,
config_.movement_schedule};
last_index = host_movement.action(host_pool, generator_provider_);
}
}
// treatments
if (config_.use_treatments) {
Expand Down
27 changes: 27 additions & 0 deletions include/pops/multi_host_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,33 @@ class MultiHostPool
throw std::invalid_argument(
"Unknown value for pest_or_pathogen: " + pest_or_pathogen);
}
/**
* @brief Move hosts from a cell to a cell (multi-host)
*
* Currenty just works for first host.
*
* @param row_from Row index of the source cell
* @param col_from Column index of the source cell
* @param row_to Row index of the target cell
* @param col_to Column index of the target cell
* @param count Number of pests to move
* @param generator Random number generator for distribution of host among pools
*
* @return Number of pests actually moved between cells
*
* @note Mortality is not supported.
*/
int move_hosts_from_to(
RasterIndex row_from,
RasterIndex col_from,
RasterIndex row_to,
RasterIndex col_to,
int count,
Generator& generator)
{
return host_pools_[0]->move_hosts_from_to(
row_from, col_from, row_to, col_to, count, generator);
}

std::vector<HostPool*>& host_pools()
{
Expand Down
2 changes: 2 additions & 0 deletions tests/test_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ int test_model_sei_deterministic_with_treatments()
std::vector<Raster<int>> exposed(
exposed_size, Raster<int>(infected.rows(), infected.cols(), 0));
std::vector<Raster<double>> empty_floats;
std::vector<std::vector<int>> movements;

TestModel::StandardSingleHostPool host_pool(
model_type_from_string(config.model_type),
Expand Down Expand Up @@ -721,6 +722,7 @@ int test_model_sei_deterministic_with_treatments()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
}
if (!outside_dispersers.empty()) {
Expand Down
36 changes: 24 additions & 12 deletions tests/test_multi_host_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ int test_minimal_parameters_one_host()
std::vector<Raster<int>> mortality_tracker(
num_mortality_steps, Raster<int>(infected.rows(), infected.cols(), 0));

// std::vector<std::vector<int>> movements = {};
// Treatments<Raster<int>, Raster<double>> treatments(config.scheduler());
std::vector<std::vector<int>> movements = {};

config.ew_res = 30;
config.ns_res = 30;
config.rows = infected.rows();
Expand Down Expand Up @@ -131,6 +131,7 @@ int test_minimal_parameters_one_host()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
Raster<int> expected_dispersers = {{8, 0, 0}, {0, 8, 0}, {0, 0, 7}};
if (dispersers != expected_dispersers) {
Expand Down Expand Up @@ -160,6 +161,7 @@ int test_minimal_parameters_one_host()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
Raster<int> expected_infected = infected;
if (infected != expected_infected) {
Expand Down Expand Up @@ -246,8 +248,8 @@ int test_minimal_parameters_two_hosts()
std::vector<Raster<int>> mortality_tracker_2(
num_mortality_steps, Raster<int>(infected_2.rows(), infected_2.cols(), 0));

// std::vector<std::vector<int>> movements = {};
// Treatments<Raster<int>, Raster<double>> treatments(config.scheduler());
std::vector<std::vector<int>> movements = {};

config.ew_res = 30;
config.ns_res = 30;
config.rows = infected_1.rows();
Expand Down Expand Up @@ -319,6 +321,7 @@ int test_minimal_parameters_two_hosts()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
Raster<int> expected_dispersers = {{16, 0, 0}, {0, 10, 0}, {0, 22, 5}};
if (dispersers != expected_dispersers) {
Expand Down Expand Up @@ -348,6 +351,7 @@ int test_minimal_parameters_two_hosts()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
Raster<int> expected_infected = infected_1;
if (infected_1 != expected_infected) {
Expand Down Expand Up @@ -434,8 +438,8 @@ int test_two_hosts_with_table_one_only()
std::vector<Raster<int>> mortality_tracker_2(
num_mortality_steps, Raster<int>(infected_2.rows(), infected_2.cols(), 0));

// std::vector<std::vector<int>> movements = {};
// Treatments<Raster<int>, Raster<double>> treatments(config.scheduler());
std::vector<std::vector<int>> movements = {};

config.ew_res = 30;
config.ns_res = 30;
config.rows = infected_1.rows();
Expand Down Expand Up @@ -518,6 +522,7 @@ int test_two_hosts_with_table_one_only()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
Raster<int> expected_dispersers = {{16, 0, 0}, {0, 10, 0}, {0, 22, 5}};
if (dispersers != expected_dispersers) {
Expand Down Expand Up @@ -547,6 +552,7 @@ int test_two_hosts_with_table_one_only()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
Raster<int> expected_infected = infected_1;
if (infected_1 != expected_infected) {
Expand Down Expand Up @@ -633,8 +639,8 @@ int test_two_hosts_with_table_other_than_one()
std::vector<Raster<int>> mortality_tracker_2(
num_mortality_steps, Raster<int>(infected_2.rows(), infected_2.cols(), 0));

// std::vector<std::vector<int>> movements = {};
// Treatments<Raster<int>, Raster<double>> treatments(config.scheduler());
std::vector<std::vector<int>> movements = {};

config.ew_res = 30;
config.ns_res = 30;
config.rows = infected_1.rows();
Expand Down Expand Up @@ -719,6 +725,7 @@ int test_two_hosts_with_table_other_than_one()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
Raster<int> expected_dispersers = {{14, 0, 0}, {0, 3, 0}, {0, 11, 3}};
if (dispersers != expected_dispersers) {
Expand Down Expand Up @@ -748,6 +755,7 @@ int test_two_hosts_with_table_other_than_one()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
Raster<int> expected_infected = infected_1;
if (infected_1 != expected_infected) {
Expand Down Expand Up @@ -834,8 +842,8 @@ int test_two_hosts_susceptibilities_one()
std::vector<Raster<int>> mortality_tracker_2(
num_mortality_steps, Raster<int>(infected_2.rows(), infected_2.cols(), 0));

// std::vector<std::vector<int>> movements = {};
// Treatments<Raster<int>, Raster<double>> treatments(config.scheduler());
std::vector<std::vector<int>> movements = {};

config.ew_res = 30;
config.ns_res = 30;
config.rows = infected_1.rows();
Expand Down Expand Up @@ -918,6 +926,7 @@ int test_two_hosts_susceptibilities_one()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
Raster<int> expected_dispersers = {{16, 0, 0}, {0, 10, 0}, {0, 22, 5}};
if (dispersers != expected_dispersers) {
Expand Down Expand Up @@ -947,6 +956,7 @@ int test_two_hosts_susceptibilities_one()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
Raster<int> expected_infected = infected_1;
if (infected_1 != expected_infected) {
Expand Down Expand Up @@ -1033,8 +1043,8 @@ int test_two_hosts_susceptibilities_other_than_one()
std::vector<Raster<int>> mortality_tracker_2(
num_mortality_steps, Raster<int>(infected_2.rows(), infected_2.cols(), 0));

// std::vector<std::vector<int>> movements = {};
// Treatments<Raster<int>, Raster<double>> treatments(config.scheduler());
std::vector<std::vector<int>> movements = {};

config.ew_res = 30;
config.ns_res = 30;
config.rows = infected_1.rows();
Expand Down Expand Up @@ -1117,6 +1127,7 @@ int test_two_hosts_susceptibilities_other_than_one()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
// First step has the same results as with susceptibility == 1 because
// number of generated dispersers is influenced by the infected in second step.
Expand Down Expand Up @@ -1148,6 +1159,7 @@ int test_two_hosts_susceptibilities_other_than_one()
spread_rate,
quarantine,
zeros,
movements,
Network<int>::null_network());
Raster<int> expected_infected = infected_1;
if (infected_1 != expected_infected) {
Expand Down

0 comments on commit ccb7f3f

Please sign in to comment.