From bbf134e7be3b30a396d73d0269788e109ceefd37 Mon Sep 17 00:00:00 2001 From: Matthew Andres Moreno Date: Fri, 24 Nov 2023 13:01:25 -0500 Subject: [PATCH] Make kill demes action respect partitions --- .../source/actions/PopulationActions.cc | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/avida-core/source/actions/PopulationActions.cc b/avida-core/source/actions/PopulationActions.cc index 2cc47eeba..65192307d 100644 --- a/avida-core/source/actions/PopulationActions.cc +++ b/avida-core/source/actions/PopulationActions.cc @@ -5282,12 +5282,30 @@ class cActionKillDemesHighestParasiteLoad : public cAction static const cString GetDescription() { return "Arguments: [double killprob=0.01] [int killmax = intmax]"; } - void Process(cAvidaContext& ctx) + void Process(cAvidaContext& ctx) { + const int part_size = m_world->GetConfig().DEMES_PARTITION_INTERVAL.Get(); + const int num_demes = m_world->GetPopulation().GetNumDemes(); + if (part_size) { + for (int i = 0; i < num_demes; i+= part_size) { + const int begin = i; + const int end = std::min(i + part_size, num_demes); + ProcessPartition(begin, end, ctx); + } + } else { + ProcessPartition(0, num_demes, ctx); + } + } + + void ProcessPartition(const int begin, const int end, cAvidaContext& ctx) { cPopulation& pop = m_world->GetPopulation(); - const int num_demes = pop.GetNumDemes(); + const int num_demes = end - begin; std::vector deme_indices(num_demes); - std::iota(std::begin(deme_indices), std::end(deme_indices), 0); + std::iota( + std::begin(deme_indices), + std::end(deme_indices), + begin + ); struct HasAny { cPopulation& pop; @@ -5321,16 +5339,18 @@ class cActionKillDemesHighestParasiteLoad : public cAction struct Comp { std::vector& loads; - Comp(std::vector &loads) : loads(loads) {} + const int begin; + Comp(std::vector &loads, const int begin) + : loads(loads), begin(begin) {} bool operator()(const int d1, const int d2) { - return loads[d1] > loads[d2]; + return loads[d1 - begin] > loads[d2 - begin]; } }; std::partial_sort( std::begin(deme_indices), std::next(std::begin(deme_indices), kill_quota), std::end(deme_indices), - Comp(parasite_loads) + Comp(parasite_loads, begin) ); struct DoKill {