[Avida-SVN] r2760 - in branches/collect: Avida.xcodeproj documentation/glossary source/actions source/analyze source/cpu source/main source/platform source/tools
blwalker at myxo.css.msu.edu
blwalker at myxo.css.msu.edu
Tue Aug 26 10:56:51 PDT 2008
Author: blwalker
Date: 2008-08-26 13:56:50 -0400 (Tue, 26 Aug 2008)
New Revision: 2760
Modified:
branches/collect/Avida.xcodeproj/project.pbxproj
branches/collect/documentation/glossary/help.Registers.html
branches/collect/documentation/glossary/help.Stack.html
branches/collect/documentation/glossary/help.add.html
branches/collect/source/actions/EnvironmentActions.cc
branches/collect/source/actions/PrintActions.cc
branches/collect/source/analyze/cAnalyze.cc
branches/collect/source/analyze/cAnalyzeGenotype.cc
branches/collect/source/analyze/cAnalyzeGenotype.h
branches/collect/source/cpu/cCPUTestInfo.cc
branches/collect/source/cpu/cCPUTestInfo.h
branches/collect/source/cpu/cHardwareExperimental.cc
branches/collect/source/cpu/cHardwareExperimental.h
branches/collect/source/cpu/cHardwareManager.cc
branches/collect/source/cpu/cHardwareManager.h
branches/collect/source/cpu/cTestCPU.cc
branches/collect/source/main/cDemeCellEvent.cc
branches/collect/source/main/cEnvironment.cc
branches/collect/source/main/cLandscape.cc
branches/collect/source/main/cOrganism.cc
branches/collect/source/main/cOrganism.h
branches/collect/source/main/cPhenPlastGenotype.cc
branches/collect/source/main/cPhenPlastGenotype.h
branches/collect/source/main/cPhenotype.cc
branches/collect/source/main/cPhenotype.h
branches/collect/source/main/cTaskLib.cc
branches/collect/source/platform/platform.h
branches/collect/source/tools/cDataFileManager.cc
Log:
Porting r2729:2759 from development to collect branch.
Modified: branches/collect/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/collect/Avida.xcodeproj/project.pbxproj 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/Avida.xcodeproj/project.pbxproj 2008-08-26 17:56:50 UTC (rev 2760)
@@ -220,23 +220,6 @@
};
/* End PBXBuildRule section */
-/* Begin PBXBuildStyle section */
- B54852BC0DF98D8E00AD254E /* Development */ = {
- isa = PBXBuildStyle;
- buildSettings = {
- COPY_PHASE_STRIP = NO;
- };
- name = Development;
- };
- B54852BD0DF98D8E00AD254E /* Deployment */ = {
- isa = PBXBuildStyle;
- buildSettings = {
- COPY_PHASE_STRIP = YES;
- };
- name = Deployment;
- };
-/* End PBXBuildStyle section */
-
/* Begin PBXContainerItemProxy section */
56F555DA0C3B36FC00E2E929 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
@@ -1834,16 +1817,12 @@
DCC30C4D0762532C008F7A48 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
- buildSettings = {
- };
- buildStyles = (
- B54852BC0DF98D8E00AD254E /* Development */,
- B54852BD0DF98D8E00AD254E /* Deployment */,
- );
+ compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 0;
mainGroup = DCC30C490762532C008F7A48;
productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;
projectDirPath = "";
+ projectRoot = "";
targets = (
7023ED520C0A590200362B9C /* full-suite */,
DCC3164C07626CF3008F7A48 /* avida */,
Modified: branches/collect/documentation/glossary/help.Registers.html
===================================================================
--- branches/collect/documentation/glossary/help.Registers.html 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/documentation/glossary/help.Registers.html 2008-08-26 17:56:50 UTC (rev 2760)
@@ -3,4 +3,8 @@
<h1>Registers</h1>
-Each <a href="help.CPU.html">CPU</a> in avida contains three registers, each of which is made up of 32 bits. All math-based <a href="help.Instruction.html">instructions</a> opperate on the registers, and various instruction will move the values in the registers around.
+<p>
+A register is a storage space for a single number.
+Each classic <a href="help.CPU.html">CPU</a> in Avida contains three registers, each of which is made up of 32 bits. All math-based <a href="help.Instruction.html">instructions</a> opperate on the registers, and various instruction will move the values in the registers around.
+</p>
+</html>
Modified: branches/collect/documentation/glossary/help.Stack.html
===================================================================
--- branches/collect/documentation/glossary/help.Stack.html 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/documentation/glossary/help.Stack.html 2008-08-26 17:56:50 UTC (rev 2760)
@@ -2,5 +2,7 @@
<title>CPU Components : Stack</title>
<h1>Stack</h1>
-
-Each <a href="help.CPU.html">CPU</a> in avida has two stacks used for storage of numbers. The <a href="help.push.html">push</a> and <a href="help.pop.html">pop</a> instructions are used to move numbers between the <a href="help.Registers.html">registers</a> and the stack, and the <a href="help.swap-stk.html">swap-stk</a> instruction toggles the active stack in use.
+<P>
+Each classic <a href="help.CPU.html">CPU</a> in Avida has two stacks used for storage of numbers. The <a href="help.push.html">push</a> and <a href="help.pop.html">pop</a> instructions are used to move numbers between the <a href="help.Registers.html">registers</a> and the stack, and the <a href="help.swap-stk.html">swap-stk</a> instruction toggles the active stack in use.
+</P>
+</html>
Modified: branches/collect/documentation/glossary/help.add.html
===================================================================
--- branches/collect/documentation/glossary/help.add.html 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/documentation/glossary/help.add.html 2008-08-26 17:56:50 UTC (rev 2760)
@@ -3,4 +3,5 @@
<h1>add</h1>
-This instruction reads in the contents of the BX and CX <a href="help.Registers.html">registers</a> and sums them together. The result of this operation is then placed in the <a href="help.Nop-Register-Notation.html">?BX?</a> register.
+<p>This instruction reads in the contents of the BX and CX <a href="help.Registers.html">registers</a> and sums them together. The result of this operation is then placed in the <a href="help.Nop-Register-Notation.html">?BX?</a> register.</p>
+</html>
Modified: branches/collect/source/actions/EnvironmentActions.cc
===================================================================
--- branches/collect/source/actions/EnvironmentActions.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/actions/EnvironmentActions.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -536,6 +536,33 @@
};
/**
+ Sets resource availiblity to seasonal
+ */
+class cActionSetSeasonalResource : public cAction
+ {
+ private:
+ cString m_res_name;
+
+ public:
+ cActionSetSeasonalResource(cWorld* world, const cString& args): cAction(world, args), m_res_name("")
+ {
+ cString largs(args);
+ if (largs.GetSize()) m_res_name = largs.PopWord();
+ }
+
+ static const cString GetDescription() { return "Arguments: <string reaction_name>"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ int time = m_world->GetStats().GetUpdate();
+ double m_res_count = -1*(0.4*tanh((time-182500)/50000)+0.5)*(0.5*sin(time/58.091)+0.5)+1;
+ cResource* res = m_world->GetEnvironment().GetResourceLib().GetResource(m_res_name);
+ if (res != NULL) m_world->GetPopulation().SetResource(res->GetID(), m_res_count);
+
+ }
+ };
+
+/**
Sets resource availiblity to periodic
*/
class cActionSetPeriodicResource : public cAction
@@ -850,6 +877,7 @@
action_lib->Register<cActionSetEnvironmentInputs>("SetEnvironmentInputs");
action_lib->Register<cActionSetEnvironmentRandomMask>("SetEnvironmentRandomMask");
+ action_lib->Register<cActionSetSeasonalResource>("SetSeasonalResource");
action_lib->Register<cActionSetPeriodicResource>("SetPeriodicResource");
action_lib->Register<cActionSetNumInstBefore0Energy>("SetNumInstBefore0Energy");
Modified: branches/collect/source/actions/PrintActions.cc
===================================================================
--- branches/collect/source/actions/PrintActions.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/actions/PrintActions.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -1581,6 +1581,8 @@
void Process(cAvidaContext& ctx)
{
+ cCPUTestInfo test_info;
+
if (ctx.GetAnalyzeMode()){ // Analyze mode
cString this_path = m_filename;
ofstream& fot = m_world->GetDataFileOFStream(this_path);
@@ -1588,7 +1590,7 @@
tListIterator<cAnalyzeGenotype> batch_it(m_world->GetAnalyze().GetCurrentBatch().List());
cAnalyzeGenotype* genotype = NULL;
while((genotype = batch_it.Next())){
- const cPhenPlastGenotype* ppgen = new cPhenPlastGenotype(genotype->GetGenome(), m_num_trials, m_world, ctx);
+ const cPhenPlastGenotype* ppgen = new cPhenPlastGenotype(genotype->GetGenome(), m_num_trials, test_info, m_world, ctx);
PrintPPG(fot, ppgen, genotype->GetID(), genotype->GetParentID());
delete ppgen;
}
@@ -1599,7 +1601,7 @@
PrintHeader(fot);
cGenotype* genotype = m_world->GetClassificationManager().GetBestGenotype();
for (int k = 0; k < m_world->GetClassificationManager().GetGenotypeCount(); k++){
- const cPhenPlastGenotype* ppgen = new cPhenPlastGenotype(genotype->GetGenome(), m_num_trials, m_world, ctx);
+ const cPhenPlastGenotype* ppgen = new cPhenPlastGenotype(genotype->GetGenome(), m_num_trials, test_info, m_world, ctx);
PrintPPG(fot, ppgen, genotype->GetID(), genotype->GetParentID());
delete ppgen;
genotype = genotype->GetNext();
Modified: branches/collect/source/analyze/cAnalyze.cc
===================================================================
--- branches/collect/source/analyze/cAnalyze.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/analyze/cAnalyze.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -4723,7 +4723,7 @@
fp << endl;
} else { // if (file_type == FILE_TYPE_HTML) {
- // Mark file as html
+ // Mark file as html
fp << "<html>" << endl;
// Setup any javascript macros needed...
@@ -4743,16 +4743,10 @@
fp << "</head>" << endl;
// Setup the body...
- fp << "<body bgcolor=\"#FFFFFF\"" << endl
- << " text=\"#000000\"" << endl
- << " link=\"#0000AA\"" << endl
- << " alink=\"#0000FF\"" << endl
- << " vlink=\"#000044\">" << endl
- << endl
- << "<h1 align=center>Run " << batch[cur_batch].Name()
- << ", ID " << genotype->GetID() << "</h1>" << endl
- << "<center>" << endl
- << endl;
+ fp << "<body>" << endl
+ << "<div align=\"center\">" << endl
+ << "<h1 align=\"center\">Run " << batch[cur_batch].Name() << ", ID " << genotype->GetID() << "</h1>" << endl
+ << endl;
// Links?
fp << "<table width=90%><tr><td align=left>";
@@ -4836,7 +4830,7 @@
// Print the individual columns...
output_it.Reset();
- tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+ tDataEntryCommand<cAnalyzeGenotype>* data_command = NULL;
int cur_col = 0;
while ((data_command = output_it.Next()) != NULL) {
data_command->SetTarget(&test_genotype);
@@ -4844,9 +4838,6 @@
const cFlexVar test_value = data_command->GetValue();
int compare = CompareFlexStat(test_value, data_command->GetValue(genotype), data_command->GetCompareType());
- // BUG! Either of the next two conditional print commands can
- // cause landscaping to be triggered in a context that causes a crash,
- // notably, if you don't provide any column parameters to MapTasks.. @JEB
if (file_type == FILE_TYPE_HTML) {
HTMLPrintStat(test_value, fp, compare, data_command->GetHtmlCellFlags(), data_command->GetNull(),
!(data_command->HasArg("blank")));
@@ -4882,14 +4873,14 @@
// And close everything up...
fp << "</table>" << endl
- << "</center>" << endl;
+ << "</div>" << endl;
}
delete [] col_pass_count;
delete [] col_fail_count;
m_world->GetDataFileManager().Remove(filename); // Close the data file object
- }
- }
+ }
+}
void cAnalyze::CommandAverageModularity(cString cur_string)
{
@@ -4897,7 +4888,6 @@
// Load in the variables...
cString filename = cur_string.PopWord();
- // cString filename = "average.dat";
int print_mode = 0; // 0=Normal, 1=Boolean results
@@ -4998,8 +4988,11 @@
///////////////////////////////////////////////////////
tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
- cAnalyzeGenotype * genotype = NULL;
+ cAnalyzeGenotype* genotype = NULL;
+ cInstSet map_inst_set(inst_set);
+ const cInstruction null_inst = map_inst_set.ActivateNullInst();
+
// would like to test oly the viable ones, but they can be non-viable
// and still reproduce and do tasks
// while ((genotype = batch_it.Next()) != NULL && genotype->GetViable()) {
@@ -5008,23 +5001,27 @@
int num_cpus = genotype->GetNumCPUs();
if (m_world->GetVerbosity() >= VERBOSE_ON) cout << " Mapping " << genotype->GetName() << endl;
+ cout.flush();
// Calculate the stats for the genotype we're working with...
genotype->Recalculate(m_ctx);
// Check if the organism does any tasks.
- int does_tasks = 0;
+ bool does_tasks = false;
for (int i = 0; i < num_cols; i++) {
- if (genotype->GetTaskCount(i) > 0) does_tasks = 1;
+ if (genotype->GetTaskCount(i) > 0) {
+ does_tasks = true;
+ break;
+ }
}
// Don't calculate the modularity if the organism doesn't reproduce
// i.e. if the fitness is 0
- if (genotype->GetFitness() != 0 && does_tasks != 0) {
+ if (genotype->GetFitness() > 0.0 && does_tasks) {
num_orgs = num_orgs + num_cpus;
const int max_line = genotype->GetLength();
- const cGenome & base_genome = genotype->GetGenome();
+ const cGenome& base_genome = genotype->GetGenome();
cGenome mod_genome(base_genome);
// Create and initialize the modularity matrix
@@ -5054,163 +5051,159 @@
int total_inst = 0; // total number of instructions involved in tasks
int total_all = 0; // sum of mod_matrix
double sum_task_overlap = 0;// task overlap for for this geneome
+
+ // Loop through all the lines of code, testing the removal of each.
+ for (int line_num = 0; line_num < max_line; line_num++) {
+ int cur_inst = base_genome[line_num].GetOp();
- cInstSet map_inst_set(inst_set);
- const cInstruction null_inst = map_inst_set.ActivateNullInst();
+ mod_genome[line_num] = null_inst;
+ cAnalyzeGenotype test_genotype(m_world, mod_genome, map_inst_set);
+ test_genotype.Recalculate(m_ctx);
- // Loop through all the lines of code, testing the removal of each.
- for (int line_num = 0; line_num < max_line; line_num++) {
- int cur_inst = base_genome[line_num].GetOp();
+ // Print the individual columns...
+ output_it.Reset();
+ tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+ int cur_col = 0;
+ while ((data_command = output_it.Next()) != NULL) {
+ data_command->SetTarget(&test_genotype);
+ test_genotype.SetSpecialArgs(data_command->GetArgs());
+ const cFlexVar test_value = data_command->GetValue();
- mod_genome[line_num] = null_inst;
- cAnalyzeGenotype test_genotype(m_world, mod_genome, map_inst_set);
- cAnalyzeGenotype old_genotype(m_world, base_genome, map_inst_set);
- test_genotype.Recalculate(m_ctx);
+ // This is done so that under 'binary' option it marks
+ // the task as being influenced by the mutation iff
+ // it is completely knocked out, not just decreased
+ genotype->SetSpecialArgs(data_command->GetArgs());
- // Print the individual columns...
- output_it.Reset();
- tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
- int cur_col = 0;
- while ((data_command = output_it.Next()) != NULL) {
- data_command->SetTarget(&test_genotype);
- test_genotype.SetSpecialArgs(data_command->GetArgs());
- const cFlexVar test_value = data_command->GetValue();
-
- // This is done so that under 'binary' option it marks
- // the task as being influenced by the mutation iff
- // it is completely knocked out, not just decreased
- genotype->SetSpecialArgs(data_command->GetArgs());
-
- int compare_type = data_command->GetCompareType();
- int compare = CompareFlexStat(test_value, data_command->GetValue(genotype), compare_type);
-
- // If knocking out an instruction stops the expression of a
- // particular task, mark that in the modularity matrix
- // and add it to two counts
- // Only do the checking if the test_genotype replicate, i.e.
- // if it's fitness is not zeros
-
- if (compare < 0 && test_genotype.GetFitness() != 0) {
- mod_matrix(cur_col,line_num) = 1;
- num_inst[cur_col]++;
- num_task[line_num]++;
- }
- cur_col++;
- }
+ int compare_type = data_command->GetCompareType();
+ int compare = CompareFlexStat(test_value, data_command->GetValue(genotype), compare_type);
- // Reset the mod_genome back to the original sequence.
- mod_genome[line_num].SetOp(cur_inst);
- } // end of genotype-phenotype mapping for a single organism
-
- for (int i = 0; i < num_cols; i++) {if (num_inst[i] != 0) total_task++;}
- for (int i = 0; i < max_line; i++) {if (num_task[i] != 0) total_inst++;}
- for (int i = 0; i < num_cols; i++) {total_all = total_all + num_inst[i];}
-
- // Add the values to the av_ variables, used for calculating the average
- // in order to weigh them by abundance, multiply everything by num_cpus
-
- av_length = av_length + max_line*num_cpus;
- av_task = av_task + total_task*num_cpus;
- av_inst = av_inst + total_inst*num_cpus;
- av_inst_len = av_inst_len + (double) total_inst*num_cpus/max_line;
-
- if (total_task !=0) av_site_task = av_site_task + num_cpus * (double) total_all/total_task;
- if (total_inst !=0) av_task_site = av_task_site + num_cpus * (double) total_all/total_inst;
- if (total_inst !=0 && total_task !=0) {
- av_t_s_norm = av_t_s_norm + num_cpus * (double) total_all/(total_inst*total_task);
+ // If knocking out an instruction stops the expression of a
+ // particular task, mark that in the modularity matrix
+ // and add it to two counts
+ // Only do the checking if the test_genotype replicate, i.e.
+ // if it's fitness is not zeros
+
+ if (compare < 0 && test_genotype.GetFitness() != 0) {
+ mod_matrix(cur_col,line_num) = 1;
+ num_inst[cur_col]++;
+ num_task[line_num]++;
+ }
+ cur_col++;
}
- for (int i = 0; i < num_cols; i++) {
- if (num_inst[i] > 0) {
- av_num_inst[i] = av_num_inst[i] + num_inst[i] * num_cpus;
- org_task[i] = org_task[i] + num_cpus; // count how many are actually doing the task
+ // Reset the mod_genome back to the original sequence.
+ mod_genome[line_num].SetOp(cur_inst);
+ } // end of genotype-phenotype mapping for a single organism
+
+ for (int i = 0; i < num_cols; i++) if (num_inst[i] != 0) total_task++;
+ for (int i = 0; i < max_line; i++) if (num_task[i] != 0) total_inst++;
+ for (int i = 0; i < num_cols; i++) total_all = total_all + num_inst[i];
+
+ // Add the values to the av_ variables, used for calculating the average
+ // in order to weigh them by abundance, multiply everything by num_cpus
+
+ av_length = av_length + max_line*num_cpus;
+ av_task = av_task + total_task*num_cpus;
+ av_inst = av_inst + total_inst*num_cpus;
+ av_inst_len = av_inst_len + (double) total_inst*num_cpus/max_line;
+
+ if (total_task !=0) av_site_task = av_site_task + num_cpus * (double) total_all/total_task;
+ if (total_inst !=0) av_task_site = av_task_site + num_cpus * (double) total_all/total_inst;
+ if (total_inst !=0 && total_task !=0) {
+ av_t_s_norm = av_t_s_norm + num_cpus * (double) total_all/(total_inst*total_task);
+ }
+
+ for (int i = 0; i < num_cols; i++) {
+ if (num_inst[i] > 0) {
+ av_num_inst[i] = av_num_inst[i] + num_inst[i] * num_cpus;
+ org_task[i] = org_task[i] + num_cpus; // count how many are actually doing the task
+ }
+ }
+
+ // calculate average task overlap
+ // first construct num_task x num_task matrix with number of sites overlapping
+ for (int i = 0; i < max_line; i++) {
+ for (int j = 0; j < num_cols; j++) {
+ for (int k = j; k < num_cols; k++) {
+ if (mod_matrix(j,i)>0 && mod_matrix(k,i)>0) {
+ task_overlap(j,k)++;
+ if (j!=k) task_overlap(k,j)++;
+ }
}
- }
-
- // calculate average task overlap
- // first construct num_task x num_task matrix with number of sites overlapping
- for (int i = 0; i < max_line; i++) {
+ }
+ }
+
+ // go though the task_overlap matrix, add and average everything up.
+ if (total_task > 1) {
+ for (int i = 0; i < num_cols; i++) {
+ double overlap_per_task = 0;
for (int j = 0; j < num_cols; j++) {
- for (int k = j; k < num_cols; k++) {
- if (mod_matrix(j,i)>0 && mod_matrix(k,i)>0) {
- task_overlap(j,k)++;
- if (j!=k) task_overlap(k,j)++;
- }
- }
+ if (i!=j) {overlap_per_task = overlap_per_task + task_overlap(i,j);}
}
- }
-
- // go though the task_overlap matrix, add and average everything up.
- if (total_task > 1) {
- for (int i = 0; i < num_cols; i++) {
- double overlap_per_task = 0;
- for (int j = 0; j < num_cols; j++) {
- if (i!=j) {overlap_per_task = overlap_per_task + task_overlap(i,j);}
- }
- if (task_overlap(i,i) !=0){
- sum_task_overlap = sum_task_overlap + overlap_per_task / (task_overlap(i,i) * (total_task-1));
- }
+ if (task_overlap(i,i) !=0){
+ sum_task_overlap = sum_task_overlap + overlap_per_task / (task_overlap(i,i) * (total_task-1));
}
}
-
- // now, divide that by number of tasks done and add to the grand sum, weigthed by num_cpus
- if (total_task!=0) {
- av_task_overlap = av_task_overlap + num_cpus * (double) sum_task_overlap/total_task ;
- }
- // calculate the first/last postion of a task, the task "spread"
- // starting from the top look for the fist command that matters for a task
-
- for (int i = 0; i < num_cols; i++) {
- int j = 0;
- while (j < max_line) {
- if (mod_matrix(i,j) > 0 && task_length[i] == 0 ) {
- task_length[i] = j;
- break;
- }
- j++;
+ }
+
+ // now, divide that by number of tasks done and add to the grand sum, weigthed by num_cpus
+ if (total_task!=0) {
+ av_task_overlap = av_task_overlap + num_cpus * (double) sum_task_overlap/total_task ;
+ }
+ // calculate the first/last postion of a task, the task "spread"
+ // starting from the top look for the fist command that matters for a task
+
+ for (int i = 0; i < num_cols; i++) {
+ int j = 0;
+ while (j < max_line) {
+ if (mod_matrix(i,j) > 0 && task_length[i] == 0 ) {
+ task_length[i] = j;
+ break;
}
+ j++;
}
-
- // starting frm the bottom look for the last command that matters for a task
- // and substract it from the first to get the task length
- // add one in order to account for both the beginning and the end instruction
- for (int i = 0; i < num_cols; i++) {
- int j = max_line - 1;
- while (j > -1) {
- if (mod_matrix(i,j) > 0) {
- task_length[i] = j - task_length[i] + 1;
- break;
- }
- j--;
+ }
+
+ // starting frm the bottom look for the last command that matters for a task
+ // and substract it from the first to get the task length
+ // add one in order to account for both the beginning and the end instruction
+ for (int i = 0; i < num_cols; i++) {
+ int j = max_line - 1;
+ while (j > -1) {
+ if (mod_matrix(i,j) > 0) {
+ task_length[i] = j - task_length[i] + 1;
+ break;
}
+ j--;
}
- // add the task lengths to the average for the batch
- // weigthed by the number of cpus for that genotype
- for (int i = 0; i < num_cols; i++) {
- av_task_length[i] = av_task_length[i] + num_cpus * task_length[i];
- }
-
- // calculate the Standard Deviation in the mean position of the task
- for (int i = 0; i < num_cols; i++) {
- for (int j = 0; j < max_line; j++) {
- if (mod_matrix(i,j)>0) sum[i] = sum[i] + j;
- }
- }
-
- double temp = 0;
- for (int i = 0; i < num_cols; i++) {
- if (num_inst[i]>1) {
- double av_sum = sum[i]/num_inst[i];
- for (int j = 0; j < max_line; j++) {
- if (mod_matrix(i,j)>0) temp = (av_sum - j)*(av_sum - j);
- }
- std_task_position[i] = std_task_position[i] + sqrt(temp/(num_inst[i]-1))*num_cpus;
- }
+ }
+ // add the task lengths to the average for the batch
+ // weigthed by the number of cpus for that genotype
+ for (int i = 0; i < num_cols; i++) {
+ av_task_length[i] = av_task_length[i] + num_cpus * task_length[i];
+ }
+
+ // calculate the Standard Deviation in the mean position of the task
+ for (int i = 0; i < num_cols; i++) {
+ for (int j = 0; j < max_line; j++) {
+ if (mod_matrix(i,j)>0) sum[i] = sum[i] + j;
+ }
+ }
+
+ double temp = 0;
+ for (int i = 0; i < num_cols; i++) {
+ if (num_inst[i]>1) {
+ double av_sum = sum[i]/num_inst[i];
+ for (int j = 0; j < max_line; j++) {
+ if (mod_matrix(i,j)>0) temp = (av_sum - j)*(av_sum - j);
+ }
+ std_task_position[i] = std_task_position[i] + sqrt(temp/(num_inst[i]-1))*num_cpus;
}
-
- for (int i = 0; i < max_line; i++) { inst_task[num_task[i]]++ ;}
- for (int i = 0; i < num_cols+1; i++) { av_inst_task[i] = av_inst_task[i] + inst_task[i] * num_cpus;}
-
+ }
+
+ for (int i = 0; i < max_line; i++) { inst_task[num_task[i]]++ ;}
+ for (int i = 0; i < num_cols+1; i++) { av_inst_task[i] = av_inst_task[i] + inst_task[i] * num_cpus;}
+
}
} // this is the end of the loop going though all the organisms
@@ -5243,7 +5236,7 @@
for (int i = 0; i < 8+4*num_cols+1; i++) {fp << "0 ";}
fp << endl;
}
- }
+}
void cAnalyze::CommandAnalyzeModularity(cString cur_string)
Modified: branches/collect/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- branches/collect/source/analyze/cAnalyzeGenotype.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/analyze/cAnalyzeGenotype.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -40,13 +40,15 @@
#include "cWorld.h"
#include "cWorldDriver.h"
+#include "tAutoRelease.h"
+
#include <cmath>
using namespace std;
cAnalyzeGenotype::cAnalyzeGenotype(cWorld* world, cString symbol_string, cInstSet& in_inst_set)
: m_world(world)
, genome(symbol_string)
- , inst_set(in_inst_set)
+ , m_inst_set(in_inst_set)
, name("")
, aligned_sequence("")
, tag("")
@@ -86,11 +88,11 @@
// Make sure that the sequences jive with the inst_set
for (int i = 0; i < genome.GetSize(); i++) {
- if (genome[i].GetOp() >= inst_set.GetSize()) {
+ if (genome[i].GetOp() >= m_inst_set.GetSize()) {
cString msg("Trying to load instruction ");
msg += genome[i].GetOp();
msg += ". Max in set is";
- msg += (inst_set.GetSize() - 1);
+ msg += (m_inst_set.GetSize() - 1);
m_world->GetDriver().RaiseException(msg);
}
}
@@ -99,7 +101,7 @@
cAnalyzeGenotype::cAnalyzeGenotype(cWorld* world, const cGenome& _genome, cInstSet& in_inst_set)
: m_world(world)
, genome(_genome)
- , inst_set(in_inst_set)
+ , m_inst_set(in_inst_set)
, name("")
, aligned_sequence("")
, tag("")
@@ -141,7 +143,7 @@
cAnalyzeGenotype::cAnalyzeGenotype(const cAnalyzeGenotype& _gen)
: m_world(_gen.m_world)
, genome(_gen.genome)
- , inst_set(_gen.inst_set)
+ , m_inst_set(_gen.m_inst_set)
, name(_gen.name)
, aligned_sequence(_gen.aligned_sequence)
, tag(_gen.tag)
@@ -227,7 +229,7 @@
// Calculate the base fitness for the genotype we're working with...
// (This may not have been run already, and cost negligiably more time
// considering the number of knockouts we need to do.
- cAnalyzeGenotype base_genotype(m_world, genome, inst_set);
+ cAnalyzeGenotype base_genotype(m_world, genome, m_inst_set);
base_genotype.Recalculate(ctx);
double base_fitness = base_genotype.GetFitness();
const tArray<int> base_task_counts( base_genotype.GetTaskCounts() );
@@ -242,7 +244,7 @@
cGenome mod_genome(genome);
// Setup a NULL instruction in a special inst set.
- cInstSet ko_inst_set(inst_set);
+ cInstSet ko_inst_set(m_inst_set);
const cInstruction null_inst = ko_inst_set.ActivateNullInst();
// If we are keeping track of the specific effects on tasks from the
@@ -362,7 +364,7 @@
void cAnalyzeGenotype::CheckLand() const
{
if (m_land == NULL) {
- m_land = new cLandscape(m_world, genome, inst_set);
+ m_land = new cLandscape(m_world, genome, m_inst_set);
m_land->SetDistance(1);
m_land->Process(m_world->GetDefaultContext());
}
@@ -371,8 +373,11 @@
void cAnalyzeGenotype::CheckPhenPlast() const
{
// Implicit genotype recalculation if required
- if (m_phenplast_stats == NULL){
- cPhenPlastGenotype pp(genome, 1000, m_world, m_world->GetDefaultContext());
+ if (m_phenplast_stats == NULL) {
+ cCPUTestInfo test_info;
+ test_info.SetInstSet(&m_inst_set);
+
+ cPhenPlastGenotype pp(genome, 1000, test_info, m_world, m_world->GetDefaultContext());
SummarizePhenotypicPlasticity(pp);
}
}
@@ -396,34 +401,26 @@
void cAnalyzeGenotype::CalcLandscape(cAvidaContext& ctx)
{
- if (m_land == NULL) m_land = new cLandscape(m_world, genome, inst_set);
+ if (m_land == NULL) m_land = new cLandscape(m_world, genome, m_inst_set);
m_land->SetDistance(1);
m_land->Process(ctx);
}
void cAnalyzeGenotype::Recalculate(cAvidaContext& ctx, cCPUTestInfo* test_info, cAnalyzeGenotype* parent_genotype, int num_trials)
{
- //Allocate our own test info if it wasn't provided
- cCPUTestInfo* temp_test_info = NULL;
+ // Allocate our own test info if it wasn't provided
+ tAutoRelease<cCPUTestInfo> local_test_info;
if (!test_info)
{
- temp_test_info = new cCPUTestInfo();
- test_info = temp_test_info;
+ test_info = new cCPUTestInfo();
+ local_test_info.Set(test_info);
}
- // @DMB - This does some 'interesting' things with the instruction set
- // Use the inst lib for this genotype... and syncrhonize environment
-
- // Backup old instruction set, update with new
- cInstSet env_inst_set_backup = m_world->GetHardwareManager().GetInstSet();
- m_world->GetHardwareManager().GetInstSet() = inst_set;
+ test_info->SetInstSet(&m_inst_set);
// Handling recalculation here
cPhenPlastGenotype recalc_data(genome, num_trials, *test_info, m_world, ctx);
- // Restore the instruction set
- m_world->GetHardwareManager().GetInstSet() = env_inst_set_backup;
-
// The most likely phenotype will be assigned to the phenotype stats
const cPlasticPhenotype* likely_phenotype = recalc_data.GetMostLikelyPhenotype();
@@ -451,17 +448,12 @@
fitness_ratio = GetFitness() / parent_genotype->GetFitness();
efficiency_ratio = GetEfficiency() / parent_genotype->GetEfficiency();
comp_merit_ratio = GetCompMerit() / parent_genotype->GetCompMerit();
- parent_dist = cStringUtil::EditDistance(genome.AsString(),
- parent_genotype->GetGenome().AsString(), parent_muts);
+ parent_dist = cStringUtil::EditDistance(genome.AsString(), parent_genotype->GetGenome().AsString(), parent_muts);
ancestor_dist = parent_genotype->GetAncestorDist() + parent_dist;
}
// Summarize plasticity information if multiple recalculations performed
- if (num_trials > 1)
- SummarizePhenotypicPlasticity(recalc_data);
-
- //Deallocate if we created
- if (temp_test_info) delete temp_test_info;
+ if (num_trials > 1) SummarizePhenotypicPlasticity(recalc_data);
}
Modified: branches/collect/source/analyze/cAnalyzeGenotype.h
===================================================================
--- branches/collect/source/analyze/cAnalyzeGenotype.h 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/analyze/cAnalyzeGenotype.h 2008-08-26 17:56:50 UTC (rev 2760)
@@ -103,7 +103,7 @@
private:
cWorld* m_world;
cGenome genome; // Full Genome
- cInstSet& inst_set; // Instruction set used in this genome
+ cInstSet& m_inst_set; // Instruction set used in this genome
cString name; // Name, if one was provided in loading
cString aligned_sequence; // Sequence (in ASCII) after alignment
cString tag; // All genotypes in a batch can be tagged
@@ -230,8 +230,8 @@
public:
- cAnalyzeGenotype(cWorld* world, cString symbol_string, cInstSet & in_inst_set);
- cAnalyzeGenotype(cWorld* world, const cGenome & _genome, cInstSet & in_inst_set);
+ cAnalyzeGenotype(cWorld* world, cString symbol_string, cInstSet& in_inst_set);
+ cAnalyzeGenotype(cWorld* world, const cGenome& _genome, cInstSet& in_inst_set);
cAnalyzeGenotype(const cAnalyzeGenotype & _gen);
~cAnalyzeGenotype();
Modified: branches/collect/source/cpu/cCPUTestInfo.cc
===================================================================
--- branches/collect/source/cpu/cCPUTestInfo.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/cpu/cCPUTestInfo.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -33,11 +33,11 @@
cCPUTestInfo::cCPUTestInfo(int max_tests)
: generation_tests(max_tests) // These vars not reset on Clear()
- , trace_execution(false)
, trace_task_order(false)
, use_random_inputs(false)
, use_manual_inputs(false)
, m_tracer(NULL)
+ , m_inst_set(NULL)
, org_array(max_tests)
, m_res_method(RES_INITIAL)
, m_res(NULL)
@@ -73,13 +73,6 @@
}
-void cCPUTestInfo::SetTraceExecution(cHardwareTracer *tracer)
-{
- trace_execution = (tracer)?(true):(false);
- m_tracer = tracer;
-}
-
-
double cCPUTestInfo::GetGenotypeFitness()
{
if (org_array[0] != NULL) return org_array[0]->GetPhenotype().GetFitness();
Modified: branches/collect/source/cpu/cCPUTestInfo.h
===================================================================
--- branches/collect/source/cpu/cCPUTestInfo.h 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/cpu/cCPUTestInfo.h 2008-08-26 17:56:50 UTC (rev 2760)
@@ -39,6 +39,7 @@
#endif
class cHardwareTracer;
+class cInstSet;
class cOrganism;
class cPhenotype;
class cString;
@@ -57,12 +58,12 @@
private:
// Inputs...
const int generation_tests; // Maximum depth in generations to test
- bool trace_execution; // Should we trace this CPU?
bool trace_task_order; // Should we keep track of ordering of tasks?
bool use_random_inputs; // Should we give the organism random inputs?
bool use_manual_inputs; // Do we have inputs that we must use?
tArray<int> manual_inputs; // if so, use these.
cHardwareTracer* m_tracer;
+ cInstSet* m_inst_set;
// Outputs...
bool is_viable; // Is this organism colony forming?
@@ -94,7 +95,8 @@
void UseRandomInputs(bool _rand=true) { use_random_inputs = _rand; use_manual_inputs = false; }
void UseManualInputs(tArray<int> inputs) {use_manual_inputs = true; use_random_inputs = false; manual_inputs = inputs;}
void ResetInputMode() {use_manual_inputs = false; use_random_inputs = false;}
- void SetTraceExecution(cHardwareTracer *tracer = NULL);
+ void SetTraceExecution(cHardwareTracer* tracer = NULL) { m_tracer = tracer; }
+ void SetInstSet(cInstSet* inst_set = NULL) { m_inst_set = inst_set; }
void SetResourceOptions(int res_method = RES_INITIAL, std::vector<std::pair<int, std::vector<double> > > * res = NULL, int update = 0, int cpu_cycle_offset = 0)
{ m_res_method = (eTestCPUResourceMethod)res_method; m_res = res; m_res_update = update; m_res_cpu_cycle_offset = cpu_cycle_offset; }
@@ -103,7 +105,8 @@
int GetGenerationTests() const { return generation_tests; }
bool GetTraceTaskOrder() const { return trace_task_order; }
bool GetUseRandomInputs() const { return use_random_inputs; }
- bool GetTraceExecution() const { return trace_execution; }
+ bool GetTraceExecution() const { return (m_tracer); }
+ cInstSet* GetInstSet() const { return m_inst_set; }
bool GetUseManualInputs() const { return use_manual_inputs; }
tArray<int> GetTestCPUInputs() const { return used_inputs; }
cHardwareTracer *GetTracer() { return m_tracer; }
Modified: branches/collect/source/cpu/cHardwareExperimental.cc
===================================================================
--- branches/collect/source/cpu/cHardwareExperimental.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/cpu/cHardwareExperimental.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -503,9 +503,12 @@
fp << organism->GetPhenotype().GetCPUCyclesUsed() << " ";
fp << "IP:" << IP().GetPosition() << " ";
+
for (int i = 0; i < NUM_REGISTERS; i++) {
+ sInternalValue& reg = m_threads[m_cur_thread].reg[i];
fp << static_cast<char>('A' + i) << "X:" << GetRegister(i) << " ";
- fp << setbase(16) << "[0x" << GetRegister(i) << "] " << setbase(10);
+ fp << setbase(16) << "[0x" << reg.value << "] " << setbase(10);
+ fp << "(" << reg.from_env << " " << reg.env_component << " " << reg.originated << " " << reg.oldest_component << ") ";
}
// Add some extra information if additional time costs are used for instructions,
@@ -520,6 +523,7 @@
<< "W-Head:" << GetHead(nHardware::HEAD_WRITE).GetPosition() << " "
<< "F-Head:" << GetHead(nHardware::HEAD_FLOW).GetPosition() << " "
<< "RL:" << GetReadLabel().AsString() << " "
+ << "Ex:" << m_last_output
<< endl;
int number_of_stacks = GetNumStacks();
Modified: branches/collect/source/cpu/cHardwareExperimental.h
===================================================================
--- branches/collect/source/cpu/cHardwareExperimental.h 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/cpu/cHardwareExperimental.h 2008-08-26 17:56:50 UTC (rev 2760)
@@ -530,7 +530,7 @@
dest.from_env = false;
dest.originated = m_cycle_count;
dest.oldest_component = src.oldest_component;
- dest.env_component = src.from_env;
+ dest.env_component = src.env_component;
}
Modified: branches/collect/source/cpu/cHardwareManager.cc
===================================================================
--- branches/collect/source/cpu/cHardwareManager.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/cpu/cHardwareManager.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -82,22 +82,22 @@
}
-cHardwareBase* cHardwareManager::Create(cOrganism* in_org)
+cHardwareBase* cHardwareManager::Create(cOrganism* in_org, cInstSet* inst_set)
{
assert(in_org != NULL);
switch (m_type)
{
case HARDWARE_TYPE_CPU_ORIGINAL:
- return new cHardwareCPU(m_world, in_org, m_inst_set);
+ return new cHardwareCPU(m_world, in_org, inst_set);
case HARDWARE_TYPE_CPU_SMT:
- return new cHardwareSMT(m_world, in_org, m_inst_set);
+ return new cHardwareSMT(m_world, in_org, inst_set);
case HARDWARE_TYPE_CPU_TRANSSMT:
- return new cHardwareTransSMT(m_world, in_org, m_inst_set);
+ return new cHardwareTransSMT(m_world, in_org, inst_set);
case HARDWARE_TYPE_CPU_EXPERIMENTAL:
- return new cHardwareExperimental(m_world, in_org, m_inst_set);
+ return new cHardwareExperimental(m_world, in_org, inst_set);
case HARDWARE_TYPE_CPU_GX:
- return new cHardwareGX(m_world, in_org, m_inst_set);
+ return new cHardwareGX(m_world, in_org, inst_set);
default:
return NULL;
}
Modified: branches/collect/source/cpu/cHardwareManager.h
===================================================================
--- branches/collect/source/cpu/cHardwareManager.h 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/cpu/cHardwareManager.h 2008-08-26 17:56:50 UTC (rev 2760)
@@ -61,7 +61,8 @@
cHardwareManager(cWorld* world);
~cHardwareManager() { ; }
- cHardwareBase* Create(cOrganism* in_org);
+ cHardwareBase* Create(cOrganism* in_org, cInstSet* inst_set);
+ inline cHardwareBase* Create(cOrganism* in_org) { return Create(in_org, m_inst_set); }
cTestCPU* CreateTestCPU() { return new cTestCPU(m_world); }
const cInstSet& GetInstSet() const { return *m_inst_set; }
Modified: branches/collect/source/cpu/cTestCPU.cc
===================================================================
--- branches/collect/source/cpu/cTestCPU.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/cpu/cTestCPU.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -359,10 +359,13 @@
if (test_info.org_array[cur_depth] != NULL) {
delete test_info.org_array[cur_depth];
}
- test_info.org_array[cur_depth] = new cOrganism(m_world, ctx, genome);
- cOrganism & organism = *( test_info.org_array[cur_depth] );
- organism.SetOrgInterface(new cTestCPUInterface(this));
- organism.GetPhenotype().SetupInject(genome);
+ cOrganism* organism = NULL;
+
+ if (test_info.GetInstSet()) organism = new cOrganism(m_world, ctx, genome, test_info.GetInstSet());
+ else organism = new cOrganism(m_world, ctx, genome);
+ test_info.org_array[cur_depth] = organism;
+ organism->SetOrgInterface(new cTestCPUInterface(this));
+ organism->GetPhenotype().SetupInject(genome);
// Run the current organism.
ProcessGestation(ctx, test_info, cur_depth);
@@ -377,10 +380,10 @@
// 4: It copied false => we must check the child.
// Case 1: ////////////////////////////////////
- if (organism.GetPhenotype().GetNumDivides() == 0) return false;
+ if (organism->GetPhenotype().GetNumDivides() == 0) return false;
// Case 2: ////////////////////////////////////
- if (organism.GetPhenotype().CopyTrue() == true) {
+ if (organism->GetPhenotype().CopyTrue() == true) {
test_info.depth_found = cur_depth;
test_info.is_viable = true;
return true;
@@ -389,7 +392,7 @@
// Case 3: ////////////////////////////////////
bool is_ancestor = false;
for (int anc_depth = 0; anc_depth < cur_depth; anc_depth++) {
- if (organism.ChildGenome() == test_info.org_array[anc_depth]->GetGenome()){
+ if (organism->ChildGenome() == test_info.org_array[anc_depth]->GetGenome()){
is_ancestor = true;
const int cur_cycle = cur_depth - anc_depth;
if (test_info.max_cycle < cur_cycle) test_info.max_cycle = cur_cycle;
@@ -406,7 +409,7 @@
// If we haven't reached maximum depth yet, check out the child.
if (cur_depth+1 < test_info.generation_tests) {
// Run the child's genome.
- return TestGenome_Body(ctx, test_info, organism.ChildGenome(), cur_depth+1);
+ return TestGenome_Body(ctx, test_info, organism->ChildGenome(), cur_depth+1);
}
// All options have failed; just return false.
Modified: branches/collect/source/main/cDemeCellEvent.cc
===================================================================
--- branches/collect/source/main/cDemeCellEvent.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/main/cDemeCellEvent.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -11,11 +11,11 @@
, m_event_width(x2-x1)
, m_event_height(y2-y1)
, m_active(false)
+ , m_static_pos(static_pos)
, m_dead(false)
- , m_static_pos(static_pos)
+ , m_id_set(false)
, m_deme(deme)
, m_world(world)
- , m_id_set(false)
{
assert(x1 <= x2);
assert(y1 <= y2);
Modified: branches/collect/source/main/cEnvironment.cc
===================================================================
--- branches/collect/source/main/cEnvironment.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/main/cEnvironment.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -1062,7 +1062,7 @@
if (cur_process->GetDemeFraction()) {
deme_bonus = cur_process->GetDemeFraction() * bonus;
bonus = (1-cur_process->GetDemeFraction()) * bonus;
- }
+ }
// Take care of the organism's bonus:
switch (cur_process->GetType()) {
Modified: branches/collect/source/main/cLandscape.cc
===================================================================
--- branches/collect/source/main/cLandscape.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/main/cLandscape.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -38,11 +38,12 @@
#include "cWorld.h"
-cLandscape::cLandscape(cWorld* world, const cGenome & in_genome, const cInstSet & in_inst_set)
+cLandscape::cLandscape(cWorld* world, const cGenome& in_genome, const cInstSet& in_inst_set)
: m_world(world), inst_set(in_inst_set), base_genome(1), peak_genome(1), trials(1), m_min_found(0),
m_max_trials(0), site_count(NULL)
{
Reset(in_genome);
+ test_info.SetInstSet(const_cast<cInstSet*>(&inst_set));
}
cLandscape::~cLandscape()
@@ -777,7 +778,6 @@
pos_frac = GetProbPos();
// Print the information on the current best.
- cCPUTestInfo test_info;
testcpu->TestGenome(ctx, test_info, cur_genome);
cPhenotype& colony_phenotype = test_info.GetColonyOrganism()->GetPhenotype();
df.Write(gen, "Generation");
Modified: branches/collect/source/main/cOrganism.cc
===================================================================
--- branches/collect/source/main/cOrganism.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/main/cOrganism.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -78,10 +78,47 @@
, m_msg(0)
, m_opinion(0)
{
- // Initialization of structures...
m_hardware = m_world->GetHardwareManager().Create(this);
-// m_cpu_stats.Setup();
+ initialize(ctx);
+}
+
+cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome, cInstSet* inst_set)
+ : m_world(world)
+ , m_genotype(NULL)
+ , m_phenotype(world)
+ , m_initial_genome(in_genome)
+ , m_mut_info(world->GetEnvironment().GetMutationLib(), in_genome.GetSize())
+ , m_interface(NULL)
+ , m_lineage_label(-1)
+ , m_lineage(NULL)
+ , m_input_pointer(0)
+ , m_input_buf(world->GetEnvironment().GetInputSize())
+ , m_output_buf(world->GetEnvironment().GetOutputSize())
+ , m_received_messages(RECEIVED_MESSAGES_SIZE)
+ , m_sent_value(0)
+ , m_sent_active(false)
+ , m_test_receive_pos(0)
+ , m_pher_drop(false)
+ , m_max_executed(-1)
+ , m_is_running(false)
+ , m_is_sleeping(false)
+ , m_is_dead(false)
+ , killed_event(false)
+ , m_net(NULL)
+ , m_msg(0)
+ , m_opinion(0)
+{
+ m_hardware = m_world->GetHardwareManager().Create(this, inst_set);
+
+ initialize(ctx);
+}
+
+
+void cOrganism::initialize(cAvidaContext& ctx)
+{
+ m_phenotype.SetInstSetSize(m_hardware->GetInstSet().GetSize());
+
if (m_world->GetConfig().DEATH_METHOD.Get() > DEATH_METHOD_OFF) {
m_max_executed = m_world->GetConfig().AGE_LIMIT.Get();
if (m_world->GetConfig().AGE_DEVIATION.Get() > 0.0) {
@@ -90,7 +127,7 @@
if (m_world->GetConfig().DEATH_METHOD.Get() == DEATH_METHOD_MULTIPLE) {
m_max_executed *= m_initial_genome.GetSize();
}
-
+
// m_max_executed must be positive or an organism will not die!
if (m_max_executed < 1) m_max_executed = 1;
}
@@ -99,7 +136,7 @@
m_rbins.SetAll(0.0);
if (m_world->GetConfig().NET_ENABLED.Get()) m_net = new cNetSupport();
- m_id = m_world->GetStats().GetTotCreatures();
+ m_id = m_world->GetStats().GetTotCreatures();
}
Modified: branches/collect/source/main/cOrganism.h
===================================================================
--- branches/collect/source/main/cOrganism.h 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/main/cOrganism.h 2008-08-26 17:56:50 UTC (rev 2760)
@@ -80,6 +80,7 @@
class cGenotype;
class cHardwareBase;
class cInjectGenotype;
+class cInstSet;
class cLineage;
class cOrgSinkMessage;
class cSaleItem;
@@ -105,10 +106,8 @@
tArray<double> m_rbins; // Holds amount of resources internal to org
// Other stats
+ cCPUMemory m_child_genome; // Child genome, while under construction.
- cCPUMemory m_child_genome; // Child genome, while under construction.
-// sCPUStats m_cpu_stats; // Info for statistics
-
// Input and Output with the environment
int m_input_pointer;
tBuffer<int> m_input_buf;
@@ -145,12 +144,16 @@
};
cNetSupport* m_net;
+
+ void initialize(cAvidaContext& ctx);
+
cOrganism(); // @not_implemented
cOrganism(const cOrganism&); // @not_implemented
cOrganism& operator=(const cOrganism&); // @not_implemented
public:
cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome);
+ cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome, cInstSet* inst_set);
~cOrganism();
// -------- Accessor Methods --------
@@ -190,7 +193,6 @@
int GetMaxExecuted() const { return m_max_executed; }
cCPUMemory& ChildGenome() { return m_child_genome; }
-// sCPUStats& CPUStats() { return m_cpu_stats; }
void SetRunning(bool in_running) { m_is_running = in_running; }
bool IsRunning() { return m_is_running; }
@@ -441,16 +443,5 @@
};
-#ifdef ENABLE_UNIT_TESTS
-namespace nOrganism {
- /**
- * Run unit tests
- *
- * @param full Run full test suite; if false, just the fast tests.
- **/
- void UnitTests(bool full = false);
-}
-#endif
-
#endif
Modified: branches/collect/source/main/cPhenPlastGenotype.cc
===================================================================
--- branches/collect/source/main/cPhenPlastGenotype.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/main/cPhenPlastGenotype.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -26,14 +26,6 @@
#include <iostream>
#include <cmath>
-cPhenPlastGenotype::cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cWorld* world, cAvidaContext& ctx)
-: m_genome(in_genome), m_num_trials(num_trials), m_world(world)
-{
- cCPUTestInfo test_info;
- test_info.UseRandomInputs(true);
- Process(test_info, world, ctx);
-}
-
cPhenPlastGenotype::cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx)
: m_genome(in_genome), m_num_trials(num_trials), m_world(world)
{
Modified: branches/collect/source/main/cPhenPlastGenotype.h
===================================================================
--- branches/collect/source/main/cPhenPlastGenotype.h 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/main/cPhenPlastGenotype.h 2008-08-26 17:56:50 UTC (rev 2760)
@@ -82,7 +82,6 @@
void Process(cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx);
public:
- cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cWorld* world, cAvidaContext& ctx);
cPhenPlastGenotype(const cGenome& in_genome, int num_trails, cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx);
~cPhenPlastGenotype();
Modified: branches/collect/source/main/cPhenotype.cc
===================================================================
--- branches/collect/source/main/cPhenotype.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/main/cPhenotype.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -28,7 +28,6 @@
#include "cEnvironment.h"
#include "cDeme.h"
#include "cHardwareManager.h"
-#include "cInstSet.h"
#include "cReactionResult.h"
#include "cTaskState.h"
#include "cTools.h"
@@ -53,7 +52,6 @@
, cur_rbins_avail(m_world->GetNumResources())
, cur_reaction_count(m_world->GetEnvironment().GetReactionLib().GetSize())
, cur_reaction_add_reward(m_world->GetEnvironment().GetReactionLib().GetSize())
- , cur_inst_count(world->GetHardwareManager().GetInstSet().GetSize())
, cur_sense_count(m_world->GetStats().GetSenseSize())
, sensed_resources(m_world->GetEnvironment().GetResourceLib().GetSize())
, cur_task_time(m_world->GetEnvironment().GetNumTasks()) // Added for tracking time; WRE 03-18-07
@@ -66,7 +64,6 @@
, last_rbins_avail(m_world->GetNumResources())
, last_reaction_count(m_world->GetEnvironment().GetReactionLib().GetSize())
, last_reaction_add_reward(m_world->GetEnvironment().GetReactionLib().GetSize())
- , last_inst_count(world->GetHardwareManager().GetInstSet().GetSize())
, last_sense_count(m_world->GetStats().GetSenseSize())
{
}
@@ -252,7 +249,7 @@
assert(age >= 0);
assert(child_copied_size >= 0);
// assert(to_die == false);
- return true;
+ return (m_world);
}
@@ -1146,259 +1143,6 @@
return true;
}
-
-///// For Loading and Saving State: /////
-
-
-bool cPhenotype::SaveState(ofstream& fp)
-{
- assert(fp.good());
- fp << "cPhenotype" << endl;
-
- fp << merit.GetDouble() << " ";
- fp << genome_length << " ";
- fp << copied_size << " ";
- fp << executed_size << " ";
- fp << gestation_time << " ";
- fp << gestation_start << " ";
- fp << fitness << " ";
- fp << div_type << " ";
-
- fp << cur_bonus << " ";
- fp << cur_num_errors << " ";
- fp << cur_num_donates << " ";
- for (int i = 0; i < cur_task_count.GetSize(); i++) {
- fp << cur_task_count[i] << " ";
- }
- for (int i = 0; i < cur_internal_task_count.GetSize(); i++) {
- fp << cur_internal_task_count[i] << " ";
- }
- for (int i = 0; i < cur_rbins_total.GetSize(); i++) {
- fp << cur_rbins_total[i] << " ";
- }
- for ( int i = 0; i < cur_rbins_avail.GetSize(); i++) {
- fp << cur_rbins_avail[i] << " ";
- }
- for (int i = 0; i < cur_reaction_count.GetSize(); i++) {
- fp << cur_reaction_count[i] << " ";
- }
- for (int i = 0; i < cur_inst_count.GetSize(); i++) {
- fp << cur_inst_count[i] << " ";
- }
-
- fp << last_merit_base << " ";
- fp << last_bonus << " ";
- fp << last_num_errors << " ";
- fp << last_num_donates << " ";
- for (int i = 0; i < last_task_count.GetSize(); i++) {
- fp << last_task_count[i] << " ";
- }
- for (int i = 0; i < last_internal_task_count.GetSize(); i++) {
- fp << last_internal_task_count[i] << " ";
- }
- for (int i = 0; i < last_rbins_total.GetSize(); i++) {
- fp << last_rbins_total[i] << " ";
- }
- for ( int i = 0; i < last_rbins_avail.GetSize(); i++) {
- fp << last_rbins_avail[i] << " ";
- }
- for (int i = 0; i < last_reaction_count.GetSize(); i++) {
- fp << last_reaction_count[i] << " ";
- }
- for (int i = 0; i < last_inst_count.GetSize(); i++) {
- fp << last_inst_count[i] << " ";
- }
-
- fp << num_divides << " ";
- fp << generation << " ";
- fp << cpu_cycles_used << " ";
- fp << time_used << " ";
- fp << age << " ";
- fp << neutral_metric << " ";
- fp << life_fitness << " ";
-
- fp << is_injected << " ";
- fp << is_donor_last << " ";
- fp << is_donor_cur << " ";
- fp << is_donor_rand_last << " ";
- fp << is_donor_rand << " ";
- fp << is_donor_null_last << " ";
- fp << is_donor_null << " ";
- fp << is_donor_kin_last << " ";
- fp << is_donor_kin << " ";
- fp << is_donor_edit_last << " ";
- fp << is_donor_edit << " ";
- fp << is_donor_gbg_last << " ";
- fp << is_donor_gbg << " ";
- fp << is_donor_truegb_last << " ";
- fp << is_donor_truegb << " ";
- fp << is_donor_threshgb_last << " ";
- fp << is_donor_threshgb << " ";
- fp << is_donor_quanta_threshgb_last << " ";
- fp << is_donor_quanta_threshgb << " ";
- fp << num_thresh_gb_donations_last << " ";
- fp << num_thresh_gb_donations << " ";
- fp << num_quanta_thresh_gb_donations_last << " ";
- fp << num_quanta_thresh_gb_donations << " ";
-
- fp << is_receiver_last << " ";
- fp << is_receiver << " ";
- fp << is_receiver_rand << " ";
- fp << is_receiver_kin << " ";
- fp << is_receiver_kin_last << " ";
- fp << is_receiver_edit << " ";
- fp << is_receiver_edit_last << " ";
- fp << is_receiver_gbg << " ";
- fp << is_receiver_truegb_last << " ";
- fp << is_receiver_truegb << " ";
- fp << is_receiver_threshgb_last << " ";
- fp << is_receiver_threshgb << " ";
- fp << is_receiver_quanta_threshgb_last << " ";
- fp << is_receiver_quanta_threshgb << " ";
- fp << is_modifier << " ";
- fp << is_modified << " ";
- fp << is_fertile << " ";
- fp << is_mutated << " ";
- fp << parent_true << " ";
- fp << parent_sex << " ";
- fp << parent_cross_num << " ";
-
- fp << copy_true << " ";
- fp << divide_sex << " ";
- fp << mate_select_id << " ";
- fp << cross_num << " ";
- fp << child_fertile << " ";
- fp << last_child_fertile << " ";
-
- fp << endl;
- return true;
-}
-
-
-bool cPhenotype::LoadState(ifstream & fp)
-{
- double tmp_merit;
- assert(fp.good());
- if( !fp.good() ) return false;
-
- fp >> tmp_merit; merit = tmp_merit;
- fp >> genome_length;
- fp >> copied_size;
- fp >> executed_size;
- fp >> gestation_time;
- fp >> gestation_start;
- fp >> fitness;
- fp >> div_type;
-
- fp >> cur_bonus;
- fp >> cur_num_errors;
- fp >> cur_num_donates;
-
- for (int i = 0; i < cur_task_count.GetSize(); i++) {
- fp >> cur_task_count[i];
- }
- for (int i = 0; i < cur_internal_task_count.GetSize(); i++) {
- fp >> cur_internal_task_count[i];
- }
- for (int i = 0; i < cur_rbins_total.GetSize(); i++) {
- fp >> cur_rbins_total[i];
- }
- for (int i = 0; i < cur_rbins_avail.GetSize(); i++) {
- fp >> cur_rbins_avail[i];
- }
- for (int i = 0; i < cur_reaction_count.GetSize(); i++) {
- fp >> cur_reaction_count[i];
- }
- for (int i = 0; i < cur_inst_count.GetSize(); i++) {
- fp >> cur_inst_count[i];
- }
-
- fp >> last_merit_base;
- fp >> last_bonus;
- fp >> last_num_errors;
- fp >> last_num_donates;
- for (int i = 0; i < last_task_count.GetSize(); i++) {
- fp >> last_task_count[i];
- }
- for (int i = 0; i < last_internal_task_count.GetSize(); i++) {
- fp >> last_internal_task_count[i];
- }
- for (int i = 0; i < last_rbins_total.GetSize(); i++) {
- fp >> last_rbins_total[i];
- }
- for (int i = 0; i < last_rbins_avail.GetSize(); i++) {
- fp >> last_rbins_avail[i];
- }
- for (int i = 0; i < last_reaction_count.GetSize(); i++) {
- fp >> last_reaction_count[i];
- }
- for (int i = 0; i < last_inst_count.GetSize(); i++) {
- fp >> last_inst_count[i];
- }
-
- fp >> num_divides;
- fp >> generation;
- fp >> cpu_cycles_used;
- fp >> time_used;
- fp >> age;
- fp >> neutral_metric;
- fp >> life_fitness;
-
- fp >> is_injected;
- fp >> is_donor_last;
- fp >> is_donor_cur;
- fp >> is_donor_rand_last;
- fp >> is_donor_rand;
- fp >> is_donor_null_last;
- fp >> is_donor_null;
- fp >> is_donor_kin_last;
- fp >> is_donor_kin;
- fp >> is_donor_edit_last;
- fp >> is_donor_edit;
- fp >> is_donor_gbg_last;
- fp >> is_donor_gbg;
- fp >> is_donor_truegb_last;
- fp >> is_donor_truegb;
- fp >> is_donor_threshgb_last;
- fp >> is_donor_threshgb;
- fp >> is_donor_quanta_threshgb_last;
- fp >> is_donor_quanta_threshgb;
- fp >> num_thresh_gb_donations_last;
- fp >> num_thresh_gb_donations;
- fp >> num_quanta_thresh_gb_donations_last;
- fp >> num_quanta_thresh_gb_donations;
- fp >> is_receiver_last;
- fp >> is_receiver;
- fp >> is_receiver_rand;
- fp >> is_receiver_kin;
- fp >> is_receiver_kin_last;
- fp >> is_receiver_edit;
- fp >> is_receiver_edit_last;
- fp >> is_receiver_gbg;
- fp >> is_receiver_truegb_last;
- fp >> is_receiver_truegb;
- fp >> is_receiver_threshgb_last;
- fp >> is_receiver_threshgb;
- fp >> is_receiver_quanta_threshgb_last;
- fp >> is_receiver_quanta_threshgb;
- fp >> is_modifier;
- fp >> is_modified;
- fp >> is_fertile;
- fp >> is_mutated;
- fp >> parent_true;
- fp >> parent_sex;
- fp >> parent_cross_num;
-
- fp >> copy_true;
- fp >> divide_sex;
- fp >> mate_select_id;
- fp >> cross_num;
- fp >> child_fertile;
- fp >> last_child_fertile;
-
- return true;
-}
-
void cPhenotype::PrintStatus(ostream& fp) const
{
fp << " MeritBase:"
Modified: branches/collect/source/main/cPhenotype.h
===================================================================
--- branches/collect/source/main/cPhenotype.h 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/main/cPhenotype.h 2008-08-26 17:56:50 UTC (rev 2760)
@@ -86,6 +86,7 @@
class cPhenotype
{
+ friend class cOrganism;
private:
cWorld* m_world;
bool initialized;
@@ -226,12 +227,20 @@
// 7. Information that is set once (when organism was born)
double permanent_germline_propensity;
+
+ inline void SetInstSetSize(int inst_set_size);
+
+
+ cPhenotype(cWorld* world);
+
+
public:
- cPhenotype() { ; } // @not_implemented
- cPhenotype(cWorld* world);
+ cPhenotype() : m_world(NULL) { ; } // Will not construct a valid cPhenotype! Only exists to support incorrect cDeme tArray usage.
+
cPhenotype(const cPhenotype&);
cPhenotype& operator=(const cPhenotype&);
~cPhenotype();
+
bool OK();
@@ -258,8 +267,6 @@
tArray<int>& insts_triggered);
// State saving and loading, and printing...
- bool SaveState(std::ofstream& fp);
- bool LoadState(std::ifstream & fp);
void PrintStatus(std::ostream& fp) const;
// Some useful methods...
@@ -503,15 +510,10 @@
};
-#ifdef ENABLE_UNIT_TESTS
-namespace nPhenotype {
- /**
- * Run unit tests
- *
- * @param full Run full test suite; if false, just the fast tests.
- **/
- void UnitTests(bool full = false);
+inline void cPhenotype::SetInstSetSize(int inst_set_size)
+{
+ cur_inst_count.Resize(inst_set_size, 0);
+ last_inst_count.Resize(inst_set_size, 0);
}
-#endif
#endif
Modified: branches/collect/source/main/cTaskLib.cc
===================================================================
--- branches/collect/source/main/cTaskLib.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/main/cTaskLib.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -49,6 +49,11 @@
# define log2(x) (log(x)/log(2.0))
#endif
+// Various workarounds for FreeBSD
+#if AVIDA_PLATFORM(FREEBSD)
+# define log2(x) (log(x)/log(2.0))
+#endif
+
static const double dCastPrecision = 100000.0;
Modified: branches/collect/source/platform/platform.h
===================================================================
--- branches/collect/source/platform/platform.h 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/platform/platform.h 2008-08-26 17:56:50 UTC (rev 2760)
@@ -39,11 +39,15 @@
# pragma warning( disable : 4355 )
#endif
-#if defined(__APPLE__) || defined(unix) || defined(__unix) || defined(__unix__) || defined (__NetBSD__) || defined(_AIX)
+#if defined(__APPLE__) || defined(unix) || defined(__unix) || defined(__unix__) || defined (__NetBSD__) || defined(_AIX) || defined(__FreeBSD__)
# define AVIDA_PLATFORM_UNIX 1
# define AVIDA_PLATFORM_THREADS 1
#endif
+#if defined(__FreeBSD__)
+# define AVIDA_PLATFORM_FREEBSD 1
+#endif
+
#if defined(__APPLE__)
# define AVIDA_PLATFORM_APPLE 1
#endif
Modified: branches/collect/source/tools/cDataFileManager.cc
===================================================================
--- branches/collect/source/tools/cDataFileManager.cc 2008-08-26 14:52:57 UTC (rev 2759)
+++ branches/collect/source/tools/cDataFileManager.cc 2008-08-26 17:56:50 UTC (rev 2760)
@@ -70,12 +70,13 @@
// Determine directory prefix, default being the current data directory
cString dir_prefix(m_target_dir);
- if (target[0] == '.' && // Must start with '.' to trigger further testing
- (target.GetSize() == 1 || // If string is exactly "."
- (target.GetSize() > 1 && // or if it ".." or "./" or ".\"
- (target[1] == '.' || target[1] == '/' || target[1] == '\\')
+ if ((target[0] == '.' && // Must start with '.' to trigger further testing
+ (target.GetSize() == 1 || // If string is exactly "."
+ (target.GetSize() > 1 && // or if it ".." or "./" or ".\"
+ (target[1] == '.' || target[1] == '/' || target[1] == '\\')
+ )
)
- )
+ ) || target[0] == '/' // If it is an absolute path, ignore prefix as well
)
{
// Treat path as current working directory relative
@@ -95,7 +96,11 @@
if (d == -1) break;
// If directory name is not null
- if (d - i > 0) cTools::MkDir(dir_prefix + target.Substring(0, d - i), false);
+ if (d - i > 0) {
+ cString dir = target.Substring(i, d - i);
+ // Create if that this directory is not a relative path component
+ if (dir.GetSize() > 2 || (dir != "." && dir != "..")) cTools::MkDir(dir_prefix + target.Substring(0, d), false);
+ }
// Adjust next directory name starting point
i = d + 1;
More information about the Avida-cvs
mailing list