Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make deme kill/replicate actions respect partitions #89

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 53 additions & 12 deletions avida-core/source/actions/PopulationActions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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;
Expand Down Expand Up @@ -5314,16 +5332,18 @@ class cActionKillDemesHighestParasiteLoad : public cAction

struct Comp {
std::vector<double>& loads;
Comp(std::vector<double> &loads) : loads(loads) {}
const int begin;
Comp(std::vector<double> &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 {
Expand Down Expand Up @@ -5362,12 +5382,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<int> 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,
Expand All @@ -5394,17 +5433,19 @@ class cActionReplicateDemesHighestBirthCount : public cAction

struct Comp {
std::vector<double> &births;
Comp(std::vector<double> &births) : births(births) {}
const int begin;
Comp(std::vector<double> &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 {
Expand Down
Loading