Skip to content

Commit

Permalink
Implement, test demes parasite memory
Browse files Browse the repository at this point in the history
  • Loading branch information
mmore500 committed Nov 15, 2023
1 parent d7b9d1b commit ac3c000
Show file tree
Hide file tree
Showing 18 changed files with 1,444 additions and 1 deletion.
75 changes: 75 additions & 0 deletions avida-core/source/actions/PopulationActions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,47 @@ class cActionKillProb : public cAction
}
};

class cActionClearParasites : public cAction
{
private:
int m_cell_start;
int m_cell_end;

public:
cActionClearParasites(cWorld *world, const cString &args, Feedback &) : cAction(world, args), m_cell_start(0), m_cell_end(-1)
{
cString largs(args);
if (largs.GetSize())
m_cell_start = largs.PopWord().AsInt();
if (largs.GetSize())
m_cell_end = largs.PopWord().AsInt();

if (m_cell_end == -1)
m_cell_end = m_cell_start + 1;
}

static const cString GetDescription() { return "Arguments: [int cell_start=0] [int cell_end=-1]"; }

void Process(cAvidaContext &ctx)
{
if (m_cell_start < 0 || m_cell_end > m_world->GetPopulation().GetSize() || m_cell_start >= m_cell_end)
{
ctx.Driver().Feedback().Warning("ClearParasites has invalid range!");
}
else
{
cUserFeedback feedback;
const cInstSet &is = m_world->GetHardwareManager().GetDefaultInstSet();
for (int i = m_cell_start; i < m_cell_end; i++)
{
auto &cell = m_world->GetPopulation().GetCell(i);
if (cell.IsOccupied()) cell.GetOrganism()->ClearParasites();
}
m_world->GetPopulation().SetSyncEvents(true);
}
}
};

