[Avida-SVN] r2954 - branches/hjg-dev/source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Thu Nov 20 06:29:57 PST 2008
Author: hjg
Date: 2008-11-20 09:29:57 -0500 (Thu, 20 Nov 2008)
New Revision: 2954
Modified:
branches/hjg-dev/source/main/cTaskLib.cc
branches/hjg-dev/source/main/cTaskLib.h
Log:
Preliminary setup for string matching & reciprocity experiments
Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc 2008-11-20 02:17:30 UTC (rev 2953)
+++ branches/hjg-dev/source/main/cTaskLib.cc 2008-11-20 14:29:57 UTC (rev 2954)
@@ -428,7 +428,6 @@
NewTask(name, "Consume raw materials", &cTaskLib::Task_ConsumeRawMaterials);
else if(name == "save_raw_mat")
NewTask(name, "Save raw materials", &cTaskLib::Task_SaveRawMaterials);
-
// event tasks
if(name == "move_to_event")
@@ -1908,12 +1907,15 @@
return 0.0;
}
-
void cTaskLib::Load_MatchStr(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors)
{
cArgSchema schema;
schema.AddEntry("string", 0, cArgSchema::SCHEMA_STRING);
+ schema.AddEntry("partial",0, 0);
+ schema.AddEntry("binary",1,1);
+ schema.AddEntry("pow",0,2.0);
cArgContainer* args = cArgContainer::Load(argstr, schema, errors);
+ envreqs.SetMinOutputs(args->GetString(0).GetSize());
if (args) NewTask(name, "MatchStr", &cTaskLib::Task_MatchStr, 0, args);
}
@@ -1925,21 +1927,41 @@
// temp_buf.Pop(); // pop the signal value off of the buffer
const cString& string_to_match = ctx.GetTaskEntry()->GetArguments().GetString(0);
+ int partial = ctx.GetTaskEntry()->GetArguments().GetInt(0);
+ int binary = ctx.GetTaskEntry()->GetArguments().GetInt(1);
+ double mypow = ctx.GetTaskEntry()->GetArguments().GetDouble(0);
int string_index;
int num_matched = 0;
int test_output;
int max_num_matched = 0;
-
- if (temp_buf.GetNumStored() > 0) {
- test_output = temp_buf[0];
-
- for (int j = 0; j < string_to_match.GetSize(); j++) {
- string_index = string_to_match.GetSize() - j - 1; // start with last char in string
- 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++;
+ int num_real=0;
+
+ if (!binary)
+ {
+ if (temp_buf.GetNumStored() > 0) {
+ test_output = temp_buf[0];
+
+ for (int j = 0; j < string_to_match.GetSize(); j++) {
+ string_index = string_to_match.GetSize() - j - 1; // start with last char in string
+ 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++;
+ }
+ max_num_matched = num_matched;
}
+ }
+ else
+ {
+ for (int j = 0; j < string_to_match.GetSize(); j++)
+ {
+ if (string_to_match[j]!='9')
+ num_real++;
+ if (string_to_match[j]=='0' && temp_buf[j]==0 ||
+ string_to_match[j]=='1' && temp_buf[j]==1)
+ num_matched++;
+ }
max_num_matched = num_matched;
+
}
bool used_received = false;
@@ -1965,10 +1987,15 @@
double bonus = 0.0;
// return value between 0 & 1 representing the percentage of string that was matched
+
double base_bonus = static_cast<double>(max_num_matched) * 2.0 / static_cast<double>(string_to_match.GetSize()) - 1;
-
+ if (partial)
+ {
+ base_bonus=double(max_num_matched)*2/double(num_real) -1;
+ }
+
if (base_bonus > 0.0) {
- bonus = pow(base_bonus, 2);
+ bonus = pow(base_bonus,mypow);
if (used_received)
m_world->GetStats().AddMarketItemUsed();
else
@@ -1978,6 +2005,7 @@
}
+
void cTaskLib::Load_MatchNumber(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors)
{
cArgSchema schema;
@@ -3109,11 +3137,17 @@
/* This task rewards organisms proportional to the raw materials
that it has accumulated.*/
double cTaskLib::Task_SaveRawMaterials(cTaskContext& ctx) const {
+// double bonus = 0.0;
+// const cString& lineage_label = ctx.GetTaskEntry()->GetArguments().GetString(0);
+
+ // check if the task only applies to a certain label...
+ //if ((lineage_label != "-1") && (lineage_label == ctx.GetOrganism()->GetLineageLabel())) {
+ // bonus = ctx.GetOrganism()->GetSelfRawMaterials();
+ //}
return ctx.GetOrganism()->GetSelfRawMaterials();
}
-
/* This task consumes an organism's raw materials. Specifically,
if an organism has one of their own available it consumes it.
If an organism has raw materials it has received in donations/
Modified: branches/hjg-dev/source/main/cTaskLib.h
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.h 2008-11-20 02:17:30 UTC (rev 2953)
+++ branches/hjg-dev/source/main/cTaskLib.h 2008-11-20 14:29:57 UTC (rev 2954)
@@ -300,6 +300,9 @@
// reputation
double Task_UseRawMaterials(cTaskContext& ctx) const;
double Task_SaveRawMaterials(cTaskContext& ctx) const;
+ double Task_SaveRawMaterials1(cTaskContext& ctx) const;
+ double Task_SaveRawMaterials2(cTaskContext& ctx) const;
+
double Task_GoodReputation(cTaskContext& ctx) const;
double Task_ConsumeRawMaterials(cTaskContext& ctx) const;
double Task_UseManyOrgsRawMaterials(cTaskContext& ctx) const;
More information about the Avida-cvs
mailing list