[Avida-SVN] r1058 - in development: Avida.xcodeproj source/actions source/cpu source/main
barrick at myxo.css.msu.edu
barrick at myxo.css.msu.edu
Sun Oct 22 15:04:22 PDT 2006
Author: barrick
Date: 2006-10-22 18:04:22 -0400 (Sun, 22 Oct 2006)
New Revision: 1058
Modified:
development/Avida.xcodeproj/project.pbxproj
development/source/actions/PrintActions.cc
development/source/cpu/cHardwareCPU.cc
development/source/main/cPhenotype.cc
development/source/main/cPhenotype.h
development/source/main/cPopulation.cc
development/source/main/cStats.cc
development/source/main/cStats.h
Log:
Added ability to generate data files sense.dat and sense_exe.dat with information on how the sense instruction is being used. Fixed a bug introduced into the sense command that had made it always sum all resources regardless of the modifying label.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2006-10-20 19:27:30 UTC (rev 1057)
+++ development/Avida.xcodeproj/project.pbxproj 2006-10-22 22:04:22 UTC (rev 1058)
@@ -951,7 +951,7 @@
DCC315CF076253A5008F7A48 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
DCC315D0076253A5008F7A48 /* task_event_gen.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.cc; sourceTree = "<group>"; };
DCC315D1076253A5008F7A48 /* task_event_gen.old.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.old.cc; sourceTree = "<group>"; };
- DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
+ DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2006-10-20 19:27:30 UTC (rev 1057)
+++ development/source/actions/PrintActions.cc 2006-10-22 22:04:22 UTC (rev 1058)
@@ -63,8 +63,11 @@
STATS_OUT_FILE(PrintDominantParaData, parasite.dat );
STATS_OUT_FILE(PrintInstructionData, instruction.dat );
STATS_OUT_FILE(PrintGenotypeMap, genotype_map.m );
-STATS_OUT_FILE(PrintMarketData, market.dat );
+STATS_OUT_FILE(PrintMarketData, market.dat );
+STATS_OUT_FILE(PrintSenseData, sense.dat );
+STATS_OUT_FILE(PrintSenseExeData, sense_exe.dat );
+
#define POP_OUT_FILE(METHOD, DEFAULT) /* 1 */ \
class cAction ## METHOD : public cAction { /* 2 */ \
private: /* 3 */ \
@@ -1475,7 +1478,9 @@
action_lib->Register<cActionPrintInstructionData>("PrintInstructionData");
action_lib->Register<cActionPrintGenotypeMap>("PrintGenotypeMap");
action_lib->Register<cActionPrintMarketData>("PrintMarketData");
-
+ action_lib->Register<cActionPrintSenseData>("PrintSenseData");
+ action_lib->Register<cActionPrintSenseExeData>("PrintSenseExeData");
+
// Population Out Files
action_lib->Register<cActionPrintPhenotypeData>("PrintPhenotypeData");
action_lib->Register<cActionPrintPhenotypeStatus>("PrintPhenotypeStatus");
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2006-10-20 19:27:30 UTC (rev 1057)
+++ development/source/cpu/cHardwareCPU.cc 2006-10-22 22:04:22 UTC (rev 1058)
@@ -213,8 +213,8 @@
"Output ?BX?, and input new number back into ?BX?, and push 1,0,\
or -1 onto stack1 if merit increased, stayed the same, or decreased"),
cInstEntryCPU("match-strings", &cHardwareCPU::Inst_MatchStrings),
- cInstEntryCPU("sell", &cHardwareCPU::Inst_Sell),
- cInstEntryCPU("buy", &cHardwareCPU::Inst_Buy),
+ cInstEntryCPU("sell", &cHardwareCPU::Inst_Sell),
+ cInstEntryCPU("buy", &cHardwareCPU::Inst_Buy),
cInstEntryCPU("send", &cHardwareCPU::Inst_Send),
cInstEntryCPU("receive", &cHardwareCPU::Inst_Receive),
cInstEntryCPU("sense", &cHardwareCPU::Inst_Sense),
@@ -2749,10 +2749,11 @@
// Only recalculate logs if these values have changed
static int last_num_resources = 0;
static int max_label_length = 0;
-
+ int num_nops = GetInstSet().GetNumNops();
+
if ((last_num_resources != res_count.GetSize()))
{
- int max_label_length = (int) ceil(log((float) res_count.GetSize())/log((float) cHardwareCPU::NUM_NOPS));
+ max_label_length = (int)ceil(log(res_count.GetSize())/log(num_nops));
last_num_resources = res_count.GetSize();
}
@@ -2781,11 +2782,11 @@
for (int i = 0; i < max_label_length - real_label_length; i++)
{
start_label.AddNop(0);
- end_label.AddNop(cHardwareCPU::NUM_NOPS-1);
+ end_label.AddNop(num_nops-1);
}
- int start_index = start_label.AsInt(cHardwareCPU::NUM_NOPS);
- int end_index = end_label.AsInt(cHardwareCPU::NUM_NOPS);
+ int start_index = start_label.AsInt(num_nops);
+ int end_index = end_label.AsInt(num_nops);
// If the label refers to ONLY resources that
// do not exist, then the operation fails
@@ -2806,6 +2807,17 @@
//Dump this value into an arbitrary register: BX
GetRegister(reg_to_set) = resource_result;
+ //We have to convert this to a different index that includes all degenerate labels possible: shortest to longest
+ int sensed_index = 0;
+ int on = 1;
+ for (int i = 0; i < real_label_length; i++)
+ {
+ sensed_index += on;
+ on *= num_nops;
+ }
+ sensed_index+= GetLabel().AsInt(num_nops);
+ organism->GetPhenotype().IncSenseCount(sensed_index);
+
return true;
// Note that we are converting <double> resources to <int> register values
Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc 2006-10-20 19:27:30 UTC (rev 1057)
+++ development/source/main/cPhenotype.cc 2006-10-22 22:04:22 UTC (rev 1058)
@@ -28,11 +28,13 @@
, cur_task_quality(m_world->GetEnvironment().GetTaskLib().GetSize())
, cur_reaction_count(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())
, last_task_count(m_world->GetEnvironment().GetTaskLib().GetSize())
, last_task_quality(m_world->GetEnvironment().GetTaskLib().GetSize())
, last_reaction_count(m_world->GetEnvironment().GetReactionLib().GetSize())
, last_inst_count(world->GetHardwareManager().GetInstSet().GetSize())
+ , last_sense_count(m_world->GetStats().GetSenseSize())
{
}
@@ -103,10 +105,10 @@
cur_task_quality.SetAll(0);
cur_reaction_count.SetAll(0);
cur_inst_count.SetAll(0);
+ cur_sense_count.SetAll(0);
for (int j = 0; j < sensed_resources.GetSize(); j++)
sensed_resources[j] = parent_phenotype.sensed_resources[j];
-
// Copy last values from parent
last_merit_base = parent_phenotype.last_merit_base;
last_bonus = parent_phenotype.last_bonus;
@@ -116,8 +118,10 @@
last_task_quality = parent_phenotype.last_task_quality;
last_reaction_count = parent_phenotype.last_reaction_count;
last_inst_count = parent_phenotype.last_inst_count;
+ last_sense_count = parent_phenotype.last_sense_count;
last_fitness = last_merit_base * last_bonus / gestation_time;
+
// Setup other miscellaneous values...
num_divides = 0;
generation = parent_phenotype.generation;
@@ -188,6 +192,7 @@
cur_reaction_count.SetAll(0);
cur_inst_count.SetAll(0);
sensed_resources.SetAll(0);
+ cur_sense_count.SetAll(0);
// Copy last values from parent
last_merit_base = _length;
@@ -197,7 +202,7 @@
last_task_count.SetAll(0);
last_task_quality.SetAll(0);
last_reaction_count.SetAll(0);
- last_inst_count.SetAll(0);
+ last_sense_count.SetAll(0);
// Setup other miscellaneous values...
num_divides = 0;
@@ -278,6 +283,7 @@
last_task_quality = cur_task_quality;
last_reaction_count = cur_reaction_count;
last_inst_count = cur_inst_count;
+ last_sense_count = cur_sense_count;
// Reset cur values.
cur_bonus = m_world->GetConfig().DEFAULT_BONUS.Get();
@@ -287,6 +293,7 @@
cur_task_quality.SetAll(0);
cur_reaction_count.SetAll(0);
cur_inst_count.SetAll(0);
+ cur_sense_count.SetAll(0);
// Setup other miscellaneous values...
num_divides++;
@@ -365,6 +372,7 @@
last_task_quality = cur_task_quality;
last_reaction_count = cur_reaction_count;
last_inst_count = cur_inst_count;
+ last_sense_count = cur_sense_count;
// Reset cur values.
cur_bonus = m_world->GetConfig().DEFAULT_BONUS.Get();
@@ -374,6 +382,7 @@
cur_task_quality.SetAll(0);
cur_reaction_count.SetAll(0);
cur_inst_count.SetAll(0);
+ cur_sense_count.SetAll(0);
sensed_resources.SetAll(-1.0);
// Setup other miscellaneous values...
@@ -446,6 +455,7 @@
cur_task_count.SetAll(0);
cur_reaction_count.SetAll(0);
cur_inst_count.SetAll(0);
+ cur_sense_count.SetAll(0);
for (int j = 0; j < sensed_resources.GetSize(); j++)
sensed_resources[j] = clone_phenotype.sensed_resources[j];
@@ -458,6 +468,7 @@
last_task_count = clone_phenotype.last_task_count;
last_reaction_count = clone_phenotype.last_reaction_count;
last_inst_count = clone_phenotype.last_inst_count;
+ last_sense_count = clone_phenotype.last_sense_count;
last_fitness = last_merit_base * last_bonus / gestation_time;
// Setup other miscellaneous values...
Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h 2006-10-20 19:27:30 UTC (rev 1057)
+++ development/source/main/cPhenotype.h 2006-10-22 22:04:22 UTC (rev 1058)
@@ -80,7 +80,8 @@
tArray<int> cur_task_count; // Total times each task was performed
tArray<double> cur_task_quality; // Average (total?) quality with which each task was performed
tArray<int> cur_reaction_count; // Total times each reaction was triggered.
- tArray<int> cur_inst_count; // Intruction exection counter
+ tArray<int> cur_inst_count; // Intsruction exection counter
+ tArray<int> cur_sense_count; // Total times resource combinations have been sensed; JEB 10-22-06
tArray<double> sensed_resources; // Resources of which the organism is explictly aware
// 3. These mark the status of "in progess" variables at the last divide.
@@ -91,7 +92,8 @@
tArray<int> last_task_count;
tArray<double> last_task_quality;
tArray<int> last_reaction_count;
- tArray<int> last_inst_count; // Intruction exection counter
+ tArray<int> last_inst_count; // Instruction exection counter
+ tArray<int> last_sense_count; // Total times resource combinations have been sensed; JEB 10-22-06
double last_fitness; // Used to determine sterilization.
// 4. Records from this organisms life...
@@ -197,6 +199,7 @@
const tArray<double> & GetCurTaskQuality() const { assert(initialized == true); return cur_task_quality; }
const tArray<int>& GetCurReactionCount() const { assert(initialized == true); return cur_reaction_count;}
const tArray<int>& GetCurInstCount() const { assert(initialized == true); return cur_inst_count; }
+ const tArray<int>& GetCurSenseCount() const { assert(initialized == true); return cur_sense_count; }
double GetSensedResource(int _in) { assert(initialized == true); return sensed_resources[_in]; }
@@ -209,6 +212,7 @@
const tArray<double> & GetLastTaskQuality() const { assert(initialized == true); return last_task_quality; }
const tArray<int>& GetLastReactionCount() const { assert(initialized == true); return last_reaction_count; }
const tArray<int>& GetLastInstCount() const { assert(initialized == true); return last_inst_count; }
+ const tArray<int>& GetLastSenseCount() const { assert(initialized == true); return last_sense_count; }
double GetLastFitness() const { assert(initialized == true); return last_fitness; }
int GetNumDivides() const { assert(initialized == true); return num_divides;}
@@ -267,6 +271,7 @@
void IncTimeUsed() { assert(initialized == true); time_used++; }
void IncErrors() { assert(initialized == true); cur_num_errors++; }
void IncDonates() { assert(initialized == true); cur_num_donates++; }
+ void IncSenseCount(const int i) { assert(initialized == true); cur_sense_count[i]++; }
bool& IsInjected() { assert(initialized == true); return is_injected; }
bool& IsParasite() { assert(initialized == true); return is_parasite; }
bool& IsModifier() { assert(initialized == true); return is_modifier; }
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2006-10-20 19:27:30 UTC (rev 1057)
+++ development/source/main/cPopulation.cc 2006-10-22 22:04:22 UTC (rev 1058)
@@ -1307,13 +1307,22 @@
}
}
+ // Test what resource combinations this creature has sensed
+ for (int j=0; j < stats.GetSenseSize(); j++) {
+ if (phenotype.GetLastSenseCount()[j] > 0)
+ {
+ stats.AddLastSense(j);
+ stats.IncLastSenseExeCount(j, phenotype.GetLastSenseCount()[j]);
+ }
+ }
+
// Increment the counts for all qualities the organism has...
if (phenotype.ParentTrue()) num_breed_true++;
if (phenotype.IsParasite()) num_parasites++;
if( phenotype.GetNumDivides() == 0 ) num_no_birth++;
if(phenotype.IsMultiThread()) num_multi_thread++;
else num_single_thread++;
- if(phenotype.IsModified()) num_modified++;
+ if(phenotype.IsModified()) num_modified++;
// Hardware specific collections...
if (organism->GetHardware().GetType() == HARDWARE_TYPE_CPU_ORIGINAL) {
Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc 2006-10-20 19:27:30 UTC (rev 1057)
+++ development/source/main/cStats.cc 2006-10-22 22:04:22 UTC (rev 1058)
@@ -16,6 +16,7 @@
#include "tDataEntry.h"
#include "cWorld.h"
#include "cWorldDriver.h"
+#include "cHardwareManager.h"
#include <float.h>
#include <math.h>
@@ -87,6 +88,7 @@
, num_sold(0)
, num_used(0)
, num_own_used(0)
+ , sense_size(0)
{
task_cur_count.Resize( m_world->GetNumTasks() );
task_last_count.Resize( m_world->GetNumTasks() );
@@ -111,8 +113,6 @@
#endif
inst_names.Resize( m_world->GetNumInstructions() );
-
-
reaction_count.Resize( m_world->GetNumReactions() );
reaction_count.SetAll(0);
@@ -123,6 +123,42 @@
reaction_names.Resize( m_world->GetNumReactions() );
resource_names.Resize( m_world->GetNumResources() );
+ // This block calculates how many slots we need to
+ // make for paying attention to different label combinations
+ int on = 1;
+ int max_sense_label_length = 0;
+ while (on < m_world->GetNumResources())
+ {
+ max_sense_label_length++;
+ sense_size += on;
+ on *= m_world->GetHardwareManager().GetInstSet().GetNumNops();
+ }
+ sense_size += on;
+
+ sense_last_count.Resize( sense_size );
+ sense_last_count.SetAll(0);
+
+ sense_last_exe_count.Resize( sense_size );
+ sense_last_exe_count.SetAll(0);
+
+ sense_names.Resize( sense_size );
+ int assign_index = 0;
+ int num_per = 1;
+ for (int i=0; i<= max_sense_label_length; i++)
+ {
+ for (int j=0; j< num_per; j++)
+ {
+ sense_names[assign_index] = (on > 1) ?
+ cStringUtil::Stringf("sense_res.%i-%i", j*on, (j+1)*on-1) :
+ cStringUtil::Stringf("sense_res.%i", j);
+
+ assign_index++;
+ }
+ on /= m_world->GetHardwareManager().GetInstSet().GetNumNops();
+ num_per *= m_world->GetHardwareManager().GetInstSet().GetNumNops();
+
+ }
+
genotype_map.Resize( m_world->GetConfig().WORLD_X.Get() * m_world->GetConfig().WORLD_Y.Get() );
SetupPrintDatabase();
}
@@ -368,6 +404,9 @@
task_last_max_quality.SetAll(0);
task_exe_count.SetAll(0);
+ sense_last_count.SetAll(0);
+ sense_last_exe_count.SetAll(0);
+
dom_merit = 0;
dom_gestation = 0.0;
dom_fitness = 0.0;
@@ -846,5 +885,35 @@
df.Write(num_used, "num used" );
df.Write(num_own_used, "num own used" );
num_bought = num_sold = num_used = num_own_used = 0;
-df.Endl();
+ df.Endl();
}
+
+void cStats::PrintSenseData(const cString& filename)
+{
+ cDataFile& df = m_world->GetDataFile(filename);
+
+ df.WriteComment( "Avida sense instruction usage\n" );
+ df.WriteComment("total number of organisms whose parents executed sense instructions with given labels" );
+
+ df.Write( GetUpdate(), "update" );
+
+ for( int i=0; i < sense_last_count.GetSize(); i++ ){
+ df.Write(sense_last_count[i], sense_names[i]);
+ }
+ df.Endl();
+}
+
+void cStats::PrintSenseExeData(const cString& filename)
+{
+ cDataFile& df = m_world->GetDataFile(filename);
+
+ df.WriteComment( "Avida sense instruction usage\n" );
+ df.WriteComment("total number of sense instructions executed by the parents of current organisms with given labels" );
+
+ df.Write( GetUpdate(), "update" );
+
+ for( int i=0; i < sense_last_exe_count.GetSize(); i++ ){
+ df.Write(sense_last_exe_count[i], sense_names[i]);
+ }
+ df.Endl();
+}
Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h 2006-10-20 19:27:30 UTC (rev 1057)
+++ development/source/main/cStats.h 2006-10-22 22:04:22 UTC (rev 1058)
@@ -215,6 +215,12 @@
int num_sold;
int num_used;
int num_own_used;
+
+ // Stats for how sense instruction is being used
+ int sense_size;
+ tArray<int> sense_last_count;
+ tArray<int> sense_last_exe_count;
+ tArray<cString> sense_names;
cStats(); // @not_implemented
cStats(const cStats&); // @not_implemented
@@ -262,6 +268,8 @@
int GetDomInjBirths() const { return dom_inj_births; }
int GetDomInjAbundance() const { return dom_inj_abundance; }
const cString & GetDomInjSequence() const { return dom_inj_sequence; }
+
+ int GetSenseSize() const { return sense_size; }
// Settings...
void SetDomGenotype(cGenotype * in_gen) { dom_genotype = in_gen; }
@@ -417,7 +425,11 @@
void IncTaskExeCount(int task_num, int task_count)
{ task_exe_count[task_num] += task_count; }
void ZeroTasks();
-
+
+ void AddLastSense(int res_comb_index) { sense_last_count[res_comb_index]++; }
+ void IncLastSenseExeCount(int res_comb_index, int count)
+ { sense_last_exe_count[res_comb_index]+= count; }
+
void SetReactions(const tArray<double> &_in) { reaction_count = _in; }
void SetResources(const tArray<double> &_in) { resource_count = _in; }
void SetResourcesGeometry(const tArray<int> &_in) { resource_geometry = _in;}
@@ -527,6 +539,7 @@
int GetResamplings() const { return num_resamplings;} //AWC 06/29/06
int GetFailedResamplings() const { return num_failedResamplings;} //AWC 06/29/06
+ int GetNumSenseSlots();
// this value gets recorded when a creature with the particular
// fitness value gets born. It will never change to a smaller value,
@@ -558,6 +571,9 @@
void PrintInstructionData(const cString& filename);
void PrintGenotypeMap(const cString& filename);
void PrintMarketData(const cString& filename);
+ void PrintSenseData(const cString& filename);
+ void PrintSenseExeData(const cString& filename);
+
};
More information about the Avida-cvs
mailing list