Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
45b474c
Added Steal and Donate Health host with config
EliasH-E Jul 1, 2025
7d355b9
Made fixes and improvements to donate and steal
EliasH-E Jul 1, 2025
9287092
Made fixes to tests and folded ONLYNOT test into SGPWorld.test.cc sin…
EliasH-E Jul 2, 2025
ffca7fe
Added functionality for instructions for stealing and donating to Hea…
EliasH-E Jul 7, 2025
f0e9611
Added Tests for steal/donate instructions
EliasH-E Jul 7, 2025
875f175
Added variable starting steal count, tied for now to CPU_TRANSFER_AMOUNT
EliasH-E Jul 8, 2025
25d5ab6
Made changes based on feedback, removed trash lines and cleaned up co…
EliasH-E Jul 9, 2025
d396fe5
Merged self
EliasH-E Jul 10, 2025
a75fbd7
Finished merge
EliasH-E Jul 10, 2025
0207c43
Really finished merge
EliasH-E Jul 10, 2025
b9ce91a
final merge fix
EliasH-E Jul 10, 2025
5866e06
Merged
EliasH-E Jul 10, 2025
2d3016c
merged
EliasH-E Jul 10, 2025
ac4d00f
Merge branch 'complex-syms-clean' of https://github.com/EliasH-E/Symb…
EliasH-E Jul 10, 2025
0d88a66
Fixed merge again
EliasH-E Jul 10, 2025
3512963
Merge branch 'anyaevostinar:complex-syms-clean' into complex-syms-clean
EliasH-E Jul 10, 2025
0860e0c
Merge branch 'complex-syms-clean' into steal_instructions
EliasH-E Jul 10, 2025
15894f6
Merge branch 'complex-syms-clean' into steal_instructions
anyaevostinar Jul 10, 2025
32c9f06
Fixed last merge problems
EliasH-E Jul 10, 2025
7ab4e6a
Merge branch 'steal_instructions' of https://github.com/EliasH-E/Symb…
EliasH-E Jul 10, 2025
e66d0a8
Made fix to CreateStartProgram and added some documentation
EliasH-E Jul 10, 2025
d3c2e8d
Made fixes to no longer crash on test build
EliasH-E Jul 10, 2025
1378b45
fixed merge tests
EliasH-E Jul 10, 2025
11a136b
Made changes based on feedback and removed new test prints
EliasH-E Jul 10, 2025
f20940d
Added free bonus updates to syms, moved where steal success is decide…
EliasH-E Jul 11, 2025
7917475
Fixed errors in sgp mode test
EliasH-E Jul 14, 2025
85a08e2
Edited steal Health to better match original
EliasH-E Jul 14, 2025
dde32b3
Merge branch 'complex-syms-clean' into steal_instructions
anyaevostinar Jul 15, 2025
3f34c3e
Added spread out steals, fixed tests and more
EliasH-E Jul 15, 2025
939728e
Merge branch 'steal_instructions' of https://github.com/EliasH-E/Symb…
EliasH-E Jul 15, 2025
89e40ec
merged
EliasH-E Jul 16, 2025
fc77eb4
Fixed Memory Leak
EliasH-E Jul 16, 2025
cd8341a
Merge branch 'anyaevostinar:complex-syms-clean' into complex-syms-clean
EliasH-E Jul 16, 2025
4fb08ed
Fixed donate tracking
EliasH-E Jul 17, 2025
b776b68
merged
EliasH-E Jul 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion source/Organism.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Organism {
std::cout << "MakeNew called from Organism" << std::endl;
throw "Organism method called!";
}


//Symbiont functions

