From c1e615b504944793a15bea3081bfb3b8ae4bbebf Mon Sep 17 00:00:00 2001 From: Matthew Andres Moreno Date: Fri, 24 Nov 2023 13:05:05 -0500 Subject: [PATCH 1/2] Make birth count repl respect partitions --- .../source/actions/PopulationActions.cc | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/avida-core/source/actions/PopulationActions.cc b/avida-core/source/actions/PopulationActions.cc index 0b1baa157..31a861b6d 100644 --- a/avida-core/source/actions/PopulationActions.cc +++ b/avida-core/source/actions/PopulationActions.cc @@ -5362,12 +5362,31 @@ class cActionReplicateDemesHighestBirthCount : public cAction static const cString GetDescription() { return "Arguments: [double replprob=0.01] [int replmax = 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); const int binomial_draw = ctx.GetRandom().GetRandBinomial( num_demes, @@ -5394,17 +5413,19 @@ class cActionReplicateDemesHighestBirthCount : public cAction struct Comp { std::vector &births; - Comp(std::vector &births) : births(births) {} + const int begin; + Comp(std::vector &births, const int begin) + : births(births), begin(begin) {} bool operator()(const int d1, const int d2) { - return births[d1] > births[d2]; + return births[d1 - begin] > births[d2 - begin]; } }; std::partial_sort( std::begin(deme_indices), std::next(std::begin(deme_indices), repl_quota), std::end(deme_indices), - Comp(birth_counts) + Comp(birth_counts, begin) ); struct DoRepl { From af9926a313ae9f1110e591b08a06a3ac4899101b Mon Sep 17 00:00:00 2001 From: Matthew Andres Moreno Date: Fri, 24 Nov 2023 13:01:25 -0500 Subject: [PATCH 2/2] 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 31a861b6d..e1aac2d29 100644 --- a/avida-core/source/actions/PopulationActions.cc +++ b/avida-core/source/actions/PopulationActions.cc @@ -5275,12 +5275,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; @@ -5314,16 +5332,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 {