[Avida-SVN] r3056 - branches/hjg-dev/source/main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Wed Dec 17 14:18:36 PST 2008


Author: hjg
Date: 2008-12-17 17:18:36 -0500 (Wed, 17 Dec 2008)
New Revision: 3056

Modified:
   branches/hjg-dev/source/main/cOrganism.h
   branches/hjg-dev/source/main/cStats.cc
   branches/hjg-dev/source/main/cStats.h
   branches/hjg-dev/source/main/cTaskLib.cc
   branches/hjg-dev/source/main/cTaskLib.h
Log:


Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h	2008-12-17 03:43:07 UTC (rev 3055)
+++ branches/hjg-dev/source/main/cOrganism.h	2008-12-17 22:18:36 UTC (rev 3056)
@@ -515,8 +515,8 @@
 	pair < int, int > GetTag() { return m_tag; }
 	void SetStringCatter(bool val) { m_strcatter = val; }
 	bool GetStringCatter() { return m_strcatter; }
+
 	
-	
 protected:
 	// The organism's own raw materials
 	int m_self_raw_materials; 

Modified: branches/hjg-dev/source/main/cStats.cc
===================================================================
--- branches/hjg-dev/source/main/cStats.cc	2008-12-17 03:43:07 UTC (rev 3055)
+++ branches/hjg-dev/source/main/cStats.cc	2008-12-17 22:18:36 UTC (rev 3056)
@@ -1781,7 +1781,7 @@
 	df.WriteTimeStamp();
 	df.Write(m_update,   "Update [update]");
 	cOrganism* org; 
-
+	
 	// Print number of perfect matches
 	df.Write(m_perfect_match.Sum(), "PerfectMatch"); 
 	m_perfect_match.Clear();
@@ -1793,7 +1793,7 @@
 		df.Write(iter2->second.Average(), iter2->first); 
   }
 	
-	map<int, int> tags;
+	
 	// Create a map of the current tags in the population .
 	for(int i=0; i<m_world->GetPopulation().GetSize(); ++i) {
     cPopulationCell& cell = m_world->GetPopulation().GetCell(i);
@@ -1801,17 +1801,18 @@
 		
     if(cell.IsOccupied()) {
 			// Get tag and increment number of orgs. 
-			tags[org->GetTagLabel()]++;
+			m_tags[org->GetTagLabel()]++;
 		}
 	}
 	
 	// print the tags
 	map<int, int>::iterator iter;   
 	stringstream ss; 
-  for(iter = tags.begin(); iter != tags.end(); iter++ ) {
+  for(iter = m_tags.begin(); iter != m_tags.end(); iter++ ) {
 		ss << iter->first; 
 		string name = ss.str(); 
 		df.Write(iter->second, name.c_str()); 
+		iter->second = 0;
   }
 	
 	

Modified: branches/hjg-dev/source/main/cStats.h
===================================================================
--- branches/hjg-dev/source/main/cStats.h	2008-12-17 03:43:07 UTC (rev 3055)
+++ branches/hjg-dev/source/main/cStats.h	2008-12-17 22:18:36 UTC (rev 3056)
@@ -793,13 +793,14 @@
 	void IncDonateToFacing() { m_donate_to_facing++; }
 	void PrintStringMatchData(const cString& filename);
 	void AddStringBitsMatchedValue(cString name, int value) { m_string_bits_matched[name].Add(value); }
+	void AddTag(int tag, int value) { m_tags[tag] = m_tags[tag] + value; }
 	void IncPerfectMatch() { m_perfect_match.Add(1); }
 protected: 
 	int m_donate_to_donor; 
 	int m_donate_to_facing;
 	std::map <cString, cDoubleSum> m_string_bits_matched;
 	cDoubleSum m_perfect_match;
-	
+	std::map <int, int> m_tags;
 
   
   // -------- Deme replication support --------

Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc	2008-12-17 03:43:07 UTC (rev 3055)
+++ branches/hjg-dev/source/main/cTaskLib.cc	2008-12-17 22:18:36 UTC (rev 3056)
@@ -433,6 +433,8 @@
     NewTask(name, "Consume raw materials", &cTaskLib::Task_ConsumeRawMaterials);			
   else if(name == "save_raw_mat")
     NewTask(name, "Save raw materials", &cTaskLib::Task_SaveRawMaterials);	
+	else if(name == "all_strings")
+    NewTask(name, "Produce or collect all strings", &cTaskLib::Task_AllStrings);	
 
   // event tasks
   if(name == "move_to_event")
@@ -1915,13 +1917,16 @@
 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("string", 0, cArgSchema::SCHEMA_STRING);		
   schema.AddEntry("partial",0, 0);
   schema.AddEntry("binary",1,1);
   schema.AddEntry("pow",0,2.0);
+	schema.AddEntry("tag",2,-1);
   cArgContainer* args = cArgContainer::Load(argstr, schema, errors);	
   envreqs.SetMinOutputs(args->GetString(0).GetSize());
 	m_strings.push_back(args->GetString(0));
+//	m_world->GetStats().AddTag(args->GetInt(2), 0);
+//	m_world->GetStats().AddTag(-1, 0);
   if (args) NewTask(name, "MatchStr", &cTaskLib::Task_MatchStr, 0, args);
 }
 
