Skip to content

Commit

Permalink
Fix kill demes highest para load, write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmore500 committed Nov 15, 2023
1 parent 25b2468 commit e401aca
Show file tree
Hide file tree
Showing 12 changed files with 1,297 additions and 43 deletions.
79 changes: 36 additions & 43 deletions avida-core/source/actions/PopulationActions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5195,61 +5195,54 @@ class cActionKillDemesHighestParasiteLoad : public cAction

void Process(cAvidaContext& ctx)
{

int target_cell;
cPopulation& pop = m_world->GetPopulation();
const int num_demes = pop.GetNumDemes();
std::vector<double> parasite_loads(num_demes);
int num_eligible = 0;

long cells_scanned = 0;
long orgs_killed = 0;
long cells_empty = 0;
const int deme_size = m_world->GetConfig().WORLD_X.Get() * (m_world->GetConfig().WORLD_Y.Get() / num_demes);
const double smudge_delta = 0.09 / deme_size;
int smudge_index = ctx.GetRandom().GetInt(0, num_demes - 1);
for (int d = 0; d < num_demes; d++)
{
cDeme &deme = pop.GetDeme(d);
if (not deme.IsEmpty())
{
num_eligible++;
const auto parasite_load = deme.GetParasiteLoad();
if (parasite_load == 0.0) continue;
// need to guarantee that parasite_loads are distinct to set threshold
parasite_loads[d] = parasite_load + smudge_delta * smudge_index;
++smudge_index;
if (smudge_index >= num_demes) smudge_index -= num_demes;
}
}

const int num_demes = pop.GetNumDemes();
const int binomial_draw = ctx.GetRandom().GetRandBinomial(
num_demes,
m_killprob
num_eligible,
m_killprob
);
const int kill_quota = std::min(binomial_draw, m_killmax);
if (kill_quota == 0) return;
std::cout << "kill quota " << kill_quota << std::endl;

double kill_thresh = 1.0;
int init_countdown = kill_quota;
int d;
int _num_eligible = 0;
for (int d = 0; d < pop.GetNumDemes(); d++) {
cDeme &deme = pop.GetDeme(d);
if (deme.IsTreatableNow() && not deme.IsEmpty()) {
{
_num_eligible++;
if (init_countdown > 0) {
kill_thresh = std::min(
kill_thresh,
deme.GetParasiteLoad()
);
init_countdown--;
} else {
kill_thresh = std::max(
deme.GetParasiteLoad(), kill_thresh
);
}
} // End if deme is treatable
} //End iterating through all demes

// go through and kill cells
int _num_killed = 0;
for (int d = 0; d < pop.GetNumDemes(); d++)
std::vector<double> top_n(kill_quota);
const auto partial_sort_end = std::partial_sort_copy(
parasite_loads.begin(), parasite_loads.end(),
top_n.begin(), top_n.end(),
std::greater<int>()
);
const auto kill_thresh = *std::prev(partial_sort_end);
std::cout << "kill thresh " << kill_thresh << std::endl;
for (int d = 0; d < num_demes; d++)
{
cDeme &deme = pop.GetDeme(d);
if (
deme.IsTreatableNow() && not deme.IsEmpty() && (deme.GetParasiteLoad() >= kill_thresh))
if (parasite_loads[d] and parasite_loads[d] >= kill_thresh)
{
_num_killed += 1;
std::cout << "bump" << std::endl;
cDeme &deme = pop.GetDeme(d);
deme.KillAll(ctx);
} // End if deme is eligible
} //End iterating through all demes
}
}

const auto _expected_killed = std::min(_num_eligible, kill_quota);
assert(_num_killed == _expected_killed);
} // End Process()
};

Expand Down
689 changes: 689 additions & 0 deletions avida-core/tests/demes_KillDemesHighestParasiteLoad/config/avida.cfg

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
REACTION NOT not process:value=1.0:type=pow requisite:max_count=1
REACTION NAND nand process:value=1.0:type=pow requisite:max_count=1
REACTION AND and process:value=2.0:type=pow requisite:max_count=1
REACTION ORN orn process:value=2.0:type=pow requisite:max_count=1
REACTION OR or process:value=3.0:type=pow requisite:max_count=1
REACTION ANDN andn process:value=3.0:type=pow requisite:max_count=1
REACTION NOR nor process:value=4.0:type=pow requisite:max_count=1
REACTION XOR xor process:value=4.0:type=pow requisite:max_count=1
REACTION EQU equ process:value=5.0:type=pow requisite:max_count=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
u begin InjectAll filename=evolved-not.org
u begin InjectParasite parasite-smt.org ABB 0 3
u begin InjectParasite parasite-smt.org ABB 17
u begin InjectParasite parasite-smt.org ABB 170
u begin InjectParasite parasite-smt.org ABB 200 203
u begin SavePopulation
u 2 KillDemesHighestParasiteLoad 1.0 1
u 2 SavePopulation
u 3 SavePopulation
u 3 Exit
Loading

0 comments on commit e401aca

Please sign in to comment.