Skip to content

Commit 1085fcf

Browse files
committed
allowing nutrient mode to skip task check during horizontal transmission and cleaning up warnings
1 parent c41c7f3 commit 1085fcf

6 files changed

Lines changed: 150 additions & 29 deletions

File tree

source/sgp_mode/HealthHost.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class HealthHost : public SGPHost {
7272
*
7373
* Purpose: For symbionts to check if their host already owes cycles.
7474
*/
75-
int GetCyclesGiven(){
75+
int GetCyclesGiven() override {
7676
return cycles_given;
7777
}
7878

source/sgp_mode/SGPHost.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ class SGPHost : public Host {
9292
return "SGPHost";
9393
}
9494

95-
bool operator<(const Organism &other) const {
95+
bool operator<(const Organism &other) const override {
9696
if (const SGPHost *sgp = dynamic_cast<const SGPHost *>(&other)) {
9797
return cpu.GetProgram() < sgp->cpu.GetProgram();
9898
} else {
9999
return false;
100100
}
101101
}
102102

103-
bool operator==(const Organism &other) const {
103+
bool operator==(const Organism &other) const override {
104104
if (const SGPHost *sgp = dynamic_cast<const SGPHost *>(&other)) {
105105
return cpu.GetProgram() == sgp->cpu.GetProgram();
106106
} else {
@@ -153,7 +153,7 @@ class SGPHost : public Host {
153153
* include reproduction and acquisition of resources; removing dead syms; and
154154
* processing alive syms.
155155
*/
156-
void Process(emp::WorldPosition pos) {
156+
void Process(emp::WorldPosition pos) override {
157157
//if (my_world->GetUpdate() % my_config->LIMITED_TASK_RESET_INTERVAL() == 0)
158158
//cpu.state.used_resources->reset();
159159
// Instead of calling Host::Process, do the important stuff here
@@ -191,7 +191,7 @@ class SGPHost : public Host {
191191
}
192192

193193
// Prototype for this host's reproduce method
194-
emp::Ptr<Organism> Reproduce();
194+
emp::Ptr<Organism> Reproduce() override;
195195

196196
/**
197197
* Input: None.
@@ -200,7 +200,7 @@ class SGPHost : public Host {
200200
*
201201
* Purpose: To avoid creating an organism via constructor in other methods.
202202
*/
203-
emp::Ptr<Organism> MakeNew() {
203+
emp::Ptr<Organism> MakeNew() override {
204204
emp::Ptr<SGPHost> host_baby = emp::NewPtr<SGPHost>(
205205
random, my_world, sgp_config, cpu.GetProgram(), GetIntVal());
206206

@@ -214,7 +214,7 @@ class SGPHost : public Host {
214214
*
215215
* Purpose: To mutate the code in the genome of this host.
216216
*/
217-
void Mutate() {
217+
void Mutate() override {
218218
Host::Mutate();
219219

220220
cpu.Mutate();

source/sgp_mode/SGPWorldSetup.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ int SGPWorld::GetNeighborHost (size_t id, emp::Ptr<Organism> symbiont){
100100
* Output: Whether host and symbiont parent are able to accomplish
101101
* at least one task in common
102102
*
103-
* Purpose: To check for task matching before vertical transmission
103+
* Purpose: To check for task matching before transmission
104104
*/
105105
bool SGPWorld::TaskMatchCheck(emp::Ptr<Organism> sym_parent, emp::Ptr<Organism> host_parent) {
106106

107+
if(sgp_config->INTERACTION_MECHANISM() == NUTRIENT) {
108+
return true;
109+
}
110+
107111
emp::Ptr<emp::BitSet<CPU_BITSET_LENGTH>> parent_tasks;
108112
emp::Ptr<emp::BitSet<CPU_BITSET_LENGTH>> host_tasks;
109113

source/test/sgp_mode_test/HealthHost.test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ TEST_CASE("Health host with symbiont loses/gains cycle 50% of time", "[sgp]") {
2929

3030
config.OUSTING(1);
3131

32-
size_t world_size = config.GRID_X() * config.GRID_Y();
3332
SGPWorld world(random, &config, LogicTasks);
3433

3534
emp::Ptr<HealthHost> host = emp::NewPtr<HealthHost>(&random, &world, &config, CreateNotProgram(100));

source/test/sgp_mode_test/SGPWorld.test.cc

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,124 @@ TEST_CASE("Host Setup", "[sgp]") {
134134
}
135135

136136

137+
TEST_CASE("TaskMaskCheck Unit Test", "[sgp]") {
138+
139+
emp::Random random(1);
140+
SymConfigSGP config;
141+
config.SEED(2);
142+
143+
144+
SGPWorld world(random, &config, LogicTasks);
145+
ProgramBuilder program;
146+
147+
GIVEN("A world in nutrient mode") {
148+
config.INTERACTION_MECHANISM(NUTRIENT);
149+
150+
WHEN("Host and symbiont do different tasks") {
151+
//Creates a host that is marked as having done NOT
152+
emp::Ptr<SGPHost> host = emp::NewPtr<SGPHost>(&random, &world, &config, program.Build(100));
153+
host->GetCPU().state.tasks_performed->Set(1);
154+
155+
//Creates a symbiont that is marked as having done NAND
156+
emp::Ptr<SGPSymbiont> sym = emp::NewPtr<SGPSymbiont>(&random, &world, &config, program.Build(100));
157+
sym->GetCPU().state.tasks_performed->Set(2);
158+
159+
THEN("TaskMatchCheck returns true") {
160+
REQUIRE(world.TaskMatchCheck(sym, host));
161+
}
162+
}
163+
164+
WHEN("Host and symbiont do the same task") {
165+
//Creates a host that is marked as having done NOT
166+
emp::Ptr<SGPHost> host = emp::NewPtr<SGPHost>(&random, &world, &config, program.Build(100));
167+
host->GetCPU().state.tasks_performed->Set(1);
168+
169+
//Creates a symbiont that is marked as having done NOT
170+
emp::Ptr<SGPSymbiont> sym = emp::NewPtr<SGPSymbiont>(&random, &world, &config, program.Build(100));
171+
sym->GetCPU().state.tasks_performed->Set(1);
172+
173+
THEN("TaskMatchCheck returns true") {
174+
REQUIRE(world.TaskMatchCheck(sym, host));
175+
}
176+
}
177+
178+
179+
}
180+
181+
GIVEN("A world in health mode") {
182+
config.INTERACTION_MECHANISM(HEALTH);
183+
184+
WHEN("Host and symbiont do different tasks") {
185+
//Creates a host that is marked as having done NOT
186+
emp::Ptr<HealthHost> host = emp::NewPtr<HealthHost>(&random, &world, &config, program.Build(100));
187+
host->GetCPU().state.tasks_performed->Set(1);
188+
189+
//Creates a symbiont that is marked as having done NAND
190+
emp::Ptr<SGPSymbiont> sym = emp::NewPtr<SGPSymbiont>(&random, &world, &config, program.Build(100));
191+
sym->GetCPU().state.tasks_performed->Set(2);
192+
193+
THEN("TaskMatchCheck returns false") {
194+
REQUIRE(!world.TaskMatchCheck(sym, host));
195+
}
196+
}
197+
198+
WHEN("Host and symbiont do the same task") {
199+
//Creates a host that is marked as having done NOT
200+
emp::Ptr<HealthHost> host = emp::NewPtr<HealthHost>(&random, &world, &config, program.Build(100));
201+
host->GetCPU().state.tasks_performed->Set(1);
202+
203+
//Creates a symbiont that is marked as having done NOT
204+
emp::Ptr<SGPSymbiont> sym = emp::NewPtr<SGPSymbiont>(&random, &world, &config, program.Build(100));
205+
sym->GetCPU().state.tasks_performed->Set(1);
206+
207+
THEN("TaskMatchCheck returns true") {
208+
REQUIRE(world.TaskMatchCheck(sym, host));
209+
}
210+
}
211+
212+
213+
}
214+
215+
GIVEN("A world in stress mode") {
216+
config.INTERACTION_MECHANISM(STRESS);
217+
218+
WHEN("Host and symbiont do different tasks") {
219+
//Creates a host that is marked as having done NOT
220+
ProgramBuilder program;
221+
emp::Ptr<StressHost> host = emp::NewPtr<StressHost>(&random, &world, &config, program.Build(100));
222+
host->GetCPU().state.tasks_performed->Set(1);
223+
224+
//Creates a symbiont that is marked as having done NAND
225+
emp::Ptr<SGPSymbiont> sym = emp::NewPtr<SGPSymbiont>(&random, &world, &config, program.Build(100));
226+
sym->GetCPU().state.tasks_performed->Set(2);
227+
228+
THEN("TaskMatchCheck returns false") {
229+
REQUIRE(!world.TaskMatchCheck(sym, host));
230+
}
231+
}
232+
233+
WHEN("Host and symbiont do the same task") {
234+
//Creates a host that is marked as having done NOT
235+
ProgramBuilder program;
236+
emp::Ptr<StressHost> host = emp::NewPtr<StressHost>(&random, &world, &config, program.Build(100));
237+
host->GetCPU().state.tasks_performed->Set(1);
238+
239+
//Creates a symbiont that is marked as having done NOT
240+
emp::Ptr<SGPSymbiont> sym = emp::NewPtr<SGPSymbiont>(&random, &world, &config, program.Build(100));
241+
sym->GetCPU().state.tasks_performed->Set(1);
242+
243+
244+
THEN("TaskMatchCheck returns true") {
245+
REQUIRE(world.TaskMatchCheck(sym, host));
246+
}
247+
}
248+
249+
250+
}
251+
252+
253+
}
254+
137255
TEST_CASE("TaskMatchCheck for parents", "[sgp]") {
138256

139257
GIVEN("An SGPWorld with no mutation"){
@@ -281,7 +399,7 @@ TEST_CASE("Organisms, without mutation will only receive credit for NOT operatio
281399
cpu.RunCPUStep(0, 100);
282400

283401
//The result of a AND bitwise operations when one of the inputs, in binary, is all ones will be the other input
284-
int all_ones_binary = 4294967295;
402+
long all_ones_binary = 4294967295;
285403
cpu.state.input_buf.push(all_ones_binary);
286404
cpu.RunCPUStep(0, 100);
287405
world.Update();

source/test/sgp_mode_test/Tasks.test.cc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ TEST_CASE("ProcessOutput Functionality", "[proc]"){
256256

257257
WHEN("ProcessOutput is run on an organism with those inputs, The NOT of the first input, and ONLY_FIRST_TASK_CREDIT is 0"){
258258
//The result of applying the NOT bitwise opeartions to the binary form of 734856699
259-
int not_output = 3560110596;
259+
long not_output = 3560110596;
260260

261261
host->GetCPU().state.world->GetTaskSet().ProcessOutput(host->GetCPU().state,not_output,0);
262262
THEN("Organism should have 5 points"){
@@ -290,7 +290,7 @@ TEST_CASE("ProcessOutput Functionality", "[proc]"){
290290

291291
WHEN("ProcessOutput is run on an organism with those inputs, The NAND of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
292292
//The result of applying the NAND bitwise opeartions to the binary form of 734856699 and 1177728054
293-
int nand_output = 4261411789;
293+
long nand_output = 4261411789;
294294
host->GetCPU().state.world->GetTaskSet().ProcessOutput(host->GetCPU().state,nand_output,0);
295295
THEN("Organism should have 5 points"){
296296
REQUIRE(host->GetPoints() == 5);
@@ -320,7 +320,7 @@ TEST_CASE("ProcessOutput Functionality", "[proc]"){
320320

321321
WHEN("ProcessOutput is run on an organism with those inputs, The AND of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
322322
//The result of applying the AND bitwise opeartions to the binary form of 734856699 and 1177728054
323-
int and_output = 33555506;
323+
long and_output = 33555506;
324324
host->GetCPU().state.world->GetTaskSet().ProcessOutput(host->GetCPU().state,and_output,0);
325325
THEN("Organism should have 5 points"){
326326
REQUIRE(host->GetPoints() == 5);
@@ -350,7 +350,7 @@ TEST_CASE("ProcessOutput Functionality", "[proc]"){
350350

351351
WHEN("ProcessOutput is run on an organism with those inputs, The ORN of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
352352
//The result of applying the ORN bitwise opeartions to the binary form of 734856699 and 1177728054
353-
int orn_output = 3150794747;
353+
long orn_output = 3150794747;
354354
host->GetCPU().state.world->GetTaskSet().ProcessOutput(host->GetCPU().state,orn_output,0);
355355
THEN("Organism should have 5 points"){
356356
REQUIRE(host->GetPoints() == 5);
@@ -380,7 +380,7 @@ TEST_CASE("ProcessOutput Functionality", "[proc]"){
380380

381381
WHEN("ProcessOutput is run on an organism with those inputs, The OR of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
382382
//The result of applying the OR bitwise opeartions to the binary form of 734856699 and 1177728054
383-
int or_output = 1879029247;
383+
long or_output = 1879029247;
384384
host->GetCPU().state.world->GetTaskSet().ProcessOutput(host->GetCPU().state,or_output,0);
385385
THEN("Organism should have 5 points"){
386386
REQUIRE(host->GetPoints() == 5);
@@ -410,7 +410,7 @@ TEST_CASE("ProcessOutput Functionality", "[proc]"){
410410

411411
WHEN("ProcessOutput is run on an organism with those inputs, The ANDN of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
412412
//The result of applying the ANDN bitwise opeartions to the binary form of 734856699 and 1177728054
413-
int andn_output = 701301193;
413+
long andn_output = 701301193;
414414
host->GetCPU().state.world->GetTaskSet().ProcessOutput(host->GetCPU().state,andn_output,0);
415415
THEN("Organism should have 5 points"){
416416
REQUIRE(host->GetPoints() == 5);
@@ -440,7 +440,7 @@ TEST_CASE("ProcessOutput Functionality", "[proc]"){
440440

441441
WHEN("ProcessOutput is run on an organism with those inputs, The NOR of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
442442
//The result of applying the NOR bitwise opeartions to the binary form of 734856699 and 1177728054
443-
int nor_output = 2415938048;
443+
long nor_output = 2415938048;
444444
host->GetCPU().state.world->GetTaskSet().ProcessOutput(host->GetCPU().state,nor_output,0);
445445
THEN("Organism should have 5 points"){
446446
REQUIRE(host->GetPoints() == 5);
@@ -470,7 +470,7 @@ TEST_CASE("ProcessOutput Functionality", "[proc]"){
470470

471471
WHEN("ProcessOutput is run on an organism with those inputs, The XOR of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
472472
//The result of applying the XOR bitwise opeartions to the binary form of 734856699 and 1177728054
473-
int xor_output = 1845473741;
473+
long xor_output = 1845473741;
474474
host->GetCPU().state.world->GetTaskSet().ProcessOutput(host->GetCPU().state,xor_output,0);
475475
THEN("Organism should have 5 points"){
476476
REQUIRE(host->GetPoints() == 5);
@@ -500,7 +500,7 @@ TEST_CASE("ProcessOutput Functionality", "[proc]"){
500500

501501
WHEN("ProcessOutput is run on an organism with those inputs, The EQU of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
502502
//The result of applying the EQU bitwise opeartions to the binary form of 734856699 and 1177728054
503-
int equ_output = 2449493554;
503+
long equ_output = 2449493554;
504504
host->GetCPU().state.world->GetTaskSet().ProcessOutput(host->GetCPU().state,equ_output,0);
505505
THEN("Organism should have 5 points"){
506506
REQUIRE(host->GetPoints() == 5);
@@ -531,7 +531,7 @@ TEST_CASE("ProcessOutput Functionality", "[proc]"){
531531
}
532532

533533
TEST_CASE("WhichTaskDone Functionality", "[sgp]"){
534-
emp::Random random(1);
534+
emp::Random random(1);
535535
SymConfigSGP config;
536536
config.SEED(1);
537537
config.MUTATION_RATE(0.0);
@@ -556,7 +556,7 @@ TEST_CASE("WhichTaskDone Functionality", "[sgp]"){
556556

557557
WHEN("WhichTaskDone is run on an organism with those inputs, The NOT of the first input, and ONLY_FIRST_TASK_CREDIT is 0"){
558558
//The result of applying the NOT bitwise opeartions to the binary form of 734856699
559-
int not_output = 3560110596;
559+
long not_output = 3560110596;
560560
THEN("WhichTaskDone should return a 0"){
561561
int task_id = host->GetCPU().state.world->GetTaskSet().WhichTaskDone(host->GetCPU().state,not_output,0);
562562
REQUIRE(task_id == 0);
@@ -565,7 +565,7 @@ TEST_CASE("WhichTaskDone Functionality", "[sgp]"){
565565

566566
WHEN("WhichTaskDone is run on an organism with those inputs, The NAND of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
567567
//The result of applying the NAND bitwise opeartions to the binary form of 734856699 and 1177728054
568-
int nand_output = 4261411789;
568+
long nand_output = 4261411789;
569569
THEN("WhichTaskDone should return a 1"){
570570
int task_id = host->GetCPU().state.world->GetTaskSet().WhichTaskDone(host->GetCPU().state,nand_output,0);
571571
REQUIRE(task_id == 1);
@@ -574,7 +574,7 @@ TEST_CASE("WhichTaskDone Functionality", "[sgp]"){
574574

575575
WHEN("WhichTaskDone is run on an organism with those inputs, The AND of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
576576
//The result of applying the AND bitwise opeartions to the binary form of 734856699 and 1177728054
577-
int and_output = 33555506;
577+
long and_output = 33555506;
578578
THEN("WhichTaskDone should return a 2"){
579579
int task_id = host->GetCPU().state.world->GetTaskSet().WhichTaskDone(host->GetCPU().state,and_output,0);
580580
REQUIRE(task_id == 2);
@@ -583,7 +583,7 @@ TEST_CASE("WhichTaskDone Functionality", "[sgp]"){
583583

584584
WHEN("WhichTaskDone is run on an organism with those inputs, The ORN of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
585585
//The result of applying the ORN bitwise opeartions to the binary form of 734856699 and 1177728054
586-
int orn_output = 3150794747;
586+
long orn_output = 3150794747;
587587
THEN("WhichTaskDone should return a 3"){
588588
int task_id = host->GetCPU().state.world->GetTaskSet().WhichTaskDone(host->GetCPU().state,orn_output,0);
589589
REQUIRE(task_id == 3);
@@ -592,7 +592,7 @@ TEST_CASE("WhichTaskDone Functionality", "[sgp]"){
592592

593593
WHEN("WhichTaskDone is run on an organism with those inputs, The OR of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
594594
//The result of applying the OR bitwise opeartions to the binary form of 734856699 and 1177728054
595-
int or_output = 1879029247;
595+
long or_output = 1879029247;
596596
THEN("WhichTaskDone should return a 4"){
597597
int task_id = host->GetCPU().state.world->GetTaskSet().WhichTaskDone(host->GetCPU().state,or_output,0);
598598
REQUIRE(task_id == 4);
@@ -601,7 +601,7 @@ TEST_CASE("WhichTaskDone Functionality", "[sgp]"){
601601

602602
WHEN("WhichTaskDone is run on an organism with those inputs, The ANDN of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
603603
//The result of applying the ANDN bitwise opeartions to the binary form of 734856699 and 1177728054
604-
int andn_output = 701301193;
604+
long andn_output = 701301193;
605605
THEN("WhichTaskDone should return a 5"){
606606
int task_id = host->GetCPU().state.world->GetTaskSet().WhichTaskDone(host->GetCPU().state,andn_output,0);
607607
REQUIRE(task_id == 5);
@@ -610,7 +610,7 @@ TEST_CASE("WhichTaskDone Functionality", "[sgp]"){
610610

611611
WHEN("WhichTaskDone is run on an organism with those inputs, The NOR of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
612612
//The result of applying the NOR bitwise opeartions to the binary form of 734856699 and 1177728054
613-
int nor_output = 2415938048;
613+
long nor_output = 2415938048;
614614
THEN("WhichTaskDone should return a 6"){
615615
int task_id = host->GetCPU().state.world->GetTaskSet().WhichTaskDone(host->GetCPU().state,nor_output,0);
616616
REQUIRE(task_id == 6);
@@ -619,7 +619,7 @@ TEST_CASE("WhichTaskDone Functionality", "[sgp]"){
619619

620620
WHEN("WhichTaskDone is run on an organism with those inputs, The XOR of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
621621
//The result of applying the XOR bitwise opeartions to the binary form of 734856699 and 1177728054
622-
int xor_output = 1845473741;
622+
long xor_output = 1845473741;
623623
THEN("WhichTaskDone should return a 7"){
624624
int task_id = host->GetCPU().state.world->GetTaskSet().WhichTaskDone(host->GetCPU().state,xor_output,0);
625625
REQUIRE(task_id == 7);
@@ -628,7 +628,7 @@ TEST_CASE("WhichTaskDone Functionality", "[sgp]"){
628628

629629
WHEN("WhichTaskDone is run on an organism with those inputs, The EQU of the two inputs, and ONLY_FIRST_TASK_CREDIT is 0"){
630630
//The result of applying the EQU bitwise opeartions to the binary form of 734856699 and 1177728054
631-
int equ_output = 2449493554;
631+
long equ_output = 2449493554;
632632
THEN("WhichTaskDone should return a 8"){
633633
int task_id = host->GetCPU().state.world->GetTaskSet().WhichTaskDone(host->GetCPU().state,equ_output,0);
634634
REQUIRE(task_id == 8);

0 commit comments

Comments
 (0)