Skip to content

Commit

Permalink
Merge branch 'complex-syms-clean' of https://github.com/K-Johnson-Hor…
Browse files Browse the repository at this point in the history
  • Loading branch information
K-Johnson-Horrigan committed Nov 1, 2024
2 parents 99331fd + 8fc0edc commit 027c516
Show file tree
Hide file tree
Showing 21 changed files with 218 additions and 72 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ jobs:
- name: run symbulation
run: cd SymbulationEmp && make debug-default && ./symbulation_default -GRID_X 5 -GRID_Y 5

- name: test web build
run: cd SymbulationEmp/emsdk && ./emsdk install 1.38.48 && ./emsdk activate 1.38.48 && source ./emsdk_env.sh && cd .. && make web

# Runs a single command using the runners shell
- name: Make tests
run: cd SymbulationEmp && make coverage


- name: test web build
run: cd SymbulationEmp/emsdk && ./emsdk install 1.38.48 && ./emsdk activate 1.38.48 && source ./emsdk_env.sh && cd .. && make web

- name: Generate coverage
run: cd SymbulationEmp && gcov -abcfu main.cc

- name: Upload coverage
uses: codecov/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
url = https://github.com/emscripten-core/emsdk
[submodule "signalgp-lite"]
path = signalgp-lite
url = https://github.com/tolziplohu/signalgp-lite
url = https://github.com/amlalejini/signalgp-lite
2 changes: 1 addition & 1 deletion Empirical
Submodule Empirical updated 891 files
21 changes: 11 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ EMP_DIR := Empirical/include
SGP_DIR := signalgp-lite/include

# Flags to use regardless of compiler
CFLAGS_all := -Wall -Wno-unused-function -std=c++17 -I$(EMP_DIR)/ -I$(SGP_DIR)/
VENDORIZE_EMP_FLAGS := -DUIT_VENDORIZE_EMP -DUIT_SUPPRESS_MACRO_INSEEP_WARNINGS
CFLAGS_all := -Wall -Wno-unused-function -std=c++20 -I$(EMP_DIR)/ -I$(SGP_DIR)/ ${VENDORIZE_EMP_FLAGS}

# Native compiler information
CXX_nat := g++
Expand Down Expand Up @@ -65,27 +66,27 @@ debug:
@echo SGP mode: make debug-sgp

debug-default: CFLAGS_nat := $(CFLAGS_nat_debug)
debug-default: default-mode
debug-default: default-mode
default-debug: debug-default

debug-parasite: CFLAGS_nat := $(CFLAGS_nat_debug)
debug-parasite: parasite-mode
debug-parasite: parasite-mode
parasite-debug: debug-parasite

debug-efficient: CFLAGS_nat := $(CFLAGS_nat_debug)
debug-efficient: efficient-mode
debug-efficient: efficient-mode
efficient-debug: debug-efficient

debug-lysis: CFLAGS_nat := $(CFLAGS_nat_debug)
debug-lysis: lysis-mode
debug-lysis: lysis-mode
lysis-debug: debug-lysis

debug-pgg: CFLAGS_nat := $(CFLAGS_nat_debug)
debug-pgg: pgg-mode
debug-pgg: pgg-mode
pgg-debug: debug-pgg

debug-sgp: CFLAGS_nat := $(CFLAGS_nat_debug)
debug-sgp: sgp-mode
debug-sgp: sgp-mode
sgp-debug: debug-sgp

debug-web: CFLAGS_web := $(CFLAGS_web_debug)
Expand All @@ -102,7 +103,7 @@ test:
@echo To run only the tests for each mode, use the following:
@echo Default mode testing: make test-default
@echo Efficient mode testing: make test-efficient
@echo Lysis mode testing: make test-lysis
@echo Lysis mode testing: make test-lysis
@echo PGG mode testing: make test-pgg
@echo SGP mode testing: make test-sgp

