Skip to content

Commit

Permalink
Merge pull request #199 from K-Johnson-Horrigan/dev-branch
Browse files Browse the repository at this point in the history
Free living syms have unique repro res threshold
  • Loading branch information
anyaevostinar committed Dec 5, 2022
2 parents 28d4e90 + 3ed396a commit 833411c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
1 change: 1 addition & 0 deletions source/ConfigSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ EMP_BUILD_CONFIG(SymConfigBase,
VALUE(ECTOSYMBIOSIS, bool, 0, "Do free-living syms and parallel hosts interact? (0 for no, 1 for yes)"),
VALUE(ECTOSYMBIOTIC_IMMUNITY, bool, 0, "Does a hosted sym confer immunity to ectosymbiosis? (0 for no, 1 for yes)"),
VALUE(FREE_SYM_RES_DISTRIBUTE, int, 0, "Number of resources to give to each free-living symbiont each update if they are available"),
VALUE(FREE_SYM_REPRO_RES, double, -1, "How many resources required for free living symbiont reproduction. If -1, use the horizontal transmission required point value."),

GROUP(LYSIS, "Lysis Settings, coming soon to the GUI!"),
VALUE(LYSIS_CHANCE, double, -1, "Chance of lysis vs. lysogeny for starting population of phage, -1 for random distribution"),
Expand Down
6 changes: 5 additions & 1 deletion source/default_mode/Symbiont.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,11 @@ class Symbiont: public Organism {
*/
void HorizontalTransmission(emp::WorldPosition location) {
if (my_config->HORIZ_TRANS()) { //non-lytic horizontal transmission enabled
if(GetPoints() >= my_config->SYM_HORIZ_TRANS_RES()) {
double required_points = my_config->SYM_HORIZ_TRANS_RES();
if (my_config->FREE_LIVING_SYMS() && my_host == nullptr && my_config->FREE_SYM_REPRO_RES() > -1) {
required_points = my_config->FREE_SYM_REPRO_RES();
}
if (GetPoints() >= required_points) {
// symbiont reproduces independently (horizontal transmission) if it has enough resources
//TODO: try just subtracting points to be consistent with vertical transmission
//points = points - my_config->SYM_HORIZ_TRANS_RES();
Expand Down
74 changes: 73 additions & 1 deletion source/test/default_mode_test/Symbiont.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ TEST_CASE("Process", "[default]") {
SymWorld w(*random, &config);
SymWorld * world = &w;

//add new test for free living sym not moving when it shouldnt
//add new test for free living sym not moving when it shouldn't
WHEN("Horizontal transmission is true and points is greater than sym_h_res") {
double int_val = 1;
// double parent_orig_int_val = 1;
Expand Down Expand Up @@ -536,6 +536,78 @@ TEST_CASE("Process", "[default]") {

sym.Delete();
}

WHEN("The symbiont is free living and horizontal transmission is true") {
config.FREE_LIVING_SYMS(1);
config.SYM_HORIZ_TRANS_RES(140.0);
config.HORIZ_TRANS(true);
double int_val = 0;
int points = 0;

WHEN("Free living symbionts have a different reproductive resource threshold than hosted symbionts") {
int free_sym_repro_res = 70;
config.FREE_SYM_REPRO_RES(free_sym_repro_res);
emp::Ptr<Symbiont> sym = emp::NewPtr<Symbiont>(random, world, &config, int_val, points);
emp::WorldPosition location = emp::WorldPosition(0, 10);
world->AddOrgAt(sym, location);

WHEN("The free living symbiont does not have enough resources to reproduce") {
int orig_points = free_sym_repro_res - 10;
size_t orig_num_orgs = world->GetNumOrgs();
sym->AddPoints(orig_points);
sym->Process(location);

THEN("The free living symbiont does not reproduce") {
REQUIRE(world->GetNumOrgs() == orig_num_orgs);
REQUIRE(sym->GetPoints() == orig_points);
}

}
WHEN("The free living symbiont has enough resources to reproduce") {
int orig_points = free_sym_repro_res + 10;
size_t orig_num_orgs = world->GetNumOrgs();
sym->AddPoints(orig_points);
sym->Process(location);

THEN("The free living symbiont reproduces and sets its points to 0") {
REQUIRE(world->GetNumOrgs() == (orig_num_orgs + 1));
REQUIRE(sym->GetPoints() == 0);
}
}
}
WHEN("Free living symbionts have the same reproductive resource threshold as hosted symbionts do for horizontal transmission") {
int sym_h_res = 120;
config.SYM_HORIZ_TRANS_RES(sym_h_res);
config.FREE_SYM_REPRO_RES(-1);
emp::Ptr<Symbiont> sym = emp::NewPtr<Symbiont>(random, world, &config, int_val, points);
emp::WorldPosition location = emp::WorldPosition(0, 10);
world->AddOrgAt(sym, location);

WHEN("The free living symbiont does not have enough resources to reproduce") {
int orig_points = sym_h_res - 10;
size_t orig_num_orgs = world->GetNumOrgs();
sym->AddPoints(orig_points);
sym->Process(location);

THEN("The free living symbiont does not reproduce") {
REQUIRE(world->GetNumOrgs() == orig_num_orgs);
REQUIRE(sym->GetPoints() == orig_points);
}

}
WHEN("The free living symbiont has enough resources to reproduce") {
int orig_points = sym_h_res + 10;
size_t orig_num_orgs = world->GetNumOrgs();
sym->AddPoints(orig_points);
sym->Process(location);

THEN("The free living symbiont reproduces and sets its points to 0") {
REQUIRE(world->GetNumOrgs() == (orig_num_orgs + 1));
REQUIRE(sym->GetPoints() == 0);
}
}
}
}
}

TEST_CASE("Symbiont ProcessResources", "[default]"){
Expand Down

0 comments on commit 833411c

Please sign in to comment.