Skip to content

Commit

Permalink
Impl para migration method guaranteeing infection
Browse files Browse the repository at this point in the history
  • Loading branch information
mmore500 committed Nov 15, 2023
1 parent 8a4bfc7 commit 4ad71a5
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 2 deletions.
1 change: 1 addition & 0 deletions avida-core/source/main/cAvidaConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ class cAvidaConfig {
CONFIG_ADD_VAR(DEMES_MIGRATION_RATE, double, 0.0, "Probability of an offspring being born in a different deme.");
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_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
23 changes: 21 additions & 2 deletions avida-core/source/main/cPopulation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1210,13 +1210,32 @@ bool cPopulation::ActivateParasite(cOrganism* host, Systematics::UnitPtr parent,
&& m_world->GetRandom().P(m_world->GetConfig().DEMES_PARASITE_MIGRATION_RATE.Get())
){
cDeme& deme = GetDeme(m_world->GetMigrationMatrix().GetProbabilisticDemeID(host_cell.GetDemeID(), m_world->GetRandom(),true));

deme.
const int infection_mode = m_world->GetConfig().DEMES_PARASITE_MIGRATION_TARGET_SELECTION_METHOD.Get();
if (infection_mode == 0) {
// Implementation #1 - Picks randomly of ALL cells in to-deme and then finds if the one it chose was occupied
// -- Not ensured to infect an individual
cPopulationCell& rand_cell = deme.GetCell(m_world->GetRandom().GetInt(deme.GetSize()));
if(rand_cell.IsOccupied()){
target_organism = rand_cell.GetOrganism();
}
}
} else if (infection_mode == 1) {
// Implementation #2 - Picks randomly, guaranteeing an infection
const int num_occupied_cells = deme.GetOrgCount();
int which_cell = m_world->GetRandom().GetInt(num_occupied_cells);
for (int i = 0; i < deme.GetSize(); i++) {
if (deme.GetCell(i).IsOccupied()) {
if (which_cell == 0) {
target_organism = deme.GetCell(i).GetOrganism();
break;
}
which_cell--;
}
}
} else {
std::cout << "bad demes parasite migration infection mode " << infection_mode << std::endl;
std::abort();
}
}
else{
// Else there was no migration ... Resort to the default BIRTH_METHOD
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#filetype genotype_data
#format id src src_args parents num_units total_units length merit gest_time fitness gen_born update_born update_deactivated depth hw_type inst_set sequence cells gest_offset lineage
# Structured Population Save
# Tue Nov 14 23:23:19 2023
# 1: ID
# 2: Source
# 3: Source Args
# 4: Parent ID(s)
# 5: Number of currently living organisms
# 6: Total number of organisms that ever existed
# 7: Genome Length
# 8: Average Merit
# 9: Average Gestation Time
# 10: Average Fitness
# 11: Generation Born
# 12: Update Born
# 13: Update Deactivated
# 14: Phylogenetic Depth
# 15: Hardware Type ID
# 16: Inst Set Name
# 17: Genome Sequence
# 18: Occupied Cell IDs
# 19: Gestation (CPU) Cycle Offsets
# 20: Lineage Label

1 div:ext (none) (none) 300 300 320 0 0 0 0 -1 -1 0 2 transsmt ycdAoaddxccccccccccccccEEEcccccccccccccccccccccccccccccccccccccccccccccccccccgccccccccccccccccccccccccccccccccccccccccEccccDcccccccccccccccccccccccccccccccccccccccccccccccccccdccccccccccccccccccccccccccccccccccccccccccxcccccccccccccccccccccccccccccccccccccccccccccccccAcccccccccccccccccccucccccccccccccccccccccypqvcrGxab 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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