-
Notifications
You must be signed in to change notification settings - Fork 33
Added functionality for Steal/Donate instructions to HealthHosts #251
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
Merged
anyaevostinar
merged 35 commits into
anyaevostinar:complex-syms-clean
from
EliasH-E:steal_instructions
Jul 18, 2025
Merged
Changes from 3 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 7d355b9
Made fixes and improvements to donate and steal
EliasH-E 9287092
Made fixes to tests and folded ONLYNOT test into SGPWorld.test.cc sin…
EliasH-E ffca7fe
Added functionality for instructions for stealing and donating to Hea…
EliasH-E f0e9611
Added Tests for steal/donate instructions
EliasH-E 875f175
Added variable starting steal count, tied for now to CPU_TRANSFER_AMOUNT
EliasH-E 25d5ab6
Made changes based on feedback, removed trash lines and cleaned up co…
EliasH-E d396fe5
Merged self
EliasH-E a75fbd7
Finished merge
EliasH-E 0207c43
Really finished merge
EliasH-E b9ce91a
final merge fix
EliasH-E 5866e06
Merged
EliasH-E 2d3016c
merged
EliasH-E ac4d00f
Merge branch 'complex-syms-clean' of https://github.com/EliasH-E/Symb…
EliasH-E 0d88a66
Fixed merge again
EliasH-E 3512963
Merge branch 'anyaevostinar:complex-syms-clean' into complex-syms-clean
EliasH-E 0860e0c
Merge branch 'complex-syms-clean' into steal_instructions
EliasH-E 15894f6
Merge branch 'complex-syms-clean' into steal_instructions
anyaevostinar 32c9f06
Fixed last merge problems
EliasH-E 7ab4e6a
Merge branch 'steal_instructions' of https://github.com/EliasH-E/Symb…
EliasH-E e66d0a8
Made fix to CreateStartProgram and added some documentation
EliasH-E d3c2e8d
Made fixes to no longer crash on test build
EliasH-E 1378b45
fixed merge tests
EliasH-E 11a136b
Made changes based on feedback and removed new test prints
EliasH-E f20940d
Added free bonus updates to syms, moved where steal success is decide…
EliasH-E 7917475
Fixed errors in sgp mode test
EliasH-E 85a08e2
Edited steal Health to better match original
EliasH-E dde32b3
Merge branch 'complex-syms-clean' into steal_instructions
anyaevostinar 3f34c3e
Added spread out steals, fixed tests and more
EliasH-E 939728e
Merge branch 'steal_instructions' of https://github.com/EliasH-E/Symb…
EliasH-E 89e40ec
merged
EliasH-E fc77eb4
Fixed Memory Leak
EliasH-E cd8341a
Merge branch 'anyaevostinar:complex-syms-clean' into complex-syms-clean
EliasH-E 4fb08ed
Fixed donate tracking
EliasH-E b776b68
merged
EliasH-E File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| #include "../../sgp_mode/GenomeLibrary.h" | ||
| #include "../../sgp_mode/CPU.h" | ||
| #include "../../sgp_mode/HealthHost.h" | ||
| #include "../../sgp_mode/SGPWorld.h" | ||
| #include "../../sgp_mode/SGPWorldSetup.cc" | ||
|
|
@@ -146,3 +148,107 @@ TEST_CASE("Health hosts evolve", "[sgp-integration]") { | |
| } | ||
| } | ||
| } | ||
|
|
||
| TEST_CASE("When DONATION_STEAL_INST is 1 then Symbiont with 'Steal' instruction properly takes CPU cycles from HealthHost", "[sgp]"){ | ||
|
|
||
| emp::Random random(1); | ||
| SymConfigSGP config; | ||
| config.RANDOM_ANCESTOR(false); | ||
| config.SEED(0); | ||
| config.ORGANISM_TYPE(HEALTH); | ||
| config.STRESS_TYPE(1); | ||
| config.MUTATION_RATE(0.0); | ||
| config.MUTATION_SIZE(0.00); | ||
| config.TRACK_PARENT_TASKS(1); | ||
| config.VT_TASK_MATCH(1); | ||
| config.ONLY_FIRST_TASK_CREDIT(1); | ||
| config.HOST_REPRO_RES(10000); | ||
| config.DONATION_STEAL_INST(1); | ||
| config.CPU_TRANSFER_CHANCE(1); | ||
|
|
||
|
|
||
| SGPWorld world(random, &config, LogicTasks); | ||
|
|
||
| //Builds program that does both NOT and NAND operations | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are places where you could use the "GIVEN" catch command |
||
|
|
||
|
|
||
| //Creates a host that only does NOT operations | ||
| emp::Ptr<HealthHost> host = emp::NewPtr<HealthHost>(&random, &world, &config, CreateNotProgram(100)); | ||
| //Creates a symbiont that does both Not and Nand operations | ||
| emp::Ptr<SGPSymbiont> sym = emp::NewPtr<SGPSymbiont>(&random, &world, &config, CreateParasiteNotProgram(100)); | ||
|
|
||
| //Adds host to world and sym to host. | ||
| world.AddOrgAt(host, 0); | ||
| host->AddSymbiont(sym); | ||
|
|
||
| WHEN("A symbiont performs a Steal instruction"){ | ||
| sym->GetCPU().RunCPUStep(0, 100); | ||
| (*(sym->GetCPU().state.tasks_performed))[0] = 0; | ||
| THEN("The host should be set to lose 4 cycles to the symbiont"){ | ||
| REQUIRE(host->GetCyclesGiven() == -4); | ||
| } | ||
| for (size_t i = 0; i < 24; i++) { | ||
| world.Update(); | ||
| } | ||
| THEN("The symbiont should complete its task one update early"){ | ||
| REQUIRE(sym->GetCPU().state.tasks_performed->Get(0) == true); | ||
| } | ||
| world.Update(); | ||
| THEN("The host should be unable to complete its task in 25 updates"){ | ||
| REQUIRE(host->GetCPU().state.tasks_performed->Get(0) == false); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| TEST_CASE("When DONATION_STEAL_INST is 1 then Symbiont with 'Donate' instruction properly gives CPU cycles to HealthHost", "[sgp]"){ | ||
|
|
||
| emp::Random random(1); | ||
| SymConfigSGP config; | ||
| config.RANDOM_ANCESTOR(false); | ||
| config.SEED(0); | ||
| config.ORGANISM_TYPE(HEALTH); | ||
| config.STRESS_TYPE(0); | ||
| config.MUTATION_RATE(0.0); | ||
| config.MUTATION_SIZE(0.00); | ||
| config.TRACK_PARENT_TASKS(1); | ||
| config.VT_TASK_MATCH(1); | ||
| config.ONLY_FIRST_TASK_CREDIT(1); | ||
| config.DONATION_STEAL_INST(1); | ||
| config.CPU_TRANSFER_CHANCE(1); | ||
|
|
||
| config.HOST_REPRO_RES(10000); | ||
|
|
||
| SGPWorld world(random, &config, LogicTasks); | ||
|
|
||
| //Builds program that does both NOT and NAND operations | ||
|
|
||
|
|
||
| //Creates a host that only does NOT operations | ||
| emp::Ptr<HealthHost> host = emp::NewPtr<HealthHost>(&random, &world, &config, CreateNotProgram(100)); | ||
| //Creates a symbiont that does both Not and Nand operations | ||
| emp::Ptr<SGPSymbiont> sym = emp::NewPtr<SGPSymbiont>(&random, &world, &config, CreateMutualistNotProgram(100)); | ||
|
|
||
| //Adds host to world and sym to host. | ||
| world.AddOrgAt(host, 0); | ||
| host->AddSymbiont(sym); | ||
|
|
||
| WHEN("A symbiont performs a Donate instruction"){ | ||
| sym->GetCPU().RunCPUStep(0, 100); | ||
| (*(sym->GetCPU().state.tasks_performed))[0] = 0; | ||
| THEN("The host should be set to gain 4 cycles from the symbiont"){ | ||
| REQUIRE(host->GetCyclesGiven() == 4); | ||
| } | ||
| for (size_t i = 0; i < 24; i++) { | ||
| world.Update(); | ||
| } | ||
| THEN("The host should complete its task one update early"){ | ||
| REQUIRE(host->GetCPU().state.tasks_performed->Get(0) == true); | ||
| } | ||
| world.Update(); | ||
| THEN("The symbiont should be unable to complete its task in 25 updates"){ | ||
| REQUIRE(sym->GetCPU().state.tasks_performed->Get(0) == false); | ||
| } | ||
|
|
||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name should make it clear what the overall phenotype is since it's more than just adding a single steal instruction. And what is it actually doing since it has steal and donate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I kind of actually forgot that this would be added to the pull request automatically on pushing. This was my current rusty implementation of placing steals throughout the genome. For some reason it was not letting me add nop inbetween, I was planning on asking about that in the slack today but it slipped my mind. I used donate because currently in my tests unless ALLOW_TRANSITION is on donate will do nothing.