@@ -1929,7 +1934,7 @@
 void cTaskLib::Load_StrCat(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors)
 {
   cArgSchema schema;
-  schema.AddEntry("string", 0, cArgSchema::SCHEMA_STRING);
+	schema.AddEntry("string", 0, cArgSchema::SCHEMA_STRING);
   schema.AddEntry("partial",0, 0);
   schema.AddEntry("binary",1,1);
   schema.AddEntry("pow",0,2.0);
@@ -1940,7 +1945,6 @@
 
 vector<cString> cTaskLib::GetMatchStrings()
 {
-	
 	return m_strings;
 }
 
@@ -1950,7 +1954,7 @@
 double cTaskLib::Task_StrCat(cTaskContext& ctx) const
 {
 	
-	if (ctx.GetOrganism()->GetStringCatter()==0) return 0;
+	//if (ctx.GetOrganism()->GetStringCatter()==0) return 0;
 
 	tBuffer<int> temp_buf(ctx.GetOutputBuffer());
 	
@@ -2021,6 +2025,10 @@
 	
 	if (ctx.GetOrganism()->GetStringCatter()) return 0;
 	
+	// These even out the stats tracking.
+	m_world->GetStats().AddTag(ctx.GetTaskEntry()->GetArguments().GetInt(2), 0);
+	m_world->GetStats().AddTag(-1, 0);
+	
 	tBuffer<int> temp_buf(ctx.GetOutputBuffer());
 	
 	const cString& string_to_match = ctx.GetTaskEntry()->GetArguments().GetString(0);
@@ -2062,8 +2070,7 @@
   }
 	
 	// Update the organism's tag. 
-	// Tag 0 indicates the organism is a producer
-	ctx.GetOrganism()->UpdateTag(0, max_num_matched);
+	ctx.GetOrganism()->UpdateTag(ctx.GetTaskEntry()->GetArguments().GetInt(2), max_num_matched);
 	// Update stats
 	cString name;
 	name = "[produced"; 
@@ -2091,6 +2098,7 @@
 		}
 	}
 	
+
 	double bonus = 0.0;
 	double base_bonus = 0.0; 
 
@@ -2116,6 +2124,57 @@
 }
 
 
+double cTaskLib::Task_AllStrings(cTaskContext& ctx) const
+{
+	// Check if the organism either created or received as a donation ; 
+	// if it misses one, then fail it. 
+	tBuffer<int> temp_buf(ctx.GetOutputBuffer());
+	
+	cString string_to_match; // = ctx.GetTaskEntry()->GetArguments().GetString(0);
+	//  int binary = ctx.GetTaskEntry()->GetArguments().GetInt(1);  
+	//int string_index;
+  int num_matched = 0;
+  //int test_output;
+  int max_num_matched = 0;
+	int sum_matched;
+  int num_real=0;
+	double bonus = 0; 
+	int total_size = 0;
+	
+	
+	// Given the desired string, pass it to the organism which will 
+	// check all possibilities. ?
+	for (unsigned int i=0; i<m_strings.size(); i++) { 
+		num_matched = 0;
+		string_to_match = m_strings[i];
+		// Check if the organism created the string. 
+		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; 
+		
+		num_matched = ctx.GetOrganism()->MatchString(m_strings[i]).first;
+		if (num_matched > max_num_matched) max_num_matched = num_matched; 
+		
+		sum_matched += max_num_matched; 
+		total_size += string_to_match.GetSize();
+	}
+	
+	if (sum_matched == total_size) {
+		m_world->GetStats().IncPerfectMatch();
+		bonus = 1.0;
+	}
+	
+  return bonus;
+}
+
+
 void cTaskLib::Load_MatchNumber(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors)
 {
   cArgSchema schema;

Modified: branches/hjg-dev/source/main/cTaskLib.h
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.h	2008-12-17 03:43:07 UTC (rev 3055)
+++ branches/hjg-dev/source/main/cTaskLib.h	2008-12-17 22:18:36 UTC (rev 3056)
@@ -252,6 +252,7 @@
   double Task_MatchNumber(cTaskContext& ctx) const;
 	void Load_StrCat(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);
   double Task_StrCat(cTaskContext& ctx) const;	
+  double Task_AllStrings(cTaskContext& ctx) const;	
 
 	
   void Load_SortInputs(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);




More information about the Avida-cvs mailing list