Skip to content

Commit

Permalink
Add option to require full demes for replication
Browse files Browse the repository at this point in the history
  • Loading branch information
mmore500 committed Nov 28, 2023
1 parent 04a5341 commit 54e4987
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions avida-core/source/actions/PopulationActions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>::max())
cActionReplicateDemesHighestFecundity(
cWorld *world,
const cString &args,
Feedback &
) : cAction(world, args)
, m_replprob(0.01)
, m_requirefull(false)
, m_replmax(std::numeric_limits<int>::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)
{
Expand Down Expand Up @@ -5519,8 +5528,23 @@ class cActionReplicateDemesHighestFecundity : public cAction
std::vector<int> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 54e4987

Please sign in to comment.