[Avida-cvs] [avida-svn] r489 - in branches/jeffdev: . source source/cpu source/event source/main source/support/config source/tools
jclune@myxo.css.msu.edu
jclune at myxo.css.msu.edu
Mon Feb 27 14:24:16 PST 2006
Author: jclune
Date: 2006-02-27 17:24:15 -0500 (Mon, 27 Feb 2006)
New Revision: 489
Removed:
branches/jeffdev/build/
Modified:
branches/jeffdev/source/cpu/cCPUMemory.cc
branches/jeffdev/source/cpu/cHardwareCPU.cc
branches/jeffdev/source/cpu/cHardwareCPU.h
branches/jeffdev/source/defs.h
branches/jeffdev/source/event/cPopulationEventFactory.cc
branches/jeffdev/source/main/cEnvironment.cc
branches/jeffdev/source/main/cPhenotype.cc
branches/jeffdev/source/main/cPhenotype.h
branches/jeffdev/source/main/cPopulation.cc
branches/jeffdev/source/main/cReactionProcess.h
branches/jeffdev/source/main/cReactionResult.cc
branches/jeffdev/source/main/cReactionResult.h
branches/jeffdev/source/main/cStats.cc
branches/jeffdev/source/main/cStats.h
branches/jeffdev/source/main/cTaskEntry.cc
branches/jeffdev/source/main/cTaskEntry.h
branches/jeffdev/source/main/cTaskLib.cc
branches/jeffdev/source/main/cTaskLib.h
branches/jeffdev/source/support/config/environment.9resource
branches/jeffdev/source/tools/tBuffer.h
Log:
Merge in r438:r488 changes from trunk into branches/jeffdev. -- Remove build dir.
Modified: branches/jeffdev/source/cpu/cCPUMemory.cc
===================================================================
--- branches/jeffdev/source/cpu/cCPUMemory.cc 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/cpu/cCPUMemory.cc 2006-02-27 22:24:15 UTC (rev 489)
@@ -21,6 +21,7 @@
cCPUMemory::cCPUMemory(int _size) : cGenome(_size), flag_array(_size)
{
+ ClearFlags();
}
cCPUMemory::cCPUMemory(const cCPUMemory & in_memory)
@@ -143,11 +144,10 @@
// Do a sloppy resize first, saving old values...
const int old_size = active_size;
- const int old_array_size = genome.GetSize();
SloppyResize(new_size);
// Clean up all of the old memory that might need it...
- for (int i = old_size; i < new_size && i < old_array_size; i++) {
+ for (int i = old_size; i < new_size; i++) {
genome[i].SetOp(0);
flag_array[i] = 0;
}
@@ -158,8 +158,14 @@
{
assert(new_size >= 0);
+ const int old_size = active_size;
+
// Do a sloppy resize, which will still have old values.
SloppyResize(new_size);
+
+ for (int i = old_size; i < new_size; i++) {
+ flag_array[i] = 0;
+ }
}
@@ -214,5 +220,6 @@
// Now just copy everything over!
for (int i = 0; i < in_genome.GetSize(); i++) {
genome[i + pos] = in_genome[i];
+ flag_array[i + pos] = 0;
}
}
Modified: branches/jeffdev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/jeffdev/source/cpu/cHardwareCPU.cc 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/cpu/cHardwareCPU.cc 2006-02-27 22:24:15 UTC (rev 489)
@@ -203,7 +203,7 @@
cInstEntryCPU("put", &cHardwareCPU::Inst_TaskPut),
cInstEntryCPU("IO", &cHardwareCPU::Inst_TaskIO, true,
"Output ?BX?, and input new number back into ?BX?"),
-
+ cInstEntryCPU("match-strings", &cHardwareCPU::Inst_MatchStrings),
cInstEntryCPU("send", &cHardwareCPU::Inst_Send),
cInstEntryCPU("receive", &cHardwareCPU::Inst_Receive),
cInstEntryCPU("sense", &cHardwareCPU::Inst_Sense),
@@ -388,6 +388,7 @@
, cur_thread(hardware_cpu.cur_thread)
, mal_active(hardware_cpu.mal_active)
, advance_ip(hardware_cpu.advance_ip)
+, executedmatchstrings(hardware_cpu.executedmatchstrings)
#ifdef INSTRUCTION_COSTS
, inst_cost(hardware_cpu.inst_cost)
, inst_ft_cost(hardware_cpu.inst_ft_cost)
@@ -423,6 +424,7 @@
cur_thread = 0;
mal_active = false;
+ executedmatchstrings = false;
#ifdef INSTRUCTION_COSTS
// instruction cost arrays
@@ -2830,6 +2832,15 @@
return true;
}
+bool cHardwareCPU::Inst_MatchStrings()
+{
+ if (executedmatchstrings)
+ return false;
+ organism->DoOutput(357913941);
+ executedmatchstrings = true;
+ return true;
+}
+
bool cHardwareCPU::Inst_Send()
{
const int reg_used = FindModifiedRegister(nHardwareCPU::REG_BX);
Modified: branches/jeffdev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/jeffdev/source/cpu/cHardwareCPU.h 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/cpu/cHardwareCPU.h 2006-02-27 22:24:15 UTC (rev 489)
@@ -99,6 +99,7 @@
// Flags...
bool mal_active; // Has an allocate occured since last divide?
bool advance_ip; // Should the IP advance after this instruction?
+ bool executedmatchstrings; // Have we already executed the match strings instruction?
// Instruction costs...
#ifdef INSTRUCTION_COSTS
@@ -393,6 +394,7 @@
bool Inst_TaskStackLoad();
bool Inst_TaskPut();
bool Inst_TaskIO();
+ bool Inst_MatchStrings();
bool Inst_Send();
bool Inst_Receive();
bool Inst_Sense();
Modified: branches/jeffdev/source/defs.h
===================================================================
--- branches/jeffdev/source/defs.h 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/defs.h 2006-02-27 22:24:15 UTC (rev 489)
@@ -8,7 +8,7 @@
#ifndef DEFS_HH
#define DEFS_HH
-#define VERSION "2.4.2"
+#define VERSION "2.4.3"
#define VERSION_TAG "Padawan"
@@ -161,7 +161,7 @@
// Number of distinct input and outputs stored in the IOBufs (to test tasks)
#define INPUT_BUF_SIZE 3
-#define OUTPUT_BUF_SIZE 1
+#define OUTPUT_BUF_SIZE 3
#define SEND_BUF_SIZE 3
#define RECEIVE_BUF_SIZE 3
Modified: branches/jeffdev/source/event/cPopulationEventFactory.cc
===================================================================
--- branches/jeffdev/source/event/cPopulationEventFactory.cc 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/event/cPopulationEventFactory.cc 2006-02-27 22:24:15 UTC (rev 489)
@@ -584,6 +584,25 @@
population->GetStats().PrintTasksExeData(fname);
}
};
+
+ class cEvent_print_reaction_data : public cPopulationEvent {
+ private:
+ cString fname;
+ public:
+ const cString GetName() const { return "print_reaction_data"; }
+ const cString GetDescription() const { return "print_reaction_data [cString fname=\"reaction.dat\"]"; }
+
+ void Configure(const cString& in_args)
+ {
+ m_args = in_args;
+ cString args(in_args);
+ if (args == "") fname="reaction.dat"; else fname=args.PopWord();
+ }
+ ///// print_tasks_exe_data /////
+ void Process(){
+ population->GetStats().PrintReactionData(fname);
+ }
+ };
///// print_resource_data /////
Modified: branches/jeffdev/source/main/cEnvironment.cc
===================================================================
--- branches/jeffdev/source/main/cEnvironment.cc 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cEnvironment.cc 2006-02-27 22:24:15 UTC (rev 489)
@@ -46,6 +46,7 @@
#include "cTools.h"
#endif
+#include <iostream>
using namespace std;
cEnvironment::cEnvironment()
@@ -237,6 +238,12 @@
return false;
new_process->SetDetectionError(var_value.AsDouble());
}
+ else if (var_name == "string") {
+ //if (!AssertInputValid(var_value, "string", var_type, var_value))
+ // return false;
+ new_process->SetMatchString(var_value);
+ }
+
else {
cerr << "Error: Unknown process variable '" << var_name
<< "' in reaction '" << reaction->GetName() << "'" << endl;
@@ -440,10 +447,12 @@
}
// Finish loading in this reaction.
- const cString trigger = desc.PopWord();
+ cString trigger_info = desc.PopWord();
+ cString trigger = trigger_info.Pop('=');
+
// Load the task trigger
- cTaskEntry * cur_task = task_lib.AddTask(trigger);
+ cTaskEntry * cur_task = task_lib.AddTask(trigger, trigger_info);
if (cur_task == NULL) {
cerr << "...failed to find task in cTaskLib..." << endl;
return false;
@@ -752,15 +761,14 @@
// If this task wasn't performed, move on to the next one.
if (task_quality == 0.0) continue;
- // Mark this task as performed...
- result.MarkTask(task_id);
-
// Examine requisites on this reaction
if (TestRequisites(cur_reaction->GetRequisites(), task_count[task_id],
- reaction_count) == false) {
- continue;
- }
+ reaction_count) == false) continue;
+ // Mark this task as performed...
+ result.MarkTask(task_id, task_quality);
+
+
// And lets process it!
DoProcesses(cur_reaction->GetProcesses(), resource_count,
task_quality, result);
Modified: branches/jeffdev/source/main/cPhenotype.cc
===================================================================
--- branches/jeffdev/source/main/cPhenotype.cc 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cPhenotype.cc 2006-02-27 22:24:15 UTC (rev 489)
@@ -31,10 +31,12 @@
: environment(_environment)
, initialized(false)
, cur_task_count(environment.GetTaskLib().GetSize())
+ , cur_task_quality(environment.GetTaskLib().GetSize())
, cur_reaction_count(environment.GetReactionLib().GetSize())
, cur_inst_count(environment.GetInstSet().GetSize())
, sensed_resources(environment.GetResourceLib().GetSize())
, last_task_count(environment.GetTaskLib().GetSize())
+ , last_task_quality(environment.GetTaskLib().GetSize())
, last_reaction_count(environment.GetReactionLib().GetSize())
, last_inst_count(environment.GetInstSet().GetSize())
{
@@ -104,6 +106,7 @@
cur_num_errors = 0;
cur_num_donates = 0;
cur_task_count.SetAll(0);
+ cur_task_quality.SetAll(0);
cur_reaction_count.SetAll(0);
cur_inst_count.SetAll(0);
for (int j = 0; j < sensed_resources.GetSize(); j++)
@@ -116,6 +119,7 @@
last_num_errors = parent_phenotype.last_num_errors;
last_num_donates = parent_phenotype.last_num_donates;
last_task_count = parent_phenotype.last_task_count;
+ 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_fitness = last_merit_base * last_bonus / gestation_time;
@@ -198,6 +202,7 @@
last_num_errors = 0;
last_num_donates = 0;
last_task_count.SetAll(0);
+ last_task_quality.SetAll(0);
last_reaction_count.SetAll(0);
last_inst_count.SetAll(0);
@@ -268,6 +273,7 @@
last_num_errors = cur_num_errors;
last_num_donates = cur_num_donates;
last_task_count = cur_task_count;
+ last_task_quality = cur_task_quality;
last_reaction_count = cur_reaction_count;
last_inst_count = cur_inst_count;
@@ -276,6 +282,7 @@
cur_num_errors = 0;
cur_num_donates = 0;
cur_task_count.SetAll(0);
+ cur_task_quality.SetAll(0);
cur_reaction_count.SetAll(0);
cur_inst_count.SetAll(0);
@@ -355,6 +362,7 @@
last_num_errors = cur_num_errors;
last_num_donates = cur_num_donates;
last_task_count = cur_task_count;
+ last_task_quality = cur_task_quality;
last_reaction_count = cur_reaction_count;
last_inst_count = cur_inst_count;
@@ -363,6 +371,7 @@
cur_num_errors = 0;
cur_num_donates = 0;
cur_task_count.SetAll(0);
+ cur_task_quality.SetAll(0);
cur_reaction_count.SetAll(0);
cur_inst_count.SetAll(0);
sensed_resources.SetAll(-1.0);
@@ -536,6 +545,9 @@
for (int i = 0; i < num_tasks; i++) {
if (result.TaskDone(i) == true) cur_task_count[i]++;
}
+ for (int i = 0; i < num_tasks; i++) {
+ if (result.TaskQuality(i) > 0) cur_task_quality[i]+= result.TaskQuality(i);
+ }
for (int i = 0; i < num_reactions; i++) {
if (result.ReactionTriggered(i) == true) cur_reaction_count[i]++;
}
Modified: branches/jeffdev/source/main/cPhenotype.h
===================================================================
--- branches/jeffdev/source/main/cPhenotype.h 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cPhenotype.h 2006-02-27 22:24:15 UTC (rev 489)
@@ -74,6 +74,7 @@
int cur_num_errors; // Total instructions executed illeagally.
int cur_num_donates; // Number of donations so far
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<double> sensed_resources; // Resources of which the organism is explictly aware
@@ -84,6 +85,7 @@
int last_num_errors;
int last_num_donates;
tArray<int> last_task_count;
+ tArray<double> last_task_quality;
tArray<int> last_reaction_count;
tArray<int> last_inst_count; // Intruction exection counter
double last_fitness; // Used to determine sterilization.
@@ -205,6 +207,8 @@
{ assert(initialized == true); return cur_num_donates; }
const tArray<int> & GetCurTaskCount() const
{ assert(initialized == true); return cur_task_count; }
+ 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
@@ -225,6 +229,8 @@
{ assert(initialized == true); return last_num_donates; }
const tArray<int> & GetLastTaskCount() const
{ assert(initialized == true); return last_task_count; }
+ 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
Modified: branches/jeffdev/source/main/cPopulation.cc
===================================================================
--- branches/jeffdev/source/main/cPopulation.cc 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cPopulation.cc 2006-02-27 22:24:15 UTC (rev 489)
@@ -1269,9 +1269,18 @@
// Test what tasks this creatures has completed.
for (int j=0; j < phenotype.GetEnvironment().GetTaskLib().GetSize(); j++) {
- if (phenotype.GetCurTaskCount()[j] > 0) stats.AddCurTask(j);
- if (phenotype.GetLastTaskCount()[j] > 0) stats.AddLastTask(j);
+ if (phenotype.GetCurTaskCount()[j] > 0)
+ {
+ stats.AddCurTask(j);
+ stats.AddCurTaskQuality(j, phenotype.GetCurTaskQuality()[j]);
+ }
+
if (phenotype.GetLastTaskCount()[j] > 0)
+ {
+ stats.AddLastTask(j);
+ stats.AddLastTaskQuality(j, phenotype.GetLastTaskQuality()[j]);
+ }
+ if (phenotype.GetLastTaskCount()[j] > 0)
stats.IncTaskExeCount(j, phenotype.GetLastTaskCount()[j]);
}
Modified: branches/jeffdev/source/main/cReactionProcess.h
===================================================================
--- branches/jeffdev/source/main/cReactionProcess.h 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cReactionProcess.h 2006-02-27 22:24:15 UTC (rev 489)
@@ -7,6 +7,9 @@
#ifndef REACTION_PROCESS_HH
#define REACTION_PROCESS_HH
+#ifndef STRING_HH
+#include "cString.h"
+#endif
#include <iostream>
@@ -23,8 +26,9 @@
double max_fraction; // Max fraction of avaiable resources useable.
cResource * product; // Output resource.
double conversion; // Conversion factor.
- bool lethal; // Lethality of reaction
+ bool lethal; // Lethality of reaction
int inst_id; // Instruction to be triggered if reaction successful.
+ cString match_string; // Bit string to match if this is a match string reaction
// Resource detection
cResource * detect; // Resource Measured
@@ -47,6 +51,7 @@
cResource * GetDetect() const { return detect; }
double GetDetectionThreshold() const { return detection_threshold; }
double GetDetectionError() const { return detection_error; }
+ cString GetMatchString() const { return match_string; }
void SetResource(cResource * _in) { resource = _in; }
void SetValue(double _in) { value = _in; }
@@ -61,6 +66,7 @@
void SetDetect(cResource * _in) { detect = _in; }
void SetDetectionThreshold(double _in) { detection_threshold = _in; }
void SetDetectionError(double _in) { detection_error = _in; }
+ void SetMatchString(cString _in) { match_string = _in; }
};
#endif
Modified: branches/jeffdev/source/main/cReactionResult.cc
===================================================================
--- branches/jeffdev/source/main/cReactionResult.cc 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cReactionResult.cc 2006-02-27 22:24:15 UTC (rev 489)
@@ -6,6 +6,8 @@
//////////////////////////////////////////////////////////////////////////////
#include "cReactionResult.h"
+#include <iostream>
+using namespace std;
cReactionResult::cReactionResult(const int num_resources,
@@ -15,6 +17,7 @@
, resources_produced(num_resources)
, resources_detected(num_resources)
, tasks_done(num_tasks)
+ , tasks_quality(num_tasks)
, receive_tasks_done(num_tasks)
, send_tasks_done(num_tasks)
, reactions_triggered(num_reactions)
@@ -41,6 +44,7 @@
resources_produced.SetAll(0.0);
resources_detected.SetAll(-1.0);
tasks_done.SetAll(false);
+ tasks_quality.SetAll(0.0);
receive_tasks_done.SetAll(false);
send_tasks_done.SetAll(false);
reactions_triggered.SetAll(false);
@@ -76,10 +80,11 @@
lethal = flag;
}
-void cReactionResult::MarkTask(int id)
+void cReactionResult::MarkTask(int id, double quality)
{
ActivateReaction();
tasks_done[id] = true;
+ tasks_quality[id] = quality;
}
@@ -159,6 +164,12 @@
return tasks_done[id];
}
+double cReactionResult::TaskQuality(int id)
+{
+ if (GetActive() == false) return 0;
+ return tasks_quality[id];
+}
+
double cReactionResult::GetAddBonus()
{
if (GetActive() == false) return 0.0;
Modified: branches/jeffdev/source/main/cReactionResult.h
===================================================================
--- branches/jeffdev/source/main/cReactionResult.h 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cReactionResult.h 2006-02-27 22:24:15 UTC (rev 489)
@@ -20,6 +20,7 @@
tArray<double> resources_produced;
tArray<double> resources_detected; //Initialize to -1.0
tArray<bool> tasks_done;
+ tArray<double> tasks_quality;
tArray<bool> receive_tasks_done;
tArray<bool> send_tasks_done;
tArray<bool> reactions_triggered;
@@ -41,7 +42,7 @@
void Produce(int id, double num);
void Detect(int id, double num);
void Lethal(bool flag);
- void MarkTask(int id);
+ void MarkTask(int id, double quality=1);
void MarkReceiveTask(int id);
void MarkSendTask(int id);
void MarkReaction(int id);
@@ -55,6 +56,7 @@
bool GetLethal();
bool ReactionTriggered(int id);
bool TaskDone(int id);
+ double TaskQuality(int id);
double GetAddBonus();
double GetMultBonus();
tArray<int> & GetInstArray();
Modified: branches/jeffdev/source/main/cStats.cc
===================================================================
--- branches/jeffdev/source/main/cStats.cc 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cStats.cc 2006-02-27 22:24:15 UTC (rev 489)
@@ -13,6 +13,7 @@
#include "cStringUtil.h"
#include "tDataEntry.h"
+#include <iostream>
#include <math.h>
using namespace std;
@@ -101,9 +102,17 @@
task_cur_count.Resize( cConfig::GetNumTasks() );
task_last_count.Resize( cConfig::GetNumTasks() );
+ task_cur_quality.Resize( cConfig::GetNumTasks() );
+ task_last_quality.Resize( cConfig::GetNumTasks() );
+ task_cur_max_quality.Resize( cConfig::GetNumTasks() );
+ task_last_max_quality.Resize( cConfig::GetNumTasks() );
task_exe_count.Resize( cConfig::GetNumTasks() );
task_cur_count.SetAll(0);
task_last_count.SetAll(0);
+ task_cur_quality.SetAll(0);
+ task_last_quality.SetAll(0);
+ task_cur_max_quality.SetAll(0);
+ task_last_max_quality.SetAll(0);
task_exe_count.SetAll(0);
#ifdef INSTRUCTION_COUNT
@@ -235,6 +244,10 @@
for( int i=0; i < task_cur_count.GetSize(); i++ ){
task_cur_count[i] = 0;
task_last_count[i] = 0;
+ task_cur_quality[i] = 0;
+ task_last_quality[i] = 0;
+ task_last_max_quality[i] = 0;
+ task_cur_max_quality[i] = 0;
}
}
@@ -392,6 +405,10 @@
task_cur_count.SetAll(0);
task_last_count.SetAll(0);
+ task_cur_quality.SetAll(0);
+ task_last_quality.SetAll(0);
+ task_cur_max_quality.SetAll(0);
+ task_last_max_quality.SetAll(0);
task_exe_count.SetAll(0);
dom_merit = 0;
@@ -647,19 +664,37 @@
void cStats::PrintTasksData(const cString & filename)
{
- cDataFile & df = GetDataFile(filename);
+ cString file = filename;
- df.WriteComment( "Avida tasks data" );
- df.WriteTimeStamp();
- df.WriteComment( "First column gives the current update, all further columns give the number" );
- df.WriteComment( "of organisms that have the particular task as a component of the merit." );
+ // flag to print both tasks.dat and taskquality.dat
+ if (filename == "tasksq.dat")
+ {
+ file = "tasks.dat";
+ cDataFile & df2 = GetDataFile("taskquality.dat");
+ df2.WriteComment( "First column gives the current update, rest give average and max task quality" );
+ df2.Write( GetUpdate(), "Update");
+ for(int i = 0; i < task_last_count.GetSize(); i++) {
+ double qual=0;
+ if (task_last_count[i] > 0)
+ qual = task_last_quality[i]/(double)task_last_count[i];
+ df2.Write( qual, task_names[i] );
+ df2.Write( task_last_max_quality[i], "Max" );
+ }
+ df2.Endl();
+ }
+ // print tasks.dat
+ cDataFile & df = GetDataFile(file);
+ df.WriteComment( "Avida tasks data" );
+ df.WriteTimeStamp();
+ df.WriteComment( "First column gives the current update, next columns give the number" );
+ df.WriteComment( "of organisms that have the particular task as a component of their merit" );
- df.Write( GetUpdate(), "Update");
- for(int i = 0; i < task_last_count.GetSize(); i++) {
- df.Write( task_last_count[i], task_names[i] );
- }
- df.Endl();
+ df.Write( GetUpdate(), "Update");
+ for(int i = 0; i < task_last_count.GetSize(); i++) {
+ df.Write( task_last_count[i], task_names[i] );
+ }
+ df.Endl();
}
Modified: branches/jeffdev/source/main/cStats.h
===================================================================
--- branches/jeffdev/source/main/cStats.h 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cStats.h 2006-02-27 22:24:15 UTC (rev 489)
@@ -179,6 +179,7 @@
int dom_gene_depth;
cString dom_sequence;
int coal_depth;
+
// Dominant Parasite
cInjectGenotype * dom_inj_genotype;
@@ -221,6 +222,10 @@
tArray<int> task_cur_count;
tArray<int> task_last_count;
+ tArray<double> task_cur_quality;
+ tArray<double> task_last_quality;
+ tArray<double> task_cur_max_quality;
+ tArray<double> task_last_max_quality;
tArray<int> task_exe_count;
tArray<double> reaction_count;
@@ -444,7 +449,17 @@
void IncExecuted() { num_executed++; }
void AddCurTask(int task_num) { task_cur_count[task_num]++; }
+ void AddCurTaskQuality(int task_num, double quality)
+ { task_cur_quality[task_num] += quality;
+ if (quality > task_cur_max_quality[task_num])
+ task_cur_max_quality[task_num] = quality;
+ }
void AddLastTask(int task_num) { task_last_count[task_num]++; }
+ void AddLastTaskQuality(int task_num, double quality)
+ { task_last_quality[task_num] += quality;
+ if (quality > task_last_max_quality[task_num])
+ task_last_max_quality[task_num] = quality;
+ }
void IncTaskExeCount(int task_num, int task_count)
{ task_exe_count[task_num] += task_count; }
void ZeroTasks();
@@ -492,6 +507,10 @@
int GetTaskCurCount(int task_num) const { return task_cur_count[task_num]; }
int GetTaskLastCount(int task_num) const {return task_last_count[task_num];}
+ double GetTaskCurQuality(int task_num) const { return task_cur_quality[task_num]/(double)task_cur_count[task_num]; }
+ double GetTaskLastQuality(int task_num) const {return task_last_quality[task_num]/(double)task_last_count[task_num];}
+ double GetTaskMaxCurQuality(int task_num) const { return task_cur_max_quality[task_num];}
+ double GetTaskMaxLastQuality(int task_num) const { return task_last_max_quality[task_num];}
int GetTaskExeCount(int task_num) const { return task_exe_count[task_num]; }
const tArray<double> & GetReactions() const { return reaction_count; }
Modified: branches/jeffdev/source/main/cTaskEntry.cc
===================================================================
--- branches/jeffdev/source/main/cTaskEntry.cc 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cTaskEntry.cc 2006-02-27 22:24:15 UTC (rev 489)
@@ -14,11 +14,12 @@
////////////////
cTaskEntry::cTaskEntry(const cString & _name, const cString & _desc,
- int _id, tTaskTest _test_fun)
+ int _id, tTaskTest _test_fun, const cString & _info)
: name(_name)
, desc(_desc)
, id(_id)
, test_fun(_test_fun)
+ , info(_info)
{
}
Modified: branches/jeffdev/source/main/cTaskEntry.h
===================================================================
--- branches/jeffdev/source/main/cTaskEntry.h 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cTaskEntry.h 2006-02-27 22:24:15 UTC (rev 489)
@@ -21,15 +21,17 @@
cString desc; // For more human-understandable output...
int id;
tTaskTest test_fun;
+ cString info; // extra info (like the string or whatever to match)
public:
cTaskEntry(const cString & _name, const cString & _desc, int _id,
- tTaskTest _test_fun);
+ tTaskTest _test_fun, const cString & info);
~cTaskEntry();
const cString & GetName() const { return name; }
const cString & GetDesc() const { return desc; }
const int GetID() const { return id; }
const tTaskTest GetTestFun() const { return test_fun; }
+ const cString & GetInfo() const { return info; }
};
#endif
Modified: branches/jeffdev/source/main/cTaskLib.cc
===================================================================
--- branches/jeffdev/source/main/cTaskLib.cc 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cTaskLib.cc 2006-02-27 22:24:15 UTC (rev 489)
@@ -17,6 +17,7 @@
#include <math.h>
#include <limits.h>
}
+#include <iostream>
using namespace std;
@@ -39,11 +40,12 @@
}
}
-cTaskEntry * cTaskLib::AddTask(const cString & name)
+cTaskEntry * cTaskLib::AddTask(const cString & name, const cString & info)
{
// Determine if this task is already in the active library.
for (int i = 0; i < task_array.GetSize(); i++) {
- if (task_array[i]->GetName() == name) {
+ if (task_array[i]->GetName() == name &&
+ task_array[i]->GetInfo() == info) {
assert(task_array[i] != NULL);
return task_array[i];
}
@@ -52,6 +54,7 @@
// Match up this name to its corresponding task
const int start_size = task_array.GetSize();
+
if (name == "echo") NewTask(name, "Echo", &cTaskLib::Task_Echo);
else if (name == "add") NewTask(name, "Add", &cTaskLib::Task_Add);
else if (name == "sub") NewTask(name, "Sub", &cTaskLib::Task_Sub);
@@ -318,6 +321,8 @@
else if (name == "math_3AM")
NewTask(name, "Math 3AM ((X+Y)^2+(Y+Z)^2)", &cTaskLib::Task_Math3in_AM);
+ // match string task
+ if (name == "matchstr") NewTask(name, "MatchStr", &cTaskLib::Task_MatchStr, 0, info);
// communication tasks
else if (name == "comm_echo")
NewTask(name, "Echo of Neighbor's Input", &cTaskLib::Task_CommEcho,
@@ -434,6 +439,7 @@
double cTaskLib::TestOutput(const cTaskEntry & task) const
{
+ cur_task = task.GetID();
tTaskTest test_fun = task.GetTestFun();
return (this->*test_fun)();
}
@@ -444,14 +450,14 @@
////////////////////////
void cTaskLib::NewTask(const cString & name, const cString & desc,
- tTaskTest task_fun, int reqs)
+ tTaskTest task_fun, int reqs, const cString & info)
{
if (reqs & REQ_NEIGHBOR_INPUT == true) use_neighbor_input = true;
if (reqs & REQ_NEIGHBOR_OUTPUT == true) use_neighbor_output = true;
const int id = task_array.GetSize();
task_array.Resize(id+1);
- task_array[id] = new cTaskEntry(name, desc, id, task_fun);
+ task_array[id] = new cTaskEntry(name, desc, id, task_fun, info);
}
@@ -1666,6 +1672,41 @@
return 0.0;
}
+double cTaskLib::Task_MatchStr() const
+{
+ if (output_buffer[0] != 357913941)
+ return 0;
+
+ output_buffer.Pop(); // pop the 1234 value off of the buffer
+ if (output_buffer.GetNumStored() == 0)
+ return 0;
+
+ const cString & string_to_match = task_array[cur_task]->GetInfo();
+ int max_num_matched = 0;
+ //for (int i=0; i<output_buffer.GetNumStored(); i++)
+ //{
+ const int test_output = output_buffer[0];
+ int num_matched = 0;
+ int string_index;
+
+ for (int j=0; j<string_to_match.GetSize(); j++)
+ {
+ string_index=string_to_match.GetSize()-j-1;
+ int k = 1 << j;
+ if ((string_to_match[string_index]=='0' && !(test_output & k)) || (string_to_match[string_index]=='1' && (test_output & k)))
+ num_matched++;
+ }
+ if (num_matched > max_num_matched)
+ max_num_matched = num_matched;
+ //}
+ output_buffer.Add(357913941);
+
+
+ // return value between 0 & 1 representing the percentage of string that was matched
+ double bonus = pow((double(max_num_matched*2)/(double)string_to_match.GetSize()),2);
+ return bonus;
+}
+
double cTaskLib::Task_CommEcho() const
{
const int test_output = output_buffer[0];
@@ -1698,4 +1739,4 @@
}
return 0.0;
-}
\ No newline at end of file
+}
Modified: branches/jeffdev/source/main/cTaskLib.h
===================================================================
--- branches/jeffdev/source/main/cTaskLib.h 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/main/cTaskLib.h 2006-02-27 22:24:15 UTC (rev 489)
@@ -38,6 +38,7 @@
mutable tList<tBuffer<int> > other_input_buffers;
mutable tList<tBuffer<int> > other_output_buffers;
mutable int logic_id;
+ mutable int cur_task; // the ID of the task currently being tested
enum req_list { REQ_NEIGHBOR_INPUT=1,
REQ_NEIGHBOR_OUTPUT=2,
@@ -52,7 +53,7 @@
int GetSize() const { return task_array.GetSize(); }
- cTaskEntry * AddTask(const cString & name);
+ cTaskEntry * AddTask(const cString & name, const cString & info);
const cTaskEntry & GetTask(int id) const;
void SetupTests(const tBuffer<int> & inputs,
@@ -66,7 +67,7 @@
private: // Direct task related methods
void NewTask(const cString & name, const cString & desc,
- tTaskTest task_fun, int reqs=0);
+ tTaskTest task_fun, int reqs=0, const cString & info="");
void SetupLogicTests(const tBuffer<int> & inputs,
const tBuffer<int> & outputs) const;
@@ -211,6 +212,8 @@
double Task_Math3in_AL() const;
double Task_Math3in_AM() const;
+ // match string tasks
+ double Task_MatchStr() const;
// Communication Tasks...
double Task_CommEcho() const;
double Task_CommNot() const;
Modified: branches/jeffdev/source/support/config/environment.9resource
===================================================================
--- branches/jeffdev/source/support/config/environment.9resource 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/support/config/environment.9resource 2006-02-27 22:24:15 UTC (rev 489)
@@ -1,33 +1,38 @@
-##############################################################################
-#
-# This is the setup file for the task/resource system. From here, you can
-# setup the available resources (including their inflow and outflow rates) as
-# well as the reactions that the organisms can trigger by performing tasks.
-#
-# This environmental setup is that of a chemostat with 9 resources, each
-# with a unique task corresponding to them. All resources have a set inflow
-# of 100, and outflow rate of 0.01, setting their an equilibrium level at
-# 10,000. Given a maximum population size of 3600 and neighborhood size of
-# 9, the fraction of the resource absorbable in each reaction is simply
-# 9/3600 or 0.0025.
-#
-# For information on how to use this file, see: doc/environment.html
-# For other sample environments, see: source/support/config/
-#
-##############################################################################
-
-RESOURCE resNOT:inflow=100:outflow=0.01 resNAND:inflow=100:outflow=0.01
-RESOURCE resAND:inflow=100:outflow=0.01 resORN:inflow=100:outflow=0.01
-RESOURCE resOR:inflow=100:outflow=0.01 resANDN:inflow=100:outflow=0.01
-RESOURCE resNOR:inflow=100:outflow=0.01 resXOR:inflow=100:outflow=0.01
-RESOURCE resEQU:inflow=100:outflow=0.01
-
-REACTION NOT not process:resource=resNOT:value=1.0:frac=0.0025:max=25
-REACTION NAND nand process:resource=resNAND:value=1.0:frac=0.0025:max=25
-REACTION AND and process:resource=resAND:value=2.0:frac=0.0025:max=25
-REACTION ORN orn process:resource=resORN:value=2.0:frac=0.0025:max=25
-REACTION OR or process:resource=resOR:value=4.0:frac=0.0025:max=25
-REACTION ANDN andn process:resource=resANDN:value=4.0:frac=0.0025:max=25
-REACTION NOR nor process:resource=resNOR:value=8.0:frac=0.0025:max=25
-REACTION XOR xor process:resource=resXOR:value=8.0:frac=0.0025:max=25
-REACTION EQU equ process:resource=resEQU:value=16.0:frac=0.0025:max=25
+##############################################################################
+#
+# This is the setup file for the task/resource system. From here, you can
+# setup the available resources (including their inflow and outflow rates) as
+# well as the reactions that the organisms can trigger by performing tasks.
+#
+# This environmental setup is that of a chemostat with 9 resources, each
+# with a unique task corresponding to them. All resources have a set inflow
+# of 100, and outflow rate of 0.01, setting their an equilibrium level at
+# 10,000. Given a maximum population size of 3600 and neighborhood size of
+# 9, the fraction of the resource absorbable in each reaction is simply
+# 9/3600 or 0.0025.
+#
+# For information on how to use this file, see: doc/environment.html
+# For other sample environments, see: source/support/config/
+#
+##############################################################################
+
+RESOURCE resNOT:inflow=100:outflow=0.01 resNAND:inflow=100:outflow=0.01
+RESOURCE resAND:inflow=100:outflow=0.01 resORN:inflow=100:outflow=0.01
+RESOURCE resOR:inflow=100:outflow=0.01 resANDN:inflow=100:outflow=0.01
+RESOURCE resNOR:inflow=100:outflow=0.01 resXOR:inflow=100:outflow=0.01
+RESOURCE resEQU:inflow=100:outflow=0.01
+
+REACTION NOT not process:resource=resNOT:value=1.0:frac=0.0025:max=25
+REACTION NAND nand process:resource=resNAND:value=1.0:frac=0.0025:max=25
+REACTION AND and process:resource=resAND:value=2.0:frac=0.0025:max=25
+REACTION ORN orn process:resource=resORN:value=2.0:frac=0.0025:max=25
+REACTION OR or process:resource=resOR:value=4.0:frac=0.0025:max=25
+REACTION ANDN andn process:resource=resANDN:value=4.0:frac=0.0025:max=25
+REACTION NOR nor process:resource=resNOR:value=8.0:frac=0.0025:max=25
+REACTION XOR xor process:resource=resXOR:value=8.0:frac=0.0025:max=25
+REACTION EQU equ process:resource=resEQU:value=16.0:frac=0.0025:max=25
+
+
+REACTION MATCHSTR matchstr process:resource=resMATCHSTR:value=16.0:frac=0.0025:max=25:string=11111111111111111111111111111111
+
+
Modified: branches/jeffdev/source/tools/tBuffer.h
===================================================================
--- branches/jeffdev/source/tools/tBuffer.h 2006-02-27 22:11:06 UTC (rev 488)
+++ branches/jeffdev/source/tools/tBuffer.h 2006-02-27 22:24:15 UTC (rev 489)
@@ -52,6 +52,12 @@
while (offset >= data.GetSize()) offset -= data.GetSize();
}
+ void Pop(){
+ total--;
+ offset--;
+ while (offset < 0) offset += data.GetSize();
+ }
+
void ZeroNumAdds() { total = 0; }
T operator[] (int i) const {
More information about the Avida-cvs
mailing list