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

Empirical pointers and variable name case updates #225

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
32 changes: 16 additions & 16 deletions source/default_mode/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Host: public Organism {
/**
*
* Purpose: Represents the set of in-progress "reproductive" symbionts belonging to a host. These are symbionts that aren't yet active.
* Symbionts can be added with AddReproSymb(). This can be cleared with ClearSyms()
* Symbionts can be added with AddReproSym(). This can be cleared with ClearSyms()
*
*/
emp::vector<emp::Ptr<Organism>> repro_syms = {};
Expand Down Expand Up @@ -401,17 +401,17 @@ class Host: public Organism {
* steal resources from the host.
*/
double StealResources(double _intval){
double hostIntVal = GetIntVal();
double host_int_val = GetIntVal();
double res_in_process = GetResInProcess();
//calculate how many resources another organism can steal from this host
if (hostIntVal>0){ //cooperative hosts shouldn't be over punished by StealResources
hostIntVal = 0;
if (host_int_val >0){ //cooperative hosts shouldn't be over punished by StealResources
host_int_val = 0;
}
if (_intval < hostIntVal){
if (_intval < host_int_val){
//organism trying to steal can overcome host's defense
double stolen = (hostIntVal - _intval) * res_in_process;
double remainingResources = res_in_process - stolen;
SetResInProcess(remainingResources);
double stolen = (host_int_val - _intval) * res_in_process;
double remaining_resources = res_in_process - stolen;
SetResInProcess(remaining_resources);
return stolen;
} else {
//defense cannot be overcome, no resources are stolen
Expand Down Expand Up @@ -477,7 +477,7 @@ class Host: public Organism {
}
else{
int num_syms = syms.size();
//essentially imitaties a 1/ 2^n chance, with n = number of symbionts
//essentially imitates a 1/ 2^n chance, with n = number of symbionts
int enter_chance = random->GetUInt((int) pow(2.0, num_syms));
if(enter_chance == 0) { return true; }
return false;
Expand Down Expand Up @@ -590,7 +590,7 @@ class Host: public Organism {
} //end DistribResources

/**
* Input: The total resources recieved by the host and its location in the world.
* Input: The total resources received by the host and its location in the world.
*
* Output: The resources remaining after the host maybe does ectosymbiosis.
*
Expand Down Expand Up @@ -660,7 +660,7 @@ class Host: public Organism {
size_t location = pos.GetIndex();
//Currently just wrapping to use the existing function
double desired_resources = my_config->RES_DISTRIBUTE();
double world_resources = my_world->PullResources(desired_resources); //recieve resources from the world
double world_resources = my_world->PullResources(desired_resources); //receive resources from the world
double resources = HandleEctosymbiosis(world_resources, location);
if(resources > 0) DistribResources(resources); //if there are enough resources left, distribute them.

Expand All @@ -683,21 +683,21 @@ class Host: public Organism {
if (HasSym()) { //let each sym do whatever they need to do
emp::vector<emp::Ptr<Organism>>& syms = GetSymbionts();
for(size_t j = 0; j < syms.size(); j++){
emp::Ptr<Organism> curSym = syms[j];
emp::Ptr<Organism> cur_sym = syms[j];
if (GetDead()){
return; //If previous symbiont killed host, we're done
}
//sym position should have host index as id and
//position in syms list + 1 as index (0 as fls index)
emp::WorldPosition sym_pos = emp::WorldPosition(j+1, location);
if(!curSym->GetDead()){
curSym->Process(sym_pos);
if(!cur_sym->GetDead()){
cur_sym->Process(sym_pos);
}
if(curSym->GetDead()) {
if(cur_sym->GetDead()) {
//if the symbiont dies during their process, remove from syms list
//UNLESS they died by getting ousted
syms.erase(syms.begin() + j);
curSym.Delete();
cur_sym.Delete();
}
} //for each sym in syms
} //if org has syms
Expand Down
4 changes: 2 additions & 2 deletions source/default_mode/SymWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class SymWorld : public emp::World<Organism>{
*
* Purpose: To destruct the objects belonging to SymWorld to conserve memory.
*/
~SymWorld() {
virtual ~SymWorld() {
if (data_node_hostintval) data_node_hostintval.Delete();
if (data_node_symintval) data_node_symintval.Delete();
if (data_node_freesymintval) data_node_freesymintval.Delete();
Expand Down Expand Up @@ -224,7 +224,7 @@ class SymWorld : public emp::World<Organism>{
* Output: The standard function object that determines which bin organisms
* should belong to depending on their interaction value
*
* Purpose: To classify organsims based on their interaction value.
* Purpose: To classify organisms based on their interaction value.
*/
fun_calc_info_t GetCalcInfoFun() {
if (!calc_info_fun) {
Expand Down
9 changes: 3 additions & 6 deletions source/default_mode/Symbiont.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class Symbiont: public Organism {


/**
* Input: The double representing the points to be set as a symbinot's points
* Input: The double representing the points to be set as a symbiont's points
*
* Output: None
*
Expand All @@ -306,7 +306,7 @@ class Symbiont: public Organism {


/**
* Input: The double representing the points to be added to a symbinot's points
* Input: The double representing the points to be added to a symbiont's points
*
* Output: None
*
Expand All @@ -333,7 +333,7 @@ class Symbiont: public Organism {
void SetAge(int _in) {age = _in;}

/**
* Input: The pointer to an organism that will be set as the symbinot's host
* Input: The pointer to an organism that will be set as the symbiont's host
*
* Output: None
*
Expand All @@ -353,8 +353,6 @@ class Symbiont: public Organism {
else infection_chance = _in;
}

//void SetResTypes(std::set<int> _in) {res_types = _in;}


/**
* Input: None
Expand Down Expand Up @@ -503,7 +501,6 @@ class Symbiont: public Organism {
* Purpose: To process a symbiont, meaning to check for reproduction, distribute resources,
* and to allow for movement
*/
//size_t rank=-1
void Process(emp::WorldPosition location) {
//ID is where they are in the world, INDEX is where they are in the host's symbiont list (or 0 if they're free living)
if (my_host.IsNull() && my_config->FREE_LIVING_SYMS()) { //free living symbiont
Expand Down
4 changes: 2 additions & 2 deletions source/pgg_mode/PGGHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class PGGHost: public Host {
Host::DistribResources(resources);

for(size_t i=0; i < syms.size(); i++){
double hostPool = syms[i]->ProcessPool();
this->AddPool(hostPool);
double host_pool = syms[i]->ProcessPool();
this->AddPool(host_pool);
}
if(syms.size()>0){this->DistribPool();}
} //end DistribResources
Expand Down
12 changes: 6 additions & 6 deletions source/pgg_mode/PGGSymbiont.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,16 @@ class PGGSymbiont: public Symbiont {
*
* Output: The double representation of resources to be given to the host.
*
* Purpose: Deteremines the resources that the symbiont is contributing
* Purpose: Determines the resources that the symbiont is contributing
* to the host's resource pool, and decriments them from the symbiont's own
* own resource collection.
*/
double ProcessPool(){
double symdonation = GetDonation();
double symPortion = GetPoints();
double hostreturn = symdonation*symPortion;
SetPoints(symPortion-hostreturn);
return hostreturn;
double sym_donation = GetDonation();
double sym_portion = GetPoints();
double host_return = sym_donation * sym_portion;
SetPoints(sym_portion - host_return);
return host_return;
}

/**
Expand Down
45 changes: 30 additions & 15 deletions source/test/default_mode_test/Host.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

TEST_CASE("Host Constructor", "[default]") {

emp::Ptr<emp::Random> random = new emp::Random(-1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(4);
SymConfigBase config;
SymWorld w(*random, &config);
SymWorld * world = &w;
Expand Down Expand Up @@ -56,10 +56,11 @@ TEST_CASE("Host Constructor", "[default]") {
host1.Delete();
host2.Delete();
host3.Delete();
random.Delete();
}

TEST_CASE("Host SetIntVal, GetIntVal", "[default]") {
emp::Ptr<emp::Random> random = new emp::Random(-1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(4);
SymConfigBase config;
SymWorld world(*random, &config);
double int_val = 1;
Expand All @@ -86,10 +87,11 @@ TEST_CASE("Host SetIntVal, GetIntVal", "[default]") {

host1.Delete();
host2.Delete();
random.Delete();
}

TEST_CASE("SetPoints, AddPoints, GetPoints", "[default]") {
emp::Ptr<emp::Random> random = new emp::Random(-1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(4);
SymConfigBase config;
SymWorld world(*random, &config);
double int_val = 1;
Expand All @@ -107,10 +109,11 @@ TEST_CASE("SetPoints, AddPoints, GetPoints", "[default]") {
REQUIRE(host->GetPoints() == expected_points);

host.Delete();
random.Delete();
}

TEST_CASE("HasSym", "[default]") {
emp::Ptr<emp::Random> random = new emp::Random(-1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(4);
SymConfigBase config;
SymWorld world(*random, &config);
double int_val = 1;
Expand All @@ -131,11 +134,12 @@ TEST_CASE("HasSym", "[default]") {
}
}
host.Delete();
random.Delete();
}

TEST_CASE("Host Mutate", "[default]") {
//TODO: put in tests for mutation size and mutation rate separately
emp::Ptr<emp::Random> random = new emp::Random(3);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(3);
SymConfigBase config;
SymWorld world(*random, &config);
double int_val = -0.31;
Expand Down Expand Up @@ -200,10 +204,11 @@ TEST_CASE("Host Mutate", "[default]") {
host.Delete();
}
}
random.Delete();
}

TEST_CASE("DistributeResources", "[default]") {
emp::Ptr<emp::Random> random = new emp::Random(-1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(5);
SymConfigBase config;
SymWorld world(*random, &config);

Expand Down Expand Up @@ -268,10 +273,11 @@ TEST_CASE("DistributeResources", "[default]") {

host.Delete();
}
random.Delete();
}

TEST_CASE("SetResInProcess, GetResInProcess", "[default]") {
emp::Ptr<emp::Random> random = new emp::Random(-1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(3);
SymConfigBase config;
SymWorld world(*random, &config);
double int_val = 1;
Expand All @@ -286,10 +292,11 @@ TEST_CASE("SetResInProcess, GetResInProcess", "[default]") {
REQUIRE(host->GetResInProcess() == expected_res_in_process);

host.Delete();
random.Delete();
}

TEST_CASE("Steal resources unit test", "[default]"){
emp::Ptr<emp::Random> random = new emp::Random(-1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(3);
SymConfigBase config;
SymWorld world(*random, &config);

Expand Down Expand Up @@ -342,11 +349,12 @@ TEST_CASE("Steal resources unit test", "[default]"){
}
host.Delete();
}
random.Delete();
}

TEST_CASE("GetDoEctosymbiosis", "[default]"){
GIVEN("A world"){
emp::Ptr<emp::Random> random = new emp::Random(17);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(17);
SymConfigBase config;
SymWorld world(*random, &config);
world.Resize(2,2);
Expand Down Expand Up @@ -425,11 +433,12 @@ TEST_CASE("GetDoEctosymbiosis", "[default]"){
REQUIRE(host->GetDoEctosymbiosis(host_pos) == true);
}
}
random.Delete();
}
}

TEST_CASE("Host GrowOlder", "[default]"){
emp::Ptr<emp::Random> random = new emp::Random(-1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(4);
SymConfigBase config;
SymWorld world(*random, &config);
config.HOST_AGE_MAX(2);
Expand All @@ -449,10 +458,11 @@ TEST_CASE("Host GrowOlder", "[default]"){
REQUIRE(world.GetNumOrgs() == 0);
}
}
random.Delete();
}

TEST_CASE("Host MakeNew", "[default]"){
emp::Ptr<emp::Random> random = new emp::Random(-1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(4);
SymConfigBase config;
SymWorld world(*random, &config);

Expand All @@ -469,10 +479,11 @@ TEST_CASE("Host MakeNew", "[default]"){

host1.Delete();
host2.Delete();
random.Delete();
}

TEST_CASE("Host Reproduce", "[default]"){
emp::Ptr<emp::Random> random = new emp::Random(-1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(4);
SymConfigBase config;
SymWorld world(*random, &config);

Expand All @@ -488,10 +499,11 @@ TEST_CASE("Host Reproduce", "[default]"){

host1.Delete();
host2.Delete();
random.Delete();
}

TEST_CASE("AddSymbiont", "[default]"){
emp::Ptr<emp::Random> random = new emp::Random(-1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(4);
SymConfigBase config;
SymWorld world(*random, &config);
double int_val = 0;
Expand Down Expand Up @@ -542,6 +554,7 @@ TEST_CASE("AddSymbiont", "[default]"){
REQUIRE(world.GetGraveyard().size() == 0);
}
}
random.Delete();
}

TEST_CASE("SymAllowedIn", "[default]") {
Expand All @@ -554,7 +567,7 @@ TEST_CASE("SymAllowedIn", "[default]") {
WHEN("Symbiont exclude is set to false") {
config.PHAGE_EXCLUDE(0);
THEN("Symbionts are added without issue") {
emp::Ptr<emp::Random> random = new emp::Random(3);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(3);
SymWorld world(*random, &config);
emp::Ptr<Host> host = emp::NewPtr<Host>(random, &world, &config, int_val);
for (int i = 0; i < sym_limit; i++) {
Expand All @@ -563,6 +576,7 @@ TEST_CASE("SymAllowedIn", "[default]") {
int num_syms = (host->GetSymbionts()).size();
REQUIRE(num_syms == sym_limit);
host.Delete();
random.Delete();
}
}

Expand All @@ -571,7 +585,7 @@ TEST_CASE("SymAllowedIn", "[default]") {
THEN("Symbionts have a decreasing change of entering the host") {
int goal_num_syms[] = { 3,3,3,3 };
for (int i = 0; i < 4; i++) {
emp::Ptr<emp::Random> random = new emp::Random(i + 1);
emp::Ptr<emp::Random> random = emp::NewPtr<emp::Random>(i + 1);
SymWorld world(*random, &config);
emp::Ptr<Host> host = emp::NewPtr<Host>(random, &world, &config, int_val);

Expand All @@ -581,6 +595,7 @@ TEST_CASE("SymAllowedIn", "[default]") {
int host_num_syms = (host->GetSymbionts()).size();
REQUIRE(goal_num_syms[i] == host_num_syms);
host.Delete();
random.Delete();
}
}
}
Expand Down
Loading
Loading