Expand All @@ -112,7 +113,7 @@ test-debug:
@echo To debug and test for each mode, use the following:
@echo Default mode: make test-debug-default
@echo Efficient mode: make test-debug-efficient
@echo Lysis mode: make test-debug-lysis
@echo Lysis mode: make test-debug-lysis
@echo PGG mode: make test-debug-pgg
@echo SGP mode: make test-debug-sgp

Expand Down Expand Up @@ -146,7 +147,7 @@ test-debug-pgg:

test-sgp:
$(CXX_nat) $(CFLAGS_nat) $(TEST_DIR)/main.cc -o symbulation.test
./symbulation.test [sgp]
./symbulation.test [sgp]
test-debug-sgp:
$(CXX_nat) $(CFLAGS_nat_debug) $(TEST_DIR)/main.cc -o symbulation.test
./symbulation.test [sgp]
Expand Down
2 changes: 1 addition & 1 deletion signalgp-lite
Submodule signalgp-lite updated 104 files
1 change: 1 addition & 0 deletions source/ConfigSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ EMP_BUILD_CONFIG(SymConfigBase,
VALUE(NUM_PHYLO_BINS, size_t, 5, "How many bins should organisms be sepeated into if phylogeny is on?"),
VALUE(NO_MUT_UPDATES, int, 0, "How many updates should be run after the end of UPDATES with all mutation turned off?"),
VALUE(PHAGE_EXCLUDE, bool, 0, "Do symbionts have a decreasing chance of getting into the host the more symbionts are already infecting it? (0 for no, 1 for yes)"), // todo: alias phage_exclude, and change name to sym_exclude
VALUE(OUSTING, bool, 0, "Should ousting (incoming symbiont kills and replaces existing symbiont) be turned on? (0 for no, 1 for yes)"),
VALUE(FILE_PATH, std::string, "", "Output file path"),
VALUE(FILE_NAME, std::string, "_data", "Root output file name"),
VALUE(DOMINANT_COUNT, size_t, 10, "Number of dominant hosts to select"),
Expand Down
23 changes: 18 additions & 5 deletions source/default_mode/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Host: public Organism {

/**
* Input: None
*
*
* Output: Name of class as string, Host
*
* Purpose: To know which subclass the object is
Expand Down Expand Up @@ -439,7 +439,18 @@ class Host: public Organism {
* Purpose: To add a symbionts to a host's symbionts
*/
int AddSymbiont(emp::Ptr<Organism> _in) {
if((int)syms.size() < my_config->SYM_LIMIT() && SymAllowedIn()){
bool allowed_in = SymAllowedIn();
if (my_config->OUSTING() && allowed_in && (int)syms.size() == my_config->SYM_LIMIT()) {
// if there's more than one sym, randomly choose one to replace, otherwise replace the one sym
const int new_sym_pos = (syms.size() > 1) ? random->GetInt(syms.size()) : 0;
emp::Ptr<Organism> old_sym = syms[new_sym_pos];
my_world->SendToGraveyard(old_sym);
syms[new_sym_pos] = _in;
_in->SetHost(this);
_in->UponInjection();
return new_sym_pos+1;
}
else if((int)syms.size() < my_config->SYM_LIMIT() && allowed_in){
syms.push_back(_in);
_in->SetHost(this);
_in->UponInjection();
Expand Down Expand Up @@ -536,7 +547,7 @@ class Host: public Organism {
if (mutation_rate == -1) mutation_rate = my_config->MUTATION_RATE();

if(random->GetDouble(0.0, 1.0) <= mutation_rate){
interaction_val += random->GetRandNormal(0.0, mutation_size);
interaction_val += random->GetNormal(0.0, mutation_size);
if(interaction_val < -1) interaction_val = -1;
else if (interaction_val > 1) interaction_val = 1;
}
Expand Down Expand Up @@ -682,8 +693,10 @@ class Host: public Organism {
if(!curSym->GetDead()){
curSym->Process(sym_pos);
}
if(curSym->GetDead()){
syms.erase(syms.begin() + j); //if the symbiont dies during their process, remove from syms list
if(curSym->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();
}
} //for each sym in syms
Expand Down
47 changes: 41 additions & 6 deletions source/default_mode/SymWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class SymWorld : public emp::World<Organism>{
*/
pop_t sym_pop;

/**
*
* Purpose: Represents the set of organisms which have been unlinked from
* their standard managing structures and need to be deleted at the end
* of every update.
*
*/
emp::vector<emp::Ptr<Organism>> graveyard = {};

/**
*
* Purpose: Represents a standard function object which determines which taxon an organism belongs to.
Expand Down Expand Up @@ -137,7 +146,7 @@ class SymWorld : public emp::World<Organism>{
}

if(my_config->PHYLOGENY()){ //host systematic deletion is handled by empirical world destructor
Clear(); // delete hosts here so that hosted symbionts get
Clear(); // delete hosts here so that hosted symbionts get
// deleted and unlinked from the sym_sys
sym_sys.Delete();
}
Expand All @@ -164,6 +173,14 @@ class SymWorld : public emp::World<Organism>{
*/
emp::World<Organism>::pop_t GetSymPop() {return sym_pop;}

/**
* Input: None
*
* Output: A reference to the world graveyard.
*
* Purpose: To get the world's graveyard.
*/
emp::vector<emp::Ptr<Organism>>& GetGraveyard() { return graveyard; }

/**
* Input: None
Expand Down Expand Up @@ -246,7 +263,7 @@ class SymWorld : public emp::World<Organism>{
* Purpose: To add a symbiont to the systematic and to set it to track its taxon
*/
emp::Ptr<emp::Taxon<int>> AddSymToSystematic(emp::Ptr<Organism> sym, emp::Ptr<emp::Taxon<int>> parent_taxon=nullptr){
emp::Ptr<emp::Taxon<int>> taxon = sym_sys->AddOrg(*sym, emp::WorldPosition(0,0), parent_taxon, GetUpdate());
emp::Ptr<emp::Taxon<int>> taxon = sym_sys->AddOrg(*sym, emp::WorldPosition(0,0), parent_taxon);
sym->SetTaxon(taxon);
return taxon;
}
Expand All @@ -264,7 +281,7 @@ class SymWorld : public emp::World<Organism>{
*/
float PullResources(float desired_resources) {
// if LIMITED_RES_TOTAL == -1, unlimited, even if limited resources was on before
if (total_res == -1 || my_config->LIMITED_RES_TOTAL() == -1) {
if (total_res == -1 || my_config->LIMITED_RES_TOTAL() == -1) {
return desired_resources;
} else {
if (total_res>=desired_resources) {
Expand Down Expand Up @@ -312,6 +329,18 @@ class SymWorld : public emp::World<Organism>{
}


/**
* Input: An organism pointer to add to the graveyard
*
* Output: None
*
* Purpose: To add organisms to the graveyard
*/
virtual void SendToGraveyard(emp::Ptr<Organism> org) {
graveyard.push_back(org);
}


/**
* Input: The pointer to the new organism;
* the world position of the location to add
Expand Down Expand Up @@ -495,7 +524,7 @@ class SymWorld : public emp::World<Organism>{
* Input: The pointer to the symbiont that is moving, the WorldPosition of its
* current location.
*
* Output: The WorldPosition object describing the symbiont's new location (it describes an
* Output: The WorldPosition object describing the symbiont's new location (it describes an
* invalid position if the symbiont is deleted during movement)
*
* Purpose: To move a symbiont into a new world position.
Expand Down Expand Up @@ -640,7 +669,7 @@ class SymWorld : public emp::World<Organism>{
/**
* Input: A size_t location to check in the symbiont population vector.
*
* Output: A boolean representing whether the the position is valid and
* Output: A boolean representing whether the the position is valid and
* occupied by a free living symbiont/
*
* Purpose: To determine if a given index is valid and occipied in the symbiont
Expand Down Expand Up @@ -752,7 +781,7 @@ class SymWorld : public emp::World<Organism>{
if (counts.size() <= result.size()) {
result.resize(counts.size());
}

return result;
}

Expand Down Expand Up @@ -789,6 +818,12 @@ class SymWorld : public emp::World<Organism>{
else sym_pop[i]->Process(sym_pos); //index 0, since it's freeliving, and id its location in the world
}
} // for each cell in schedule

// clean up the graveyard
for (size_t i = 0; i < graveyard.size(); i++) {
graveyard[i].Delete();
}
graveyard.clear();
} // Update()
};// SymWorld class
#endif
8 changes: 4 additions & 4 deletions source/default_mode/Symbiont.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ class Symbiont: public Organism {
* Purpose: To destruct the symbiont and remove the symbiont from the systematic.
*/
~Symbiont() {
if(my_config->PHYLOGENY() == 1) {my_world->GetSymSys()->RemoveOrg(my_taxon, my_world->GetUpdate());}
if(my_config->PHYLOGENY() == 1) {my_world->GetSymSys()->RemoveOrg(my_taxon);}
}

/**
* Input: None
*
*
* Output: Name of class as string, Symbiont
*
* Purpose: To know which subclass the object is
Expand Down Expand Up @@ -396,13 +396,13 @@ class Symbiont: public Organism {
double local_size = my_config->MUTATION_SIZE();

if (random->GetDouble(0.0, 1.0) <= local_rate) {
interaction_val += random->GetRandNormal(0.0, local_size);
interaction_val += random->GetNormal(0.0, local_size);
if(interaction_val < -1) interaction_val = -1;
else if (interaction_val > 1) interaction_val = 1;

//also modify infection chance, which is between 0 and 1
if(my_config->FREE_LIVING_SYMS()){
infection_chance += random->GetRandNormal(0.0, local_size);
infection_chance += random->GetNormal(0.0, local_size);
if (infection_chance < 0) infection_chance = 0;
else if (infection_chance > 1) infection_chance = 1;
}
Expand Down
10 changes: 5 additions & 5 deletions source/efficient_mode/EfficientSymbiont.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class EfficientSymbiont: public Symbiont {

/**
* Input: None
*
*
* Output: Name of class as string, EfficientSymbiont
*
* Purpose: To know which subclass the object is
Expand Down Expand Up @@ -189,19 +189,19 @@ class EfficientSymbiont: public Symbiont {
}

if (random->GetDouble(0.0, 1.0) <= int_rate) {
interaction_val += random->GetRandNormal(0.0, local_size);
interaction_val += random->GetNormal(0.0, local_size);
if(interaction_val < -1) interaction_val = -1;
else if (interaction_val > 1) interaction_val = 1;

//also modify infection chance, which is between 0 and 1
if(efficient_config->FREE_LIVING_SYMS()){
infection_chance += random->GetRandNormal(0.0, local_size);
infection_chance += random->GetNormal(0.0, local_size);
if (infection_chance < 0) infection_chance = 0;
else if (infection_chance > 1) infection_chance = 1;
}
}
if (random->GetDouble(0.0, 1.0) <= eff_mut_rate) {
efficiency += random->GetRandNormal(0.0, local_size);
efficiency += random->GetNormal(0.0, local_size);
if(efficiency < 0) efficiency = 0;
else if (efficiency > 1) efficiency = 1;
}
Expand Down Expand Up @@ -239,7 +239,7 @@ class EfficientSymbiont: public Symbiont {
return sym_baby;
}
#pragma clang diagnostic pop


/**
* Input: The pointer to the organism that is the new host baby
Expand Down
4 changes: 2 additions & 2 deletions source/lysis_mode/Bacterium.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Bacterium : public Host {

/**
* Input: None
*
*
* Output: Name of class as string, Bacterium
*
* Purpose: To know which subclass the object is
Expand Down Expand Up @@ -139,7 +139,7 @@ class Bacterium : public Host {

//mutate host genome if enabled
if(lysis_config->MUTATE_INC_VAL()){
host_incorporation_val += random->GetRandNormal(0.0, lysis_config->MUTATION_SIZE());
host_incorporation_val += random->GetNormal(0.0, lysis_config->MUTATION_SIZE());

if(host_incorporation_val < 0) host_incorporation_val = 0;

Expand Down
Loading

0 comments on commit 027c516

Please sign in to comment.