/*
Applies a fixed population bottleneck to the current population.
Parameters:
Expand Down Expand Up @@ -3970,6 +4011,38 @@ class cActionDecayPoints : public cAction
}
};


class cActionUpdateDemeParasiteMemoryScores : public cAction
{
private:
double m_decay_rate;
bool m_verbose;

public:
cActionUpdateDemeParasiteMemoryScores(cWorld* world, const cString& args, Feedback&) : cAction(world, args), m_decay_rate(0.99), m_verbose(false)
{
cString largs(args);
m_decay_rate = largs.PopWord().AsDouble();
m_verbose = largs.PopWord().AsInt();
}

static const cString GetDescription() { return "Arguments: <double decay_rate>"; }

void Process(cAvidaContext& ctx)
{
auto& pop = m_world->GetPopulation();
const int numDemes = pop.GetNumDemes();
for (int deme_id = 0; deme_id < numDemes; deme_id++)
{
auto &deme = pop.GetDeme(deme_id);
deme.UpdateParasiteMemoryScore(m_decay_rate);
if (m_verbose) std::cout << deme.GetParasiteMemoryScore() << " ";
}
if (m_verbose) std::cout << std::endl;
}
};


class cActionCompeteOrganisms : public cAction
{
private:
Expand Down Expand Up @@ -5826,6 +5899,7 @@ void RegisterPopulationActions(cActionLibrary* action_lib)
action_lib->Register<cActionKillInstLimit>("KillInstLimit");
action_lib->Register<cActionKillInstPair>("KillInstPair");
action_lib->Register<cActionKillProb>("KillProb");
action_lib->Register<cActionClearParasites>("ClearParasites");
action_lib->Register<cActionApplyBottleneck>("ApplyBottleneck");
action_lib->Register<cActionKillDominantGenotype>("KillDominantGenotype");
action_lib->Register<cActionProbKillSequence>("KillProbSequence");
Expand Down Expand Up @@ -5859,6 +5933,7 @@ void RegisterPopulationActions(cActionLibrary* action_lib)
action_lib->Register<cActionMixPopulation>("MixPopulation");

action_lib->Register<cActionDecayPoints>("DecayPoints");
action_lib->Register<cActionUpdateDemeParasiteMemoryScores>("UpdateDemeParasiteMemoryScores");

action_lib->Register<cActionFlash>("Flash");

Expand Down
1 change: 1 addition & 0 deletions avida-core/source/main/cAvidaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ class cAvidaConfig {
CONFIG_ADD_VAR(DEMES_PARASITE_MIGRATION_RATE, double, 0.0, "Probability of a parasite migrating to a different deme. Note: only works with DEMES_MIGRATION_METHOD 4.");
CONFIG_ADD_VAR(DEMES_MIGRATION_METHOD, int, 0, "Which demes can an offspring land in when it migrates?\n0 = Any other deme\n1 = Eight neighboring demes\n2 = Two adjacent demes in list\n3 = Proportional based on the number of points\n4 = Use the weight matrix specified in MIGRATION_FILE");
CONFIG_ADD_VAR(DEMES_PARASITE_MIGRATION_TARGET_SELECTION_METHOD, int, 0, "How should a target cell be chosen in the migrated-to deme?\n0 = Select a cell randomly, if it is not occupied infection fails\n1 = Select an occupied cell randomly");
CONFIG_ADD_VAR(DEMES_PARASITE_MIGRATION_MEMORY_SCORE_PROTECTIVE_THRESHOLD, double, 1.0, "Above what parasite memory score should hosts be protected from incoming parasite migration?");
CONFIG_ADD_VAR(DEMES_NUM_X, int, 0, "Simulated number of demes in X dimension. Used only for migration. ");
CONFIG_ADD_VAR(DEMES_PARTITION_INTERVAL, int, 0, "Restrict deme replication to within partitions of DEMES_PARTITION_INTERVAL consecutive deme ids. No restriction if 0. Partition size cannot be smaller than two. Does not affect migration.");
CONFIG_ADD_VAR(DEMES_SEED_METHOD, int, 0, "Deme seeding method.\n0 = Maintain old consistency\n1 = New method using genotypes");
Expand Down
4 changes: 4 additions & 0 deletions avida-core/source/main/cDeme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ cDeme::cDeme()
, birth_count_perslot(0)
, _age(0)
, generation(0)
, parasite_memory_score(0.0)
, total_org_energy(0.0)
, time_used(0)
, gestation_time(0)
Expand Down Expand Up @@ -117,6 +118,7 @@ cDeme& cDeme::operator=(const cDeme& in_deme)
birth_count_perslot = in_deme.birth_count_perslot;
_age = in_deme._age;
generation = in_deme.generation;
parasite_memory_score = in_deme.parasite_memory_score;
total_org_energy = in_deme.total_org_energy;
time_used = in_deme.time_used;
gestation_time = in_deme.gestation_time;
Expand Down Expand Up @@ -202,6 +204,7 @@ void cDeme::Setup(int id, const Apto::Array<int> & in_cells, int in_width, cWorl
last_org_count = 0;
birth_count_perslot = 0;
m_world = world;
parasite_memory_score = 0.0;

replicateDeme = false;

Expand Down Expand Up @@ -513,6 +516,7 @@ void cDeme::Reset(cAvidaContext& ctx, bool resetResources, double deme_energy)
time_used = 0;
cur_birth_count = 0;
cur_normalized_time_used = 0;
parasite_memory_score = 0.0;
injected_count = 0;
birth_count_perslot = 0;
eventsTotal = 0;
Expand Down
9 changes: 8 additions & 1 deletion avida-core/source/main/cDeme.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class cDeme
int birth_count_perslot;
int _age; //!< Age of this deme, in updates.
int generation; //!< Generation of this deme
double parasite_memory_score;
double total_org_energy; //! amount of energy in organisms in this deme
int time_used; //!< number of cpu cycles this deme has used
int gestation_time; // Time used during last generation
Expand Down Expand Up @@ -188,7 +189,13 @@ class cDeme
double GetParasiteLoad() const {
return static_cast<double>(GetNumParasites()) / GetOrgCount();
}


void UpdateParasiteMemoryScore(const double decay) {
parasite_memory_score += GetParasiteLoad();
parasite_memory_score *= decay;
}
double GetParasiteMemoryScore() const { return parasite_memory_score; }

void IncOrgCount() { cur_org_count++; }
void DecOrgCount() { cur_org_count--; }

Expand Down
Loading

0 comments on commit ac3c000

Please sign in to comment.