Skip to content

Commit

Permalink
Use rounding for overpopulation movements (#221)
Browse files Browse the repository at this point in the history
This replaces flooring in overpopulation movements by rounding.

It updates the test as well to match (although the original test still passes as is).
  • Loading branch information
wenzeslaus authored Dec 19, 2024
1 parent 7133fdd commit 24bc87b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions include/pops/actions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,8 @@ class MoveOverpopulatedPests
dispersal_kernel_(generator.overpopulation(), i, j);
// for leaving_percentage == 0.5
// 2 infected -> 1 leaving
// 3 infected -> 1 leaving
int leaving =
static_cast<int>(std::floor(original_count * leaving_percentage_));
// 3 infected -> 2 leaving (assuming always rounding up for .5)
int leaving = std::lround(original_count * leaving_percentage_);
leaving = hosts.pests_from(i, j, leaving, generator.overpopulation());
if (row < 0 || row >= rows_ || col < 0 || col >= cols_) {
pests.add_outside_dispersers_at(row, col, leaving);
Expand Down
3 changes: 1 addition & 2 deletions tests/test_overpopulation_movements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ int test_model()
config.use_spreadrates = false;
config.create_schedules();
// More reference data
int leaving =
static_cast<int>(std::ceil(infected(0, 0) * config.leaving_percentage));
int leaving = std::lround(infected(0, 0) * config.leaving_percentage);
// Objects
std::vector<std::vector<int>> suitable_cells =
find_suitable_cells<int>(total_hosts);
Expand Down

0 comments on commit 24bc87b

Please sign in to comment.