Skip to content

Commit 720e649

Browse files
committed
Merge branch 'complex-syms-clean' of https://github.com/anyaevostinar/SymbulationEmp into complex-syms-clean
2 parents 15f76c8 + c2202bc commit 720e649

11 files changed

Lines changed: 577 additions & 79 deletions

File tree

source/catch/main.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
#include "../test/sgp_mode_test/SGPHost.test.cc"
3535
#include "../test/sgp_mode_test/SGPSymbiont.test.cc"
3636
#include "../test/sgp_mode_test/StressHost.test.cc"
37-
#include "../test/sgp_mode_test/HealthHost.test.cc"
37+
#include "../test/sgp_mode_test/FirstCredit.test.cc"
38+
#include "../test/sgp_mode_test/OnlyNOT.test.cc"
39+
#include "../test/sgp_mode_test/ParentTask.test.cc"
40+
//#include "../test/sgp_mode_test/HealthHost.test.cc"
3841

3942
#include "../test/integration_test/spatial_structure/vt.test.cc"
4043
#include "../test/integration_test/lysogeny/plr.test.cc"

source/sgp_mode/CPUState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct CPUState {
4949

5050
emp::Ptr<emp::BitSet<CPU_BITSET_LENGTH>> used_resources = emp::NewPtr<emp::BitSet<CPU_BITSET_LENGTH>>();
5151
emp::Ptr<emp::BitSet<CPU_BITSET_LENGTH>> tasks_performed = emp::NewPtr<emp::BitSet<CPU_BITSET_LENGTH>>();
52-
emp::Ptr<emp::BitSet<CPU_BITSET_LENGTH>> parent_tasks_performed = emp::NewPtr<emp::BitSet<CPU_BITSET_LENGTH>>(true);
52+
emp::Ptr<emp::BitSet<CPU_BITSET_LENGTH>> parent_tasks_performed = emp::NewPtr<emp::BitSet<CPU_BITSET_LENGTH>>(false);
5353
int task_change_lose[CPU_BITSET_LENGTH] = { 0 };
5454
int task_change_gain[CPU_BITSET_LENGTH] = { 0 };
5555

source/sgp_mode/HealthHost.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class HealthHost : public SGPHost {
6464
if (HasSym()) {
6565
if (sgp_config->STRESS_TYPE() == MUTUALIST) {
6666
//Host with mutualist gains 50% of CPU from mutualist
67-
if (random->P(0.5)) {
67+
68+
if (random->P(sgp_config->CPU_TRANSFER_CHANCE())) {
6869
host_cycle = 2;
6970
sym_cycle = 0;
7071
} else {
@@ -74,7 +75,7 @@ class HealthHost : public SGPHost {
7475
}
7576
else if (sgp_config->STRESS_TYPE() == PARASITE) {
7677
//Host with parasite loses 50% of CPU to parasite
77-
if (random->P(0.5)) {
78+
if (random->P(sgp_config->CPU_TRANSFER_CHANCE())) {
7879
host_cycle = 0;
7980
sym_cycle = 1;
8081
} else {
@@ -84,37 +85,36 @@ class HealthHost : public SGPHost {
8485
}
8586
}
8687

87-
//TODO: Should this be in a little loop to avoid duplicate code?
88-
//Probably doesn't matter that much
89-
if (host_cycle >= 1) {
90-
GetCPU().RunCPUStep(pos, sgp_config->CYCLES_PER_UPDATE());
91-
}
92-
if (host_cycle == 2) {
88+
//Loops running CPU steps
89+
for(int i = 0; i < host_cycle; i++){
9390
GetCPU().RunCPUStep(pos, sgp_config->CYCLES_PER_UPDATE());
9491
}
9592

96-
if (HasSym() && sym_cycle) { // let each sym do whatever they need to do
97-
emp::vector<emp::Ptr<Organism>> &syms = GetSymbionts();
98-
for (size_t j = 0; j < syms.size(); j++) {
99-
emp::Ptr<Organism> curSym = syms[j];
100-
if (GetDead()) {
101-
return; // If previous symbiont killed host, we're done
102-
}
103-
// sym position should have host index as id and
104-
// position in syms list + 1 as index (0 as fls index)
105-
emp::WorldPosition sym_pos = emp::WorldPosition(j + 1, pos.GetIndex());
106-
if (!curSym->GetDead()) {
107-
curSym->Process(sym_pos);
108-
}
109-
if (curSym->GetDead()) {
110-
syms.erase(syms.begin() + j); // if the symbiont dies during their
111-
// process, remove from syms list
112-
curSym.Delete();
113-
}
93+
if (HasSym() && sym_cycle > 0) { // let each sym do whatever they need to do
94+
for (int i = 0; i < sym_cycle; i++){
95+
emp::vector<emp::Ptr<Organism>> &syms = GetSymbionts();
96+
for (size_t j = 0; j < syms.size(); j++) {
97+
emp::Ptr<Organism> curSym = syms[j];
98+
if (GetDead()) {
99+
return; // If previous symbiont killed host, we're done
100+
}
101+
// sym position should have host index as id and
102+
// position in syms list + 1 as index (0 as fls index)
103+
emp::WorldPosition sym_pos = emp::WorldPosition(j + 1, pos.GetIndex());
104+
if (!curSym->GetDead()) {
105+
curSym->Process(sym_pos);
106+
}
107+
if (curSym->GetDead()) {
108+
syms.erase(syms.begin() + j); // if the symbiont dies during their
109+
// process, remove from syms list
110+
curSym.Delete();
111+
}
112+
114113
} // for each sym in syms
115114
} // if org has syms
116115

117-
116+
}
117+
GrowOlder();
118118
}
119119
};
120120
#endif // HEALTHHOST_H

source/sgp_mode/SGPConfigSetup.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ EMP_EXTEND_CONFIG(SymConfigSGP, SymConfigBase,
2828
VALUE(EXTINCTION_FREQUENCY, size_t, 2000, "How often should extinction events occur (in updates)?"),
2929
VALUE(PARASITE_DEATH_CHANCE, double, 0.5, "What death chance does a parasite confer?"),
3030
VALUE(MUTUALIST_DEATH_CHANCE, double, 0.125, "What death chance does a mutualist confer?"),
31-
VALUE(BASE_DEATH_CHANCE, double, 0.25, "What death chance does a host have in the absence of symbionts?")
31+
VALUE(BASE_DEATH_CHANCE, double, 0.25, "What death chance does a host have in the absence of symbionts?"),
32+
VALUE(CPU_TRANSFER_CHANCE, double, 0.5, "What is the chance for cycles to be stolen/donated?"),
33+
VALUE(ONLY_FIRST_TASK_CREDIT, int, 0, "Should symbionts only get credit for their first task")
34+
3235
)
3336

3437
#endif

source/sgp_mode/SGPWorldSetup.cc

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,47 @@ int SGPWorld::GetNeighborHost (size_t id, emp::Ptr<Organism> symbiont){
8181
* Purpose: To check for task matching before vertical transmission
8282
*/
8383
bool SGPWorld::TaskMatchCheck(emp::Ptr<Organism> sym_parent, emp::Ptr<Organism> host_parent) {
84+
8485
emp::Ptr<emp::BitSet<CPU_BITSET_LENGTH>> parent_tasks;
8586
emp::Ptr<emp::BitSet<CPU_BITSET_LENGTH>> host_tasks;
87+
8688
if (sgp_config->TRACK_PARENT_TASKS()) {
87-
parent_tasks = sym_parent.DynamicCast<SGPSymbiont>()->GetCPU().state.parent_tasks_performed;
88-
host_tasks = host_parent.DynamicCast<SGPHost>()->GetCPU().state.parent_tasks_performed;
89+
emp::Ptr<emp::BitSet<CPU_BITSET_LENGTH>> grand_parent_tasks;
90+
emp::Ptr<emp::BitSet<CPU_BITSET_LENGTH>> parent_host_tasks;
91+
92+
grand_parent_tasks = sym_parent.DynamicCast<SGPSymbiont>()->GetCPU().state.parent_tasks_performed;
93+
parent_host_tasks = host_parent.DynamicCast<SGPHost>()->GetCPU().state.parent_tasks_performed;
94+
95+
parent_tasks = sym_parent.DynamicCast<SGPSymbiont>()->GetCPU().state.tasks_performed;
96+
host_tasks = host_parent.DynamicCast<SGPHost>()->GetCPU().state.tasks_performed;
97+
98+
99+
for (int i = CPU_BITSET_LENGTH - 1; i > -1; i--) {
100+
101+
if ((parent_tasks->Get(i) || grand_parent_tasks->Get(i)) && (host_tasks->Get(i) || parent_host_tasks->Get(i))) {
102+
103+
//If either parent sym or grandparent sym can do task
104+
//host and parent host can do task then sym baby can infect
105+
return true;
106+
}
107+
}
89108
}
90109
else {
91110
parent_tasks = sym_parent.DynamicCast<SGPSymbiont>()->GetCPU().state.tasks_performed;
92111
host_tasks = host_parent.DynamicCast<SGPHost>()->GetCPU().state.tasks_performed;
112+
113+
for (int i = host_tasks - 1; i > -1; i--) {
114+
115+
116+
if (parent_tasks->Get(i) && host_tasks->Get(i)) {
117+
118+
//both parent sym and host can do this task, symbiont baby can infect
119+
return true;
120+
}
93121
}
94-
for (int i = host_tasks->size() - 1; i > -1; i--) {
95-
if (parent_tasks->Get(i) && host_tasks->Get(i)) {
96-
//both parent sym and host can do this task, symbiont baby can infect
97-
return true;
98-
}
99-
}
122+
}
123+
124+
100125
return false;
101126
}
102127

source/sgp_mode/Tasks.cc

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,90 @@
66

77
void Task::MarkPerformed(CPUState &state, uint32_t output, size_t task_id,
88
bool shared) {
9-
state.used_resources->Set(task_id);
10-
state.tasks_performed->Set(task_id);
11-
12-
if (dependencies.size()) {
13-
size_t total = num_dep_completes;
14-
for (size_t i : dependencies) {
15-
// Subtract just as much as needed from each dependency until we've
16-
// accumulated `num_dep_completes` completions
17-
size_t subtract = std::min(state.available_dependencies[i], total);
18-
total -= subtract;
19-
state.available_dependencies[i] -= subtract;
20-
21-
subtract = std::min((*state.shared_available_dependencies)[i], total);
22-
total -= subtract;
23-
(*state.shared_available_dependencies)[i] -= subtract;
24-
25-
if (total == 0) {
9+
10+
11+
if (state.world->GetConfig()->ONLY_FIRST_TASK_CREDIT()){
12+
13+
//Iterates through all tasks and checks if any of them have been done
14+
bool donePreviousTask = false;
15+
for(int i = 0; i < CPU_BITSET_LENGTH; i++){
16+
if(state.tasks_performed->Get(i) != 0){
17+
donePreviousTask = true;
18+
2619
break;
2720
}
2821
}
29-
}
3022

31-
if (shared) {
32-
(*state.shared_available_dependencies)[task_id]++;
33-
} else {
34-
state.available_dependencies[task_id]++;
23+
//If no other tasks have been done, set the current task to have been completed
24+
if(!donePreviousTask){
25+
26+
state.tasks_performed->Set(task_id);
27+
state.used_resources->Set(task_id);
28+
29+
30+
if (dependencies.size()) {
31+
size_t total = num_dep_completes;
32+
for (size_t i : dependencies) {
33+
// Subtract just as much as needed from each dependency until we've
34+
// accumulated `num_dep_completes` completions
35+
size_t subtract = std::min(state.available_dependencies[i], total);
36+
total -= subtract;
37+
state.available_dependencies[i] -= subtract;
38+
39+
subtract = std::min((*state.shared_available_dependencies)[i], total);
40+
total -= subtract;
41+
(*state.shared_available_dependencies)[i] -= subtract;
42+
43+
if (total == 0) {
44+
break;
45+
}
46+
}
47+
}
48+
49+
if (shared) {
50+
(*state.shared_available_dependencies)[task_id]++;
51+
} else {
52+
53+
state.available_dependencies[task_id]++;
54+
55+
}
56+
}
3557
}
58+
else{
59+
60+
//Hosts and Symbionts get credit for all tasks they complete
61+
62+
state.tasks_performed->Set(task_id);
63+
state.used_resources->Set(task_id);
64+
65+
66+
if (dependencies.size()) {
67+
size_t total = num_dep_completes;
68+
for (size_t i : dependencies) {
69+
// Subtract just as much as needed from each dependency until we've
70+
// accumulated `num_dep_completes` completions
71+
size_t subtract = std::min(state.available_dependencies[i], total);
72+
total -= subtract;
73+
state.available_dependencies[i] -= subtract;
74+
75+
subtract = std::min((*state.shared_available_dependencies)[i], total);
76+
total -= subtract;
77+
(*state.shared_available_dependencies)[i] -= subtract;
78+
79+
if (total == 0) {
80+
break;
81+
}
82+
}
83+
}
84+
85+
if (shared) {
86+
(*state.shared_available_dependencies)[task_id]++;
87+
} else {
88+
state.available_dependencies[task_id]++;
89+
}
90+
}
91+
92+
3693
}
3794

3895
#endif

0 commit comments

Comments
 (0)