From 54e4987f96683616b75c9955a73fa332e7949d12 Mon Sep 17 00:00:00 2001 From: Matthew Andres Moreno Date: Tue, 28 Nov 2023 12:02:15 -0500 Subject: [PATCH] Add option to require full demes for replication --- .../source/actions/PopulationActions.cc | 30 +++++++++++++++++-- .../config/events.cfg | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/avida-core/source/actions/PopulationActions.cc b/avida-core/source/actions/PopulationActions.cc index ffbb939fe9..628065b6f5 100644 --- a/avida-core/source/actions/PopulationActions.cc +++ b/avida-core/source/actions/PopulationActions.cc @@ -5480,18 +5480,27 @@ class cActionReplicateDemesHighestFecundity : public cAction { private: double m_replprob; + bool m_requirefull; int m_replmax; public: - cActionReplicateDemesHighestFecundity(cWorld *world, const cString &args, Feedback &) : cAction(world, args), m_replprob(0.01), m_replmax(std::numeric_limits::max()) + cActionReplicateDemesHighestFecundity( + cWorld *world, + const cString &args, + Feedback & + ) : cAction(world, args) + , m_replprob(0.01) + , m_requirefull(false) + , m_replmax(std::numeric_limits::max()) { cString largs(args); if (largs.GetSize()) m_replprob = largs.PopWord().AsDouble(); + if (largs.GetSize()) m_requirefull = largs.PopWord().AsInt(); if (largs.GetSize()) m_replmax = largs.PopWord().AsInt(); assert(m_replprob >= 0); } - static const cString GetDescription() { return "Arguments: [double replprob=0.01] [int replmax = intmax]"; } + static const cString GetDescription() { return "Arguments: [double replprob=0.01] [bool requirefull = false] [int replmax = intmax]"; } void Process(cAvidaContext &ctx) { @@ -5519,8 +5528,23 @@ class cActionReplicateDemesHighestFecundity : public cAction std::vector deme_indices(num_demes); std::iota(std::begin(deme_indices), std::end(deme_indices), begin); + struct IsEligible { + cPopulation &pop; + const bool requirefull; + IsEligible(cPopulation &pop, const bool requirefull) + : pop(pop), requirefull(requirefull) {} + bool operator()(const int d) { + auto& deme = pop.GetDeme(d); + return (deme.GetOrgCount() == deme.GetSize()) or not requirefull; + } + }; + const int num_eligible = std::count_if( + std::begin(deme_indices), std::end(deme_indices), + IsEligible(pop, m_requirefull) + ); + const int binomial_draw = ctx.GetRandom().GetRandBinomial( - num_demes, + num_eligible, m_replprob ); const int repl_quota = std::min(binomial_draw, m_replmax); diff --git a/avida-core/tests/demes_ReplicateDemesHighestFecundity/config/events.cfg b/avida-core/tests/demes_ReplicateDemesHighestFecundity/config/events.cfg index 4a44f542b5..07983cfcaa 100644 --- a/avida-core/tests/demes_ReplicateDemesHighestFecundity/config/events.cfg +++ b/avida-core/tests/demes_ReplicateDemesHighestFecundity/config/events.cfg @@ -3,7 +3,7 @@ u begin LoadGermlines detailgermlines-500.sgerm u begin LoadBirthCounts detailgermlines-500.sgerm u begin SavePopulation u begin SaveGermlines filename=evolved.sgerm:birthcounts=1 -u 2 ReplicateDemesHighestFecundity 1.0 1 +u 2 ReplicateDemesHighestFecundity 1.0 0 1 u 2 SaveGermlines filename=evolved.sgerm:birthcounts=1 u 2 SavePopulation u 3 Exit