Skip to content

Commit 9f2b569

Browse files
committed
Fixed merge conflict'
2 parents c93c43b + b776b68 commit 9f2b569

12 files changed

Lines changed: 831 additions & 511 deletions

source/Organism.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ class Organism {
185185
std::cout << "GetCyclesGiven called from Organism" << std::endl;
186186
throw "Organism method called!";
187187
}
188-
189188
//Bacterium functions
190189
virtual double ProcessLysogenResources(double phage_inc_val){
191190
std::cout << "ProcessLysogenResources called from Organism" << std::endl;

source/sgp_mode/CPUState.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ struct CPUState {
5858
// If this organism is queued for reproduction, this stores its position in
5959
// the queue. When the organism dies, its queue slot will be invalidated.
6060
int in_progress_repro = -1;
61-
emp::Ptr<emp::vector<uint32_t>> internal_environment =
62-
emp::NewPtr<emp::vector<uint32_t>>();
6361
emp::vector<size_t> jump_table;
6462

6563
emp::Ptr<Organism> organism;

source/sgp_mode/GenomeLibrary.h

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ class ProgramBuilder : emp::vector<sgpl::Instruction<Spec>> {
5151
push_back(inst);
5252
}
5353

54+
void AddNop(uint8_t arg0 = 0, uint8_t arg1 = 0,
55+
uint8_t arg2 = 0) {
56+
sgpl::Instruction<Spec> inst;
57+
inst.op_code = 0;
58+
inst.args = {arg0, arg1, arg2};
59+
push_back(inst);
60+
}
61+
5462
sgpl::Program<Spec> Build(size_t length) {
5563
Add("Reproduce");
5664

@@ -257,14 +265,36 @@ class ProgramBuilder : emp::vector<sgpl::Instruction<Spec>> {
257265
Add("SharedIO");
258266
}
259267

260-
void AddSteal(){
268+
void AddStartSteal(int steal_count){
269+
270+
int diff = 96/steal_count;
271+
272+
for (int i = 0; i < steal_count; i++){
273+
274+
for (int x = 1; x < diff; x++){
275+
AddNop();
276+
277+
}
278+
Add("Steal");
279+
280+
}
261281

262-
Add("Steal");
263-
//std::cout << "Adding Steal" << std::endl;
264282
}
265283

266-
void AddDonate(){
267-
Add("Donate");
284+
void AddStartDonate(int donate_count){
285+
286+
int diff = 96/donate_count;
287+
int index = 1;
288+
for (int i = 0; i < donate_count; i++){
289+
290+
for (int x = 1; x < diff; x++){
291+
AddNop();
292+
293+
294+
}
295+
Add("Donate");
296+
297+
}
268298
}
269299
};
270300

@@ -279,22 +309,57 @@ sgpl::Program<Spec> CreateNotProgram(size_t length) {
279309
return program.Build(length);
280310
}
281311

282-
sgpl::Program<Spec> CreateMutualistStart(size_t length) {
312+
sgpl::Program<Spec> CreateParasiteNotProgram(size_t length, int steal_count) {
313+
ProgramBuilder program;
314+
program.Add("Steal");
315+
program.Add("Steal");
316+
program.AddStartSteal(steal_count);
317+
program.AddNot();
318+
319+
return program.Build(length);
320+
}
321+
322+
sgpl::Program<Spec> CreateMutualistNotProgram(size_t length, int donate_count) {
283323
ProgramBuilder program;
284-
program.AddNand();
285-
return program.BuildNoRepro(length);
324+
325+
program.Add("Donate");
326+
program.Add("Donate");
327+
program.AddStartDonate(donate_count);
328+
program.AddNot();
329+
return program.Build(length);
286330
}
287331

332+
sgpl::Program<Spec> CreateEquProgram(size_t length) {
333+
ProgramBuilder program;
334+
program.AddEqu();
335+
return program.Build(length);
336+
}
337+
338+
288339
/**
289340
* Picks what type of starting program should be created based on the config and
290341
* creates it.
291342
*/
292343
sgpl::Program<Spec> CreateStartProgram(emp::Ptr<SymConfigSGP> config) {
293344
if (config->TASK_TYPE() == 1) {
294-
return CreateNotProgram(PROGRAM_LENGTH);
295-
} else {
296-
return CreateReproProgram(PROGRAM_LENGTH);
345+
if(config->DONATION_STEAL_INST() == 1){
346+
if(config->STRESS_TYPE() == 1){
347+
return CreateParasiteNotProgram(PROGRAM_LENGTH, config->CPU_TRANSFER_AMOUNT());
348+
}
349+
else if(config->STRESS_TYPE() == 0){
350+
return CreateMutualistNotProgram(PROGRAM_LENGTH, config->CPU_TRANSFER_AMOUNT());
351+
}
352+
else{
353+
return CreateNotProgram(PROGRAM_LENGTH);
354+
}
355+
}
356+
else{
357+
return CreateNotProgram(PROGRAM_LENGTH);
358+
}
359+
297360
}
361+
return CreateReproProgram(PROGRAM_LENGTH);
362+
298363
}
299364

300365
#endif

source/sgp_mode/HealthHost.h

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ class HealthHost : public SGPHost {
77

88
public:
99

10-
int cycles_given = 0;
11-
10+
//Tracks whether an update needs to be given to a symbiont or received from a symbiont
11+
int cycles_given = 1;
12+
13+
//Test variables that are currently used to give symbionts some starting cycles and then give them scraps throughout
14+
//the rest of their updates.
15+
int honoray_cycles = 0;
16+
int starting_updates = 1;
17+
emp::Ptr<Organism> last_sym = NULL;
1218
/**
1319
* Constructs a new SGPHost as an ancestor organism, with either a random
1420
* genome or a blank genome that knows how to do a simple task depending on
@@ -57,7 +63,17 @@ class HealthHost : public SGPHost {
5763
random, GetWorld(), sgp_config, GetCPU().GetProgram(), GetIntVal());
5864
return host_baby;
5965
}
60-
66+
void CycleTransfer(int amount) override {
67+
cycles_given += amount;
68+
}
69+
70+
int GetCyclesGiven(){
71+
return cycles_given;
72+
}
73+
74+
std::string const GetName() override{
75+
return "HealthHost";
76+
}
6177
/**
6278
* Input: The location of the host.
6379
*
@@ -78,19 +94,58 @@ class HealthHost : public SGPHost {
7894
if (HasSym()) {
7995

8096
if(sgp_config->DONATION_STEAL_INST()){
81-
sym_cycle = 1;
82-
83-
if(cycles_given >= int(sgp_config->CYCLES_PER_UPDATE())){
84-
host_cycle += 1;
85-
sym_cycle -= 1;
86-
cycles_given -= int(sgp_config->CYCLES_PER_UPDATE());
97+
98+
99+
if(cycles_given >= 1){
100+
if(random->P(sgp_config->CPU_TRANSFER_CHANCE())){
101+
host_cycle += 1;
102+
sym_cycle -= 1;
103+
cycles_given = 0;
104+
}
87105

106+
107+
//cycles_given = 0;
108+
}
109+
if(cycles_given <= -1){
110+
111+
112+
if(random->P(sgp_config->CPU_TRANSFER_CHANCE())){
113+
host_cycle = 0;
114+
sym_cycle += 1;
115+
cycles_given = 0;
116+
}
117+
//cycles_given = 0;
118+
88119
}
89-
else if(cycles_given <= (-1 * int(sgp_config->CYCLES_PER_UPDATE()))){
90-
host_cycle -= 1;
91-
sym_cycle += 1;
92-
cycles_given += int(sgp_config->CYCLES_PER_UPDATE());
93120

121+
//This sequence checks if the symbiont will receive a cycle, if it has not then it checks if
122+
//one of its bonus updates is left, if so it uses one, if not it ticks up the counter
123+
//for when it receives said bonus update.
124+
//Allows for symbiont to reach steals but to still need them
125+
emp::vector<emp::Ptr<Organism>> &syms = GetSymbionts();
126+
emp::Ptr<Organism> curSym = syms[0];
127+
if(last_sym != curSym){
128+
last_sym = curSym;
129+
cycles_given = 0;
130+
starting_updates = sgp_config->STARTING_BONUS();
131+
}
132+
133+
if(sym_cycle == 0 && sgp_config->DONATION_STEAL_INST()){
134+
135+
136+
137+
if(starting_updates > 0){
138+
sym_cycle += 1;
139+
starting_updates -= 1;
140+
}
141+
142+
}
143+
if(starting_updates < 1){
144+
honoray_cycles += 1;
145+
if(honoray_cycles == sgp_config->BONUS_UPDATE_WAIT()){
146+
starting_updates += 1;
147+
honoray_cycles = 0;
148+
}
94149
}
95150
}
96151
else{
@@ -115,8 +170,12 @@ class HealthHost : public SGPHost {
115170
}
116171
}
117172
}
173+
174+
118175
}
119176

177+
178+
120179
//Loops running CPU steps
121180
for(int i = 0; i < host_cycle; i++){
122181
GetCPU().RunCPUStep(pos, sgp_config->CYCLES_PER_UPDATE());
@@ -149,13 +208,6 @@ class HealthHost : public SGPHost {
149208
GrowOlder();
150209
}
151210

152-
void CycleTransfer(int amount) override {
153-
cycles_given += amount;
154-
}
155-
156-
int GetCyclesGiven(){
157-
return cycles_given;
158-
}
159211
};
160212

161213

source/sgp_mode/Instructions.h

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -116,51 +116,38 @@ INST(SharedIO, {
116116
*a = next;
117117
state.input_buf.push(next);
118118
});
119+
119120
INST(Donate, {
120121
if (state.world->GetConfig()->DONATION_STEAL_INST() && (state.world->GetConfig()->STRESS_TYPE() == 0 || state.world->GetConfig()->ALLOW_TRANSITION_EVOLUTION() == 1)) {
121-
if (state.organism->IsHost() || state.organism->GetHost() == nullptr){
122-
122+
if (state.organism->IsHost()){
123123
return;
124-
if (emp::Ptr<Organism> host = state.organism->GetHost()) {
125-
// Donate 20% of the total points of the symbiont-host system
126-
// This way, a sym can donate e.g. 40 or 60 percent of their points in a
127-
// couple of instructions
128-
double to_donate =
129-
fmin(state.organism->GetPoints(),
130-
(state.organism->GetPoints() + host->GetPoints()) * 0.20);
131-
state.world->GetSymDonatedDataNode().WithMonitor(
132-
[=](auto &m) { m.AddDatum(to_donate); });
133-
host->AddPoints(to_donate);
134-
state.organism->AddPoints(-to_donate);
135124
}
136-
if (emp::Ptr<Organism> host = state.organism->GetHost()) {
137-
138-
//New Donate implementation:
139-
host->CycleTransfer(int(state.world->GetConfig()->CYCLES_PER_UPDATE()));
140-
141-
125+
emp::Ptr<Organism> host = state.organism->GetHost();
126+
if(host->GetCyclesGiven() <= 0){
127+
host->CycleTransfer(1);
128+
state.world->GetDonateCount().WithMonitor(
129+
[=](auto &m) { m.AddDatum(1); });
142130
}
131+
132+
143133
}
144134

145-
}});
135+
});
146136
INST(Steal, {
147137
if (state.world->GetConfig()->DONATION_STEAL_INST() && (state.world->GetConfig()->STRESS_TYPE() == 1 || state.world->GetConfig()->ALLOW_TRANSITION_EVOLUTION() == 1)) {
148-
if (state.organism->IsHost() || state.organism->GetHost() == nullptr){
138+
if (state.organism->IsHost()){
149139
return;
150-
if (emp::Ptr<Organism> host = state.organism->GetHost()) {
151-
// Steal 20% of the total points of the symbiont-host system
152-
// This way, a sym can steal e.g. 40 or 60 percent of the host's points in
153-
// a couple of instructions
154-
double to_steal =
155-
fmin(host->GetPoints(),
156-
(state.organism->GetPoints() + host->GetPoints()) * 0.20);
157-
state.world->GetSymStolenDataNode().WithMonitor(
158-
[=](auto &m) { m.AddDatum(to_steal); });
159-
host->AddPoints(-to_steal);
160-
state.organism->AddPoints(to_steal);
161140
}
141+
emp::Ptr<Organism> host = state.organism->GetHost();
142+
if(host->GetCyclesGiven() >= 0){
143+
host->CycleTransfer(-1);
144+
state.world->GetStealCount().WithMonitor(
145+
[=](auto &m) { m.AddDatum(1); });
146+
}
147+
}
148+
162149
}
163-
}});
150+
);
164151

165152
} // namespace inst
166153

source/sgp_mode/SGPConfigSetup.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ EMP_EXTEND_CONFIG(SymConfigSGP, SymConfigBase,
1111
VALUE(CYCLES_PER_UPDATE, size_t, 4, "Number of CPU cycles that organisms run every update"),
1212
VALUE(THREAD_COUNT, size_t, 1, "Number of threads used to process organisms in parallel"),
1313
VALUE(TASK_TYPE, bool, 1, "1 for NOT + repro starting genome, 0 for repro starting program"),
14-
VALUE(DONATION_STEAL_INST, bool, 1, "1 if you want donate and steal instructions in the instruction set, 0 if not"),
14+
VALUE(DONATION_STEAL_INST, bool, 0, "1 if you want donate and steal instructions in the instruction set, 0 if not"),
1515
VALUE(RANDOM_IO_INPUT, bool, true, "1 to give organisms random input when they IO, 0 to give them only ones"),
1616
VALUE(ORGANISM_TYPE, size_t, DEFAULT, "What sgp organisms should population the world? (0 for default SGP, 1 for Health organisms, 2 for stress organisms)"),
1717
VALUE(VT_TASK_MATCH, bool, 0, "Should task matching be required for vertical transmission? (0 for no, 1 for yes)"),
@@ -24,8 +24,11 @@ EMP_EXTEND_CONFIG(SymConfigSGP, SymConfigBase,
2424
VALUE(MUTUALIST_DEATH_CHANCE, double, 0.125, "What death chance does a mutualist confer?"),
2525
VALUE(BASE_DEATH_CHANCE, double, 0.25, "What death chance does a host have in the absence of symbionts?"),
2626
VALUE(CPU_TRANSFER_CHANCE, double, 0.5, "What is the chance for cycles to be stolen/donated?"),
27-
VALUE(ONLY_FIRST_TASK_CREDIT, int, 0, "Should symbionts only get credit for their first task"),
28-
VALUE(ALLOW_TRANSITION_EVOLUTION, int, 0, "Should symbionts be allowed to evolve from mutalists to parasties and vice versa")
27+
VALUE(CPU_TRANSFER_AMOUNT, double, 1, "How many updates should be stolen/donated by instruction based symbionts"),
28+
VALUE(ONLY_FIRST_TASK_CREDIT, int, 0, "Should organisms only get credit for their first task"),
29+
VALUE(ALLOW_TRANSITION_EVOLUTION, int, 0, "Should symbionts be allowed to evolve from mutualists to parasties and vice versa"),
30+
VALUE(BONUS_UPDATE_WAIT, int, 5, "If DONATION_STEAL_INST is 1 how many updates till a symbiont receives a free extra update"),
31+
VALUE(STARTING_BONUS, int, 1, "How many bonus updates do symbionts start with")
2932
)
3033

3134
#endif

0 commit comments

Comments
 (0)