Skip to content

Commit 45293f1

Browse files
Merge pull request #280 from EliasH-E/documenationClean
Made edits to Documentation for GenomeLibrary.h, HealthHosts.h, & SGPDataNodes.h
2 parents e0910f4 + a581a04 commit 45293f1

5 files changed

Lines changed: 119 additions & 44 deletions

File tree

source/sgp_mode/GenomeLibrary.h

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ProgramBuilder : emp::vector<sgpl::Instruction<Spec>> {
5959
push_back(inst);
6060
}
6161

62+
6263
sgpl::Program<Spec> Build(size_t length) {
6364
Add("Reproduce");
6465

@@ -102,15 +103,6 @@ class ProgramBuilder : emp::vector<sgpl::Instruction<Spec>> {
102103
Add("SharedIO");
103104
}
104105

105-
void AddPrivateNot() {
106-
// privateio r0
107-
// nand r0, r0, r0
108-
// privateio r0
109-
Add("PrivateIO");
110-
Add("Nand");
111-
Add("PrivateIO");
112-
}
113-
114106
void AddNand() {
115107
// sharedio r0
116108
// sharedio r1
@@ -122,17 +114,6 @@ class ProgramBuilder : emp::vector<sgpl::Instruction<Spec>> {
122114
Add("SharedIO");
123115
}
124116

125-
void AddPrivateNand() {
126-
// sharedio r0
127-
// sharedio r1
128-
// nand r0, r1, r0
129-
// sharedio r0
130-
Add("PrivateIO");
131-
Add("PrivateIO", 1);
132-
Add("Nand", 0, 1, 0);
133-
Add("PrivateIO");
134-
}
135-
136117
void AddAnd() {
137118
// ~(a nand b)
138119
// sharedio r0
@@ -298,7 +279,8 @@ class ProgramBuilder : emp::vector<sgpl::Instruction<Spec>> {
298279
* Output: None.
299280
*
300281
* Purpose: Spread out donate instructions throughout the organism's genome in order to allow donations
301-
* during a symbiont's entire genome and not just in one place. Without the spread of instructions symbionts were unable to donate regularly.
282+
* during a symbiont's entire genome and not just in one place. Without the spread of
283+
* instructions symbionts were unable to donate regularly.
302284
*/
303285
void AddStartDonate(int donate_count){
304286

@@ -319,17 +301,39 @@ class ProgramBuilder : emp::vector<sgpl::Instruction<Spec>> {
319301
}
320302
};
321303

304+
305+
/**
306+
* Input: Total length of program
307+
*
308+
* Output: Program that contains only a Reproduce instruction
309+
*
310+
* Purpose: Used for testing reproduction
311+
*/
322312
sgpl::Program<Spec> CreateReproProgram(size_t length) {
323313
ProgramBuilder program;
324314
return program.Build(length);
325315
}
326316

317+
/**
318+
* Input: Total length of program
319+
*
320+
* Output: Program that performs a NOT operation
321+
*
322+
* Purpose: Creates the program for the majority of starting organisms
323+
*/
327324
sgpl::Program<Spec> CreateNotProgram(size_t length) {
328325
ProgramBuilder program;
329326
program.AddNot();
330327
return program.Build(length);
331328
}
332329

330+
/**
331+
* Input: Total length of program and the number of steal instructions that should be in the program
332+
*
333+
* Output: Program that performs a NOT operation and contains steal instructions
334+
*
335+
* Purpose: Creates a program for starting parasite symbionts when DONATION_STEAL_INST is enabled
336+
*/
333337
sgpl::Program<Spec> CreateParasiteNotProgram(size_t length, int steal_count) {
334338
ProgramBuilder program;
335339
if(steal_count < 0){
@@ -347,6 +351,14 @@ sgpl::Program<Spec> CreateParasiteNotProgram(size_t length, int steal_count) {
347351
return program.Build(length);
348352
}
349353

354+
355+
/**
356+
* Input: Total length of program and the number of donate instructions that should be in the program
357+
*
358+
* Output: Program that performs a NOT operation and contains donate instructions
359+
*
360+
* Purpose: Creates a program for starting mutualist symbionts when DONATION_STEAL_INST is enabled
361+
*/
350362
sgpl::Program<Spec> CreateMutualistNotProgram(size_t length, int donate_count) {
351363
ProgramBuilder program;
352364
if(donate_count < 0){
@@ -363,6 +375,14 @@ sgpl::Program<Spec> CreateMutualistNotProgram(size_t length, int donate_count) {
363375
return program.Build(length);
364376
}
365377

378+
379+
/**
380+
* Input: Total length of program
381+
*
382+
* Output: Program that performs the EQU operation
383+
*
384+
* Purpose: Creates a program that is able to perform EQU and reproduce, used for testing
385+
*/
366386
sgpl::Program<Spec> CreateEquProgram(size_t length) {
367387
ProgramBuilder program;
368388
program.AddEqu();
@@ -371,8 +391,11 @@ sgpl::Program<Spec> CreateEquProgram(size_t length) {
371391

372392

373393
/**
374-
* Picks what type of starting program should be created based on the config and
375-
* creates it.
394+
* Input: A config file
395+
*
396+
* Output: Program for starting symbionts based on config
397+
*
398+
* Purpose: Assigns the correct program to the starting symbionts of the world
376399
*/
377400
sgpl::Program<Spec> CreateStartProgram(emp::Ptr<SymConfigSGP> config) {
378401
if(config->DONATION_STEAL_INST() == 1){

source/sgp_mode/HealthHost.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ class HealthHost : public SGPHost {
1010
//Tracks whether an update needs to be given to a symbiont or received from a symbiont
1111
int cycles_given = 1;
1212

13-
//Test variables that are currently used to give symbionts some starting cycles and then give them scraps throughout
13+
//Variables that are currently used to give symbionts some starting cycles and then give them scraps throughout
1414
//the rest of their updates.
1515
int honoray_cycles = 0;
1616
int starting_updates = 1;
1717
emp::Ptr<Organism> last_sym = NULL;
1818
/**
19-
* Constructs a new SGPHost as an ancestor organism, with either a random
20-
* genome or a blank genome that knows how to do a simple task depending on
21-
* the config setting RANDOM_ANCESTOR.
19+
* Constructs a new SGPHost as an ancestor organism, with a blank genome that knows how to do a simple task.
2220
*/
2321
HealthHost(emp::Ptr<emp::Random> _random, emp::Ptr<SGPWorld> _world,
2422
emp::Ptr<SymConfigSGP> _config, double _intval = 0.0,
@@ -92,7 +90,9 @@ class HealthHost : public SGPHost {
9290
*
9391
* Output: None
9492
*
95-
* Purpose: TBD
93+
* Purpose: To process the host, meaning: running its program code, which can
94+
* include reproduction and acquisition of resources; removing dead syms;
95+
* processing alive syms; Giving CPU cycles to syms; Receiving CPU cycles from syms;.
9696
*/
9797
void Process(emp::WorldPosition pos) override {
9898
if (GetDead()) {
@@ -116,8 +116,6 @@ class HealthHost : public SGPHost {
116116
cycles_given = 0;
117117
}
118118

119-
120-
//cycles_given = 0;
121119
}
122120
if(cycles_given <= -1){
123121

@@ -127,7 +125,7 @@ class HealthHost : public SGPHost {
127125
sym_cycle += 1;
128126
cycles_given = 0;
129127
}
130-
//cycles_given = 0;
128+
131129

132130
}
133131

@@ -214,8 +212,8 @@ class HealthHost : public SGPHost {
214212
curSym.Delete();
215213
}
216214

217-
} // for each sym in syms
218-
} // if org has syms
215+
}
216+
}
219217

220218
}
221219
GrowOlder();

source/sgp_mode/SGPDataNodes.h

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ void SGPWorld::CreateDataFiles() {
3131

3232

3333
/**
34-
* Input: The address of the string representing the file to be
35-
* created's name
34+
* Input: A reference to the string that will be used as the files name
3635
*
3736
* Output: The address of the DataFile that has been created.
3837
*
@@ -56,6 +55,15 @@ emp::DataFile &SGPWorld::SetUpOrgCountFile(const std::string &filename) {
5655
return file;
5756
}
5857

58+
/**
59+
* Input: A reference to the string that will be used as the files name
60+
*
61+
* Output: The address of the DataFile that has been created.
62+
*
63+
* Purpose: To set up the file that will be used to track
64+
* task counts in the world.
65+
* This includes the amount of each task completed for hosts and symbionts.
66+
*/
5967
emp::DataFile &SGPWorld::SetupTasksFile(const std::string &filename) {
6068
auto &file = SetupFile(filename);
6169
file.AddVar(update, "update", "Update");
@@ -73,7 +81,14 @@ emp::DataFile &SGPWorld::SetupTasksFile(const std::string &filename) {
7381
return file;
7482
}
7583

76-
84+
/**
85+
* Input:A reference to the string that will be used as the files name
86+
*
87+
* Output: The address of the DataFile that has been created.
88+
*
89+
* Purpose: To set up the file that will be used to track
90+
* the amount of Donate and Steal instructions ran
91+
*/
7792
emp::DataFile &SGPWorld::SetupSymInstFile(const std::string &filename) {
7893
auto &file = SetupFile(filename);
7994
file.AddVar(update, "update", "Update");
@@ -109,8 +124,7 @@ void SGPWorld::SetupTransmissionFileColumns(emp::DataFile& file) {
109124
}
110125

111126
/**
112-
* Input: The address of the string representing the file to be
113-
* created's name
127+
* Input: A reference to the string that will be used as the files name
114128
*
115129
* Output: None
116130
*
@@ -183,8 +197,7 @@ void SGPWorld::WriteTaskCombinationsFile(const std::string& filename) {
183197
}
184198

185199
/**
186-
* Input: The address of the string representing the file to be
187-
* created's name
200+
* Input: A reference to the string that will be used as the files name
188201
*
189202
* Output: None
190203
*
@@ -229,7 +242,14 @@ void SGPWorld::WriteOrgReproHistFile(const std::string& filename) {
229242
out_file.close();
230243
}
231244

232-
245+
/**
246+
* Input: None
247+
*
248+
* Output: None
249+
*
250+
* Purpose: To set up the data node storing the count
251+
* of each task completed for hosts and symbionts
252+
*/
233253
void SGPWorld::SetupTasksNodes() {
234254
if (!data_node_host_tasks.size()) {
235255
data_node_host_tasks.resize(task_set.NumTasks());
@@ -246,14 +266,27 @@ void SGPWorld::SetupTasksNodes() {
246266
}
247267
}
248268

249-
269+
/**
270+
* Input: None
271+
*
272+
* Output: Data monitor for the number of steal instruction ran
273+
*
274+
* Purpose: Get Steal count data node and create it if it doesn't already exist
275+
*/
250276
emp::DataMonitor<int> &SGPWorld::GetStealCount() {
251277
if (!data_node_steal_count) {
252278
data_node_steal_count.New();
253279
}
254280
return *data_node_steal_count;
255281
}
256282

283+
/**
284+
* Input: None
285+
*
286+
* Output: Data monitor for the number of donate instruction ran
287+
*
288+
* Purpose: Get Donate count data node and create it if it doesn't already exist
289+
*/
257290
emp::DataMonitor<int> &SGPWorld::GetDonateCount() {
258291
if (!data_node_donate_count) {
259292
data_node_donate_count.New();

source/sgp_mode/SGPSymbiont.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ class SGPSymbiont : public Symbiont {
124124
*/
125125
CPU &GetCPU() { return cpu; }
126126

127-
127+
/**
128+
* Input: Score of completed task, id of completed task
129+
*
130+
* Output: Calculated score to be received post interaction
131+
*
132+
* Purpose: Adjusts score that symbiont will receive based on whether it is giving some of its points to host
133+
* or stealing some of the hosts points.
134+
*/
128135
float DoTaskInteraction(float score, size_t task_id) {
129136
if(sgp_config->INTERACTION_MECHANISM() == 3){ //Nutrient mode
130137
emp::Ptr<SGPHost> host = my_host.DynamicCast<SGPHost>();

source/sgp_mode/Tasks.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class TaskSet {
126126
*
127127
* Output: None
128128
*
129-
* Purpose: Checks whether any tasks were completed and if so marks them as completing for reproductive purposes
129+
* Purpose: Checks whether any tasks were completed and if so marks them as completed for reproductive purposes
130130
* and awards the proper amount of points.
131131
*/
132132
void ProcessOutput(CPUState &state, uint32_t output, bool is_only_task_credit){
@@ -240,6 +240,14 @@ class TaskSet {
240240

241241
Iterator end() const { return Iterator{*this, tasks.size()}; }
242242

243+
/**
244+
* Input: None
245+
*
246+
* Output: None
247+
*
248+
* Purpose: Resets the count of all tasks to 0 for both symbionts and hosts
249+
* Used during the creation of the task data file and also for tests that check task counts
250+
*/
243251
void ResetTaskData() {
244252
for (size_t i = 0; i < tasks.size(); i++) {
245253
n_succeeds_host[i]->store(0);
@@ -252,6 +260,10 @@ class TaskSet {
252260
* The 9 default logic tasks in Avida
253261
* These are checked top-to-bottom and the reward is given for the first one
254262
* that matches
263+
*
264+
* Two of each logic task are stored, one where all tasks are worth 5 points
265+
* and one where harder tasks are worth more points.
266+
* The SGP config DIFFERENT_TASK_VALUES enables differing points among tasks
255267
*/
256268
const Task
257269
NOT = {"NOT", 1, 5.0, [](auto &x) { return ~x[0]; }},
@@ -273,13 +285,15 @@ const Task
273285
XOR_8 = {"XOR", 2, 8.0, [](auto &x) { return x[0] ^ x[1]; }},
274286
EQU_16 = {"EQU", 2, 16.0, [](auto &x) { return ~(x[0] ^ x[1]); }};
275287

288+
//Set of tasks where all tasks are worth 5 points, used when DIFFERENT_TASK_VALUES is 0
276289
const TaskSet LogicTasks{
277290
emp::NewPtr<Task>(NOT), emp::NewPtr<Task>(NAND),
278291
emp::NewPtr<Task>(AND), emp::NewPtr<Task>(ORN),
279292
emp::NewPtr<Task>(OR), emp::NewPtr<Task>(ANDN),
280293
emp::NewPtr<Task>(NOR), emp::NewPtr<Task>(XOR),
281294
emp::NewPtr<Task>(EQU)};
282295

296+
//Set of tasks where harder tasks are worth more points, used when DIFFERENT_TASK_VALUES is 1
283297
const TaskSet LogicTasksDiff{
284298
emp::NewPtr<Task>(NOT_1), emp::NewPtr<Task>(NAND_1),
285299
emp::NewPtr<Task>(AND_2), emp::NewPtr<Task>(ORN_2),

0 commit comments

Comments
 (0)