Expand Down Expand Up @@ -176,7 +177,14 @@ class Organism {
virtual void ClearReproSyms() {
std::cout << "ClearReproSyms called from Organism" << std::endl;
throw "Organism method called!";}

virtual void CycleTransfer(int _in){
std::cout << "CycleTransfer called from Organism" << std::endl;
throw "Organism method called!";
}
virtual int GetCyclesGiven(){
std::cout << "GetCyclesGiven called from Organism" << std::endl;
throw "Organism method called!";
}
//Bacterium functions
virtual double ProcessLysogenResources(double phage_inc_val){
std::cout << "ProcessLysogenResources called from Organism" << std::endl;
Expand Down
73 changes: 67 additions & 6 deletions source/sgp_mode/GenomeLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,32 @@ class ProgramBuilder : emp::vector<sgpl::Instruction<Spec>> {
Add("Nand", 0, 0, 0);
Add("SharedIO");
}

void AddStartSteal(int steal_count){

for (int i = 0; i < steal_count; i++){
Add("Steal");

Add("Steal");
Add("Steal");
Add("Steal");

}
Add("Steal");
}

void AddStartDonate(int donate_count){

for (int i = 0; i < donate_count; i++){
Add("Donate");

Add("Donate");
Add("Donate");
Add("Donate");

}
Add("Donate");
}
};

sgpl::Program<Spec> CreateReproProgram(size_t length) {
Expand All @@ -269,22 +295,57 @@ sgpl::Program<Spec> CreateNotProgram(size_t length) {
return program.Build(length);
}

sgpl::Program<Spec> CreateMutualistStart(size_t length) {
sgpl::Program<Spec> CreateParasiteNotProgram(size_t length, int steal_count) {
ProgramBuilder program;
program.AddNand();
return program.BuildNoRepro(length);
program.Add("Steal");
program.Add("Steal");
program.AddStartSteal(steal_count);
program.AddNot();

return program.Build(length);
}

sgpl::Program<Spec> CreateMutualistNotProgram(size_t length, int donate_count) {
ProgramBuilder program;

program.Add("Donate");
program.Add("Donate");
program.AddStartDonate(donate_count);
program.AddNot();
return program.Build(length);
}

sgpl::Program<Spec> CreateEquProgram(size_t length) {
ProgramBuilder program;
program.AddEqu();
return program.Build(length);
}


/**
* Picks what type of starting program should be created based on the config and
* creates it.
*/
sgpl::Program<Spec> CreateStartProgram(emp::Ptr<SymConfigSGP> config) {
if (config->TASK_TYPE() == 1) {
return CreateNotProgram(PROGRAM_LENGTH);
} else {
return CreateReproProgram(PROGRAM_LENGTH);
if(config->DONATION_STEAL_INST() == 1){
if(config->STRESS_TYPE() == 1){
return CreateParasiteNotProgram(PROGRAM_LENGTH, config->CPU_TRANSFER_AMOUNT());
}
else if(config->STRESS_TYPE() == 0){
return CreateMutualistNotProgram(PROGRAM_LENGTH, config->CPU_TRANSFER_AMOUNT());
}
else{
return CreateNotProgram(PROGRAM_LENGTH);
}
}
else{
return CreateNotProgram(PROGRAM_LENGTH);
}

}
return CreateReproProgram(PROGRAM_LENGTH);

}

#endif
82 changes: 79 additions & 3 deletions source/sgp_mode/HealthHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ class HealthHost : public SGPHost {

public:

//Tracks whether an update needs to be given to a symbiont or recieved from a symbiont
Comment thread
EliasH-E marked this conversation as resolved.
Outdated
int cycles_given = 0;
Comment thread
EliasH-E marked this conversation as resolved.
Outdated

//Test variables that are currently used to give symbionts some starting cycles and then give them scraps throughout
//the rest of their updates.
int honoray_cycles = 0;
int starting_updates = 10;
emp::Ptr<Organism> last_sym = NULL;
/**
* Constructs a new SGPHost as an ancestor organism, with either a random
* genome or a blank genome that knows how to do a simple task depending on
Expand Down Expand Up @@ -43,7 +51,19 @@ class HealthHost : public SGPHost {
random, GetWorld(), sgp_config, GetCPU().GetProgram(), GetIntVal());
return host_baby;
}

void CycleTransfer(int amount) override {
if(random->P(sgp_config->CPU_TRANSFER_CHANCE())){
cycles_given += amount;
}
}

int GetCyclesGiven(){
return cycles_given;
}

std::string const GetName() override{
return "HealthHost";
}
/**
* Input: The location of the host.
*
Expand All @@ -62,9 +82,57 @@ class HealthHost : public SGPHost {
int host_cycle = 1;
int sym_cycle = 0;
if (HasSym()) {
if (sgp_config->STRESS_TYPE() == MUTUALIST) {

if(sgp_config->DONATION_STEAL_INST()){


if(cycles_given >= 1){

host_cycle += 1;
sym_cycle -= 1;

cycles_given = 0;
}
if(cycles_given <= -1){

host_cycle = 0;
sym_cycle += 1;

cycles_given = 0;

}

//This sequence checks if the symbiont will recieve a cycle, if it has not then it checks if

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"receive"

//one of its bonus updates is left, if so it uses one, if not it ticks up the counter
//for when it recieves said bonus update.
//Allows for symbiont to reach steals but to still need them

if(sym_cycle == 0 && sgp_config->DONATION_STEAL_INST()){
//Will delete later
// emp::vector<emp::Ptr<Organism>> &syms = GetSymbionts();
// emp::Ptr<Organism> curSym = syms[0];
// if(last_sym != curSym){
// last_sym = curSym;
// starting_updates = sgp_config->STARTING_BONUS();
// }

if(starting_updates > 0){
sym_cycle += 1;
starting_updates -= 1;
}

}
if(starting_updates < 1){
honoray_cycles += 1;
if(honoray_cycles == sgp_config->BONUS_UPDATE_WAIT()){
starting_updates += 1;
honoray_cycles = 0;
}
}
}
Comment thread
EliasH-E marked this conversation as resolved.
else{
if (sgp_config->STRESS_TYPE() == MUTUALIST) {
//Host with mutualist gains 50% of CPU from mutualist

if (random->P(sgp_config->CPU_TRANSFER_CHANCE())) {
host_cycle = 2;
sym_cycle = 0;
Expand All @@ -83,8 +151,13 @@ class HealthHost : public SGPHost {
sym_cycle = 0;
}
}
}


}



//Loops running CPU steps
for(int i = 0; i < host_cycle; i++){
GetCPU().RunCPUStep(pos, sgp_config->CYCLES_PER_UPDATE());
Expand Down Expand Up @@ -116,5 +189,8 @@ class HealthHost : public SGPHost {
}
GrowOlder();
}

};

Comment thread
EliasH-E marked this conversation as resolved.

#endif // HEALTHHOST_H
53 changes: 26 additions & 27 deletions source/sgp_mode/Instructions.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#ifndef INSTRUCTIONS_H
#define INSTRUCTIONS_H


#include "CPUState.h"
#include "SGPWorld.h"
#include "Tasks.h"


#include "sgpl/hardware/Cpu.hpp"
#include "sgpl/operations/flow_global/Anchor.hpp"
#include "sgpl/program/Program.hpp"
Expand Down Expand Up @@ -113,42 +116,38 @@ INST(SharedIO, {
*a = next;
state.input_buf.push(next);
});

INST(Donate, {
if (state.world->GetConfig()->DONATION_STEAL_INST()) {
if (state.organism->IsHost() || state.organism->GetHost() == nullptr)
if (state.world->GetConfig()->DONATION_STEAL_INST() && (state.world->GetConfig()->STRESS_TYPE() == 0 || state.world->GetConfig()->ALLOW_TRANSITION_EVOLUTION() == 1)) {
if (state.organism->IsHost()){
return;
if (emp::Ptr<Organism> host = state.organism->GetHost()) {
// Donate 20% of the total points of the symbiont-host system
// This way, a sym can donate e.g. 40 or 60 percent of their points in a
// couple of instructions
double to_donate =
fmin(state.organism->GetPoints(),
(state.organism->GetPoints() + host->GetPoints()) * 0.20);
state.world->GetSymDonatedDataNode().WithMonitor(
[=](auto &m) { m.AddDatum(to_donate); });
host->AddPoints(to_donate);
state.organism->AddPoints(-to_donate);
}
emp::Ptr<Organism> host = state.organism->GetHost();
if(host->GetCyclesGiven() <= 0){
host->CycleTransfer(1);
state.world->GetDonateCount().WithMonitor(
[=](auto &m) { m.AddDatum(1); });
}


}

});
INST(Steal, {
if (state.world->GetConfig()->DONATION_STEAL_INST()) {
if (state.organism->IsHost() || state.organism->GetHost() == nullptr)
if (state.world->GetConfig()->DONATION_STEAL_INST() && (state.world->GetConfig()->STRESS_TYPE() == 1 || state.world->GetConfig()->ALLOW_TRANSITION_EVOLUTION() == 1)) {
if (state.organism->IsHost()){
return;
if (emp::Ptr<Organism> host = state.organism->GetHost()) {
// Steal 20% of the total points of the symbiont-host system
// This way, a sym can steal e.g. 40 or 60 percent of the host's points in
// a couple of instructions
double to_steal =
fmin(host->GetPoints(),
(state.organism->GetPoints() + host->GetPoints()) * 0.20);
state.world->GetSymStolenDataNode().WithMonitor(
[=](auto &m) { m.AddDatum(to_steal); });
host->AddPoints(-to_steal);
state.organism->AddPoints(to_steal);
}
emp::Ptr<Organism> host = state.organism->GetHost();
if(host->GetCyclesGiven() >= 0){
host->CycleTransfer(-1);
state.world->GetStealCount().WithMonitor(
[=](auto &m) { m.AddDatum(1); });
}
}

}
});
);

} // namespace inst

Expand Down
7 changes: 5 additions & 2 deletions source/sgp_mode/SGPConfigSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ EMP_EXTEND_CONFIG(SymConfigSGP, SymConfigBase,
VALUE(MUTUALIST_DEATH_CHANCE, double, 0.125, "What death chance does a mutualist confer?"),
VALUE(BASE_DEATH_CHANCE, double, 0.25, "What death chance does a host have in the absence of symbionts?"),
VALUE(CPU_TRANSFER_CHANCE, double, 0.5, "What is the chance for cycles to be stolen/donated?"),
VALUE(ONLY_FIRST_TASK_CREDIT, int, 0, "Should symbionts only get credit for their first task")

VALUE(CPU_TRANSFER_AMOUNT, double, 1, "How many updates should be stolen/donated by instruction based symbionts"),
VALUE(ONLY_FIRST_TASK_CREDIT, int, 0, "Should organisms only get credit for their first task"),
VALUE(ALLOW_TRANSITION_EVOLUTION, int, 0, "Should symbionts be allowed to evolve from mutualists to parasties and vice versa"),
VALUE(BONUS_UPDATE_WAIT, int, 40, "If DONATION_STEAL_INST is 1 how many updates till a symbiont recieves a free extra update"),
Comment thread
EliasH-E marked this conversation as resolved.
Outdated
VALUE(STARTING_BONUS, int, 10, "How many bonus updates do symbionts start with")
Comment thread
EliasH-E marked this conversation as resolved.
Outdated
)

#endif
32 changes: 32 additions & 0 deletions source/sgp_mode/SGPDataNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ void SGPWorld::CreateDataFiles() {
SetupTasksFile(sgp_config->FILE_PATH() + "Tasks" + sgp_config->FILE_NAME() +
file_ending)
.SetTimingRepeat(sgp_config->DATA_INT());
SetupSymInstFile(sgp_config->FILE_PATH() + "SymInstCount" +
sgp_config->FILE_NAME() + file_ending)
.SetTimingRepeat(sgp_config->DATA_INT());
}


Expand Down Expand Up @@ -99,6 +102,21 @@ emp::DataFile &SGPWorld::SetupSymDonatedFile(const std::string &filename) {
return file;
}

emp::DataFile &SGPWorld::SetupSymInstFile(const std::string &filename) {
auto &file = SetupFile(filename);
file.AddVar(update, "update", "Update");
GetStealCount();
file.AddTotal(data_node_steal_count->UnsynchronizedGetMonitor(),
"sym_steal_ran", "Amount of times steal instructions were ran", true);

GetDonateCount();
file.AddTotal(data_node_steal_count->UnsynchronizedGetMonitor(),
"sym_donate_ran", "Amount of times donate instructions were ran", true);

file.PrintHeaderKeys();
return file;
}

/**
* Input: The address of the string representing the file to be
* created's name
Expand Down Expand Up @@ -263,4 +281,18 @@ SyncDataMonitor<double> &SGPWorld::GetSymStolenDataNode() {
return *data_node_sym_stolen;
}

SyncDataMonitor<int> &SGPWorld::GetStealCount() {
if (!data_node_steal_count) {
data_node_steal_count.New();
}
return *data_node_steal_count;
}

SyncDataMonitor<int> &SGPWorld::GetDonateCount() {
if (!data_node_donate_count) {
data_node_donate_count.New();
}
return *data_node_donate_count;
}

#endif
Loading