[Avida-SVN] r3047 - in branches/hjg-dev/source: cpu main tools

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Mon Dec 15 08:48:49 PST 2008


Author: hjg
Date: 2008-12-15 11:48:49 -0500 (Mon, 15 Dec 2008)
New Revision: 3047

Modified:
   branches/hjg-dev/source/cpu/cHardwareCPU.cc
   branches/hjg-dev/source/cpu/cHardwareCPU.h
   branches/hjg-dev/source/main/cAvidaConfig.h
   branches/hjg-dev/source/main/cOrgInterface.h
   branches/hjg-dev/source/main/cOrganism.cc
   branches/hjg-dev/source/main/cOrganism.h
   branches/hjg-dev/source/main/cPopulation.cc
   branches/hjg-dev/source/main/cPopulationInterface.cc
   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
   branches/hjg-dev/source/tools/tBuffer.h
Log:
string cat task

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-12-15 16:48:49 UTC (rev 3047)
@@ -478,6 +478,7 @@
 		tInstLibEntry<tMethod>("rotate-to-rep-k", &cHardwareCPU::Inst_RotateToReputationK, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("rotate-to-rep-and-donate", &cHardwareCPU::Inst_RotateToGreatestReputationAndDonate, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("rotate-to-rep-tag", &cHardwareCPU::Inst_RotateToGreatestReputationWithDifferentTag, nInstFlag::STALL),
+		tInstLibEntry<tMethod>("rotate-to-tag", &cHardwareCPU::Inst_RotateToDifferentTag, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("if-donor",  &cHardwareCPU::Inst_IfDonor, nInstFlag::STALL),
 
 	
@@ -7229,7 +7230,7 @@
  a different tag. */
 bool cHardwareCPU::Inst_RotateToGreatestReputationWithDifferentTag(cAvidaContext& ctx)
 {
-	organism->GetOrgInterface().RotateToGreatestReputationWithDifferentTag(organism->GetTag());
+	organism->GetOrgInterface().RotateToGreatestReputationWithDifferentTag(organism->GetTagLabel());
 	return true;	
 }
 
@@ -7251,6 +7252,45 @@
 	return true;
 }
 
+// hjg
+bool cHardwareCPU::Inst_RotateToDifferentTag(cAvidaContext& ctx)
+{
+	//get the neighborhood size
+  const int num_neighbors = organism->GetNeighborhoodSize();
+	
+  // Turn to face a random neighbor
+  int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
+  for (int i = 0; i < neighbor_id; i++) organism->Rotate(1);
+  cOrganism * neighbor = organism->GetNeighbor();
+
+  int max_id = neighbor_id + num_neighbors;
+	
+  //we have not found a match yet
+  bool found = false;
+	
+  // rotate through orgs in neighborhood  
+  while (neighbor_id < max_id) {
+		neighbor = organism->GetNeighbor();
+		
+		//if neighbor exists, do they have a different tag?
+		if (neighbor != NULL) {
+			if (organism->GetTagLabel() != neighbor->GetTagLabel()) found = true;
+	
+		}
+		
+		// stop searching through the neighbors if we already found one
+		if (found == true){
+			break;
+		}
+	
+		organism->Rotate(1);
+		neighbor_id++;
+	}
+	
+	return true;
+}
+
+
 /* Decrease the lower reputation bar */
 bool cHardwareCPU:: Inst_DecK(cAvidaContext& ctx)
 {
@@ -7336,12 +7376,13 @@
 		
 		// Check if the donation is from one species to another
 		// If the config option is selected, then exit otherwise.
-		if (m_world->GetConfig().INTER_SPECIES_DONATION.Get()) {
+		if (m_world->GetConfig().DONATION_RESTRICTIONS.Get() == 1) {
 			int spec_self =  organism->GetLineageLabel();
 			int spec_neighbor = neighbor->GetLineageLabel();
 			if (spec_self == spec_neighbor) return true;
-		}
+		} 
 		
+		
 		// Get the organism's string from its output buffer
 		tBuffer<int> org_str (organism->GetOuptput());
 
@@ -7367,8 +7408,16 @@
 			}
 		}
 			
-		// tag the organism & update the reputation
-		organism->SetTag(best);
+		
+		// If the organism has the same tag as the neighbor, disable the 
+		// donation.
+		if (m_world->GetConfig().DONATION_RESTRICTIONS.Get() == 2) {
+			// Check if the donation is from one tag to another
+			if (organism->GetTagLabel() == neighbor->GetTagLabel()) 
+				return true;
+		}
+		
+		// update the reputation		
 		organism->SetAverageReputation(max);
 		
 		// Donate the string

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-12-15 16:48:49 UTC (rev 3047)
@@ -703,6 +703,8 @@
 	bool Inst_RotateToGreatestReputation(cAvidaContext& ctx);	
 	// Rotate to the organims with the greatest reputation that has a different tag
 	bool Inst_RotateToGreatestReputationWithDifferentTag(cAvidaContext& ctx);	
+	// Rotate to an organim with a different tag
+	bool Inst_RotateToDifferentTag(cAvidaContext& ctx);	
 	// Rotate to the organims with the greatest reputation and donate
 	bool Inst_RotateToGreatestReputationAndDonate(cAvidaContext& ctx);	
 	// Roate to Reputation k

Modified: branches/hjg-dev/source/main/cAvidaConfig.h
===================================================================
--- branches/hjg-dev/source/main/cAvidaConfig.h	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/main/cAvidaConfig.h	2008-12-15 16:48:49 UTC (rev 3047)
@@ -568,7 +568,7 @@
   CONFIG_ADD_VAR(REPUTATION_REWARD, int, 0, "Reward an organism for having a good reputation");
   CONFIG_ADD_VAR(DONATION_FAILURE_PERCENT, int, 0, "Percentage of times that a donation fails");
   CONFIG_ADD_VAR(RANDOMIZE_RAW_MATERIAL_AMOUNT, int, 0, "Should all the organisms receive the same amount 0/1 (off/on)");
-  CONFIG_ADD_VAR(INTER_SPECIES_DONATION, int, 0, "Only donations from one species to another are allowed 0/1 (off/on)");
+  CONFIG_ADD_VAR(DONATION_RESTRICTIONS, int, 0, "0=none\n1=inter-species only\n2=different tag only");
   CONFIG_ADD_VAR(INHERIT_REPUTATION, int, 0, "0=reputation are not inherited\n1=reputations are inherited\n2=tags are inherited");
   CONFIG_ADD_VAR(MATCH_PERCENT, int, 0, "0=percentage above chance\n1=percentage");
 

Modified: branches/hjg-dev/source/main/cOrgInterface.h
===================================================================
--- branches/hjg-dev/source/main/cOrgInterface.h	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/main/cOrgInterface.h	2008-12-15 16:48:49 UTC (rev 3047)
@@ -34,6 +34,8 @@
 #ifndef cOrgInterface_h
 #define cOrgInterface_h
 
+#include <string>
+
 class cAvidaContext;
 class cCodeLabel;
 class cDeme;

Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/main/cOrganism.cc	2008-12-15 16:48:49 UTC (rev 3047)
@@ -84,7 +84,7 @@
 	, m_amount_donate_received(0)
 	, m_k(0)
   , m_failed_reputation_increases(0)
-  , m_tag(0)
+  , m_tag(make_pair(-1, 0))
 {
   m_hardware = m_world->GetHardwareManager().Create(this);
 
@@ -936,3 +936,68 @@
 	m_failed_reputation_increases = m_failed_reputation_increases + (donor_list.size() - m);
 	donor_list.clear();
 }
+
+/* Update the tag. If the organism was not already tagged, 
+ or the new tag is the same as the old tag, or the number
+ of bits is > than the old tag, update.*/
+void cOrganism::UpdateTag(int new_tag, int bits)
+{
+	if ((m_tag.first == -1) || 
+			(m_tag.first == new_tag) ||
+			(m_tag.second < bits)) {
+		m_tag = make_pair(new_tag, bits);
+	} 
+}
+
+
+// Return how well the organism does on catting strings.
+int cOrganism::CheckStrCat(const cString& string_to_match)
+{
+	// for each donated string try this...
+	// Get org string & make right length
+	tBuffer<int> test_str(string_to_match.GetSize());
+	tBuffer<int> org_str (GetOutputBuf());
+	
+	int max_num_matched =0;
+	
+	// This will make the string the size of the capacity. 
+	int length = org_str.GetCapacity();
+	int org_str_length = org_str.GetTotal(); 
+	
+	while (org_str_length < length) { 
+		org_str.Add(-1);
+		org_str_length = org_str.GetTotal(); 
+	}
+	
+	int num_matched = 0;
+
+	if (m_all_received_messages.size()) {
+		// Check with org in first position...
+		for (unsigned int k = 0; k < m_all_received_messages.size(); k++) {
+			tBuffer<int> received = m_all_received_messages[k].first;
+			num_matched = 0;
+			test_str.Cat(org_str);
+			test_str.Cat(received);	
+			num_matched = MatchStringsHelper(test_str, string_to_match);
+			if (num_matched > max_num_matched){
+				max_num_matched = num_matched;
+			}
+		}
+			
+			// Check with org in first position...
+			for (unsigned int k = 0; k < m_all_received_messages.size(); k++) {
+				tBuffer<int> received = m_all_received_messages[k].first;
+				num_matched = 0;
+				test_str.Cat(received);	
+				test_str.Cat(org_str);
+				num_matched = MatchStringsHelper(test_str, string_to_match);
+				if (num_matched > max_num_matched){
+					max_num_matched = num_matched;
+				}
+			
+		}
+		
+	}
+	return max_num_matched;
+}
+

Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/main/cOrganism.h	2008-12-15 16:48:49 UTC (rev 3047)
@@ -494,6 +494,10 @@
 	std::pair < int, int > MatchString(const cString& str); 
 	//  Return the maximum number of characters matched by the strings
 	int MatchStringsHelper(tBuffer<int> org_string, const cString& string_to_match); 
+	
+	// Return how well the organism does on catting strings.
+	int CheckStrCat(const cString& string_to_match); 
+	
 	// Praise all donors of this organism and then clear the list
 	void PraiseDonors(); 
 	// Get number of failed reputation increases
@@ -501,9 +505,14 @@
 	// Add a donor
 	void AddDonor(int org_id) { donor_list.insert(org_id); }
 	// Set tag 
-	void SetTag(int new_tag) { m_tag = new_tag; }
+	void SetTag(int new_tag, int bits) { m_tag = make_pair(new_tag, bits); }
+	// Set tag
+	void SetTag(pair < int, int > new_tag)  { m_tag = new_tag; }
+	// Update tag
+	void UpdateTag(int new_tag, int bits); 
 	// Get tag
-	int GetTag() { return m_tag; }
+	int GetTagLabel() { return m_tag.first; }
+	pair < int, int > GetTag() { return m_tag; }
 	
 	
 protected:
@@ -527,7 +536,7 @@
 	vector < std::pair < tBuffer<int>, int > > m_all_received_messages;
 	// int number of reputation increase failures
 	int m_failed_reputation_increases;
-	int m_tag;
+	std::pair < int, int > m_tag;
 	
   // -------- End of reputation support --------
 

Modified: branches/hjg-dev/source/main/cPopulation.cc
===================================================================
--- branches/hjg-dev/source/main/cPopulation.cc	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/main/cPopulation.cc	2008-12-15 16:48:49 UTC (rev 3047)
@@ -361,6 +361,9 @@
 			child_array[i]->SetReputation(parent_organism.GetReputation()); 
 		} else if (m_world->GetConfig().INHERIT_REPUTATION.Get() == 2) { 
 			child_array[i]->SetTag(parent_organism.GetTag()); 	
+		}else if (m_world->GetConfig().INHERIT_REPUTATION.Get() == 3) { 
+			child_array[i]->SetTag(parent_organism.GetTag()); 
+			child_array[i]->SetReputation(parent_organism.GetReputation()); 
 		}
   }
   

Modified: branches/hjg-dev/source/main/cPopulationInterface.cc
===================================================================
--- branches/hjg-dev/source/main/cPopulationInterface.cc	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/main/cPopulationInterface.cc	2008-12-15 16:48:49 UTC (rev 3047)
@@ -413,7 +413,7 @@
 			cOrganism* cur_neighbor = faced_cell->GetOrganism();
 			
 			// if it has high reputation	
-			if ((cur_neighbor->GetTag() != tag) && (cur_neighbor->GetReputation() >= high_rep)) {
+			if ((cur_neighbor->GetTagLabel() != tag) && (cur_neighbor->GetReputation() >= high_rep)) {
 				if (cur_neighbor->GetReputation() > high_rep) {
 					high_rep = cur_neighbor->GetReputation();
 					high_rep_orgs.clear();
@@ -431,25 +431,42 @@
 	if (high_rep_orgs.size() > 0) {
 		unsigned int rand_num = m_world->GetRandom().GetUInt(0, high_rep_orgs.size()); 
 		int high_org_id = high_rep_orgs[rand_num];
+		int found = false;
 		
-		for(int i=0; i<cell.ConnectionList().GetSize(); ++i) {
-			const cPopulationCell* faced_cell = cell.ConnectionList().GetFirst();
-			
+	/*	const cPopulationCell* faced_cell = cell.ConnectionList().GetFirst();
+		while (!found) { 
+			cell.ConnectionList().CircNext();
 			if (IsNeighborCellOccupied()) {
 				
 				cOrganism* cur_neighbor = faced_cell->GetOrganism();
-				//			int test_rep = 	cell.ConnectionList().GetFirst()->GetOrganism()->GetReputation();
 				
 				// if it has high reputation	
 				if (cur_neighbor->GetID() == high_org_id) {
-					int test_id = cur_neighbor->GetTag();
-					break;
+					found = true;
 				}
 			}
-			
-			cell.ConnectionList().CircNext();
-			
-		}
+					
+		}*/
+		for(int i=0; i<cell.ConnectionList().GetSize(); ++i) {
+		 const cPopulationCell* faced_cell = cell.ConnectionList().GetFirst();
+		 
+		 if (IsNeighborCellOccupied()) {
+		 
+		 cOrganism* cur_neighbor = faced_cell->GetOrganism();
+		 //			int test_rep = 	cell.ConnectionList().GetFirst()->GetOrganism()->GetReputation();
+		 
+		 // if it has high reputation	
+		 if (cur_neighbor->GetID() == high_org_id) {
+		 break;
+		 }
+		 }
+		 
+		 cell.ConnectionList().CircNext();
+		 
+		 }
+
+		
+		
 	}
 	
 }

Modified: branches/hjg-dev/source/main/cStats.cc
===================================================================
--- branches/hjg-dev/source/main/cStats.cc	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/main/cStats.cc	2008-12-15 16:48:49 UTC (rev 3047)
@@ -1780,18 +1780,41 @@
 	df.WriteComment("Avida organism string donation information");
 	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();
 	
+	
 	// Interate through map of information.
+	map<cString,cDoubleSum>::iterator iter2;   
+  for(iter2 = m_string_bits_matched.begin(); iter2 != m_string_bits_matched.end(); iter2++ ) {
+		df.Write(iter2->second.Average(), iter2->first); 
+  }
 	
-		//	df.Write(m_donate_to_donor, "Number of donate to donor [donatedonor]");
-	//	df.Write(m_donate_to_facing, "Number of donate to facing [donatefacing]");
+	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);
+		org = cell.GetOrganism();
+		
+    if(cell.IsOccupied()) {
+			// Get tag and increment number of orgs. 
+			tags[org->GetTagLabel()]++;
+		}
+	}
 	
-	map<cString,cDoubleSum>::iterator iter;   
-  for(iter = m_string_bits_matched.begin(); iter != m_string_bits_matched.end(); iter++ ) {
-//    cout << "word: " << iter->first << ", count: " << iter->second << endl;
-		df.Write(iter->second.Average(), iter->first); 
+	// print the tags
+	map<int, int>::iterator iter;   
+	stringstream ss; 
+  for(iter = tags.begin(); iter != tags.end(); iter++ ) {
+		ss << iter->first; 
+		string name = ss.str(); 
+		df.Write(iter->second, name.c_str()); 
   }
 	
+	
   df.Endl();
 }
 

Modified: branches/hjg-dev/source/main/cStats.h
===================================================================
--- branches/hjg-dev/source/main/cStats.h	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/main/cStats.h	2008-12-15 16:48:49 UTC (rev 3047)
@@ -793,10 +793,12 @@
 	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 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;
 	
 
   

Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/main/cTaskLib.cc	2008-12-15 16:48:49 UTC (rev 3047)
@@ -356,6 +356,10 @@
     Load_MatchStr(name, info, envreqs, errors);
   else if (name == "match_number")
     Load_MatchNumber(name, info, envreqs, errors);
+	
+	if (name == "strcat") 
+    Load_StrCat(name, info, envreqs, errors);
+
   
   if (name == "sort_inputs")
     Load_SortInputs(name, info, envreqs, errors);
@@ -1916,12 +1920,24 @@
   schema.AddEntry("partial",0, 0);
   schema.AddEntry("binary",1,1);
   schema.AddEntry("pow",0,2.0);
-  cArgContainer* args = cArgContainer::Load(argstr, schema, errors);
+  cArgContainer* args = cArgContainer::Load(argstr, schema, errors);	
   envreqs.SetMinOutputs(args->GetString(0).GetSize());
   if (args) NewTask(name, "MatchStr", &cTaskLib::Task_MatchStr, 0, args);
 }
 
+/* This loads the string cat parameters.*/
+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("partial",0, 0);
+  schema.AddEntry("binary",1,1);
+  schema.AddEntry("pow",0,2.0);
+  cArgContainer* args = cArgContainer::Load(argstr, schema, errors);	
+  if (args) NewTask(name, "StrCat", &cTaskLib::Task_StrCat, 0, args);
+}
 
+
 vector<cString> cTaskLib::GetMatchStrings()
 {
 	if (m_strings.size() == 0) {
@@ -1938,14 +1954,64 @@
 	return m_strings;
 }
 
+
+/* This task checks to see if an organism can create a string by catting the
+ string in its buffer with each of the strings it has received as a donation. */
+double cTaskLib::Task_StrCat(cTaskContext& ctx) const
+{
+	tBuffer<int> temp_buf(ctx.GetOutputBuffer());
+	
+	const cString& string_to_match = ctx.GetTaskEntry()->GetArguments().GetString(0);
+  int partial = ctx.GetTaskEntry()->GetArguments().GetInt(0);
+//  int binary = ctx.GetTaskEntry()->GetArguments().GetInt(1);  
+	//int string_index;
+  //int num_matched = 0;
+  //int test_output;
+  int max_num_matched = 0;
+  int num_real=0;
+  double mypow = ctx.GetTaskEntry()->GetArguments().GetDouble(0);
+	bool used_received = false;
+
+	
+	// Given the desired string, pass it to the organism which will 
+	// check all possibilities. ?
+	
+	max_num_matched = ctx.GetOrganism()->CheckStrCat(string_to_match);
+	
+	cString name;
+	name = "[catted"; 
+	name += string_to_match;
+	name += "]";
+	m_world->GetStats().AddStringBitsMatchedValue(name, max_num_matched);
+	
+	if (max_num_matched == string_to_match.GetSize()) m_world->GetStats().IncPerfectMatch();
+	
+	
+	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,mypow);
+    if (used_received)
+      m_world->GetStats().AddMarketItemUsed();
+    else
+      m_world->GetStats().AddMarketOwnItemUsed();
+  }
+  return bonus;
+}
+
+
 double cTaskLib::Task_MatchStr(cTaskContext& ctx) const
 {
-  tBuffer<int> temp_buf(ctx.GetOutputBuffer());
-  //  if (temp_buf[0] != 357913941) return 0;
-  
-  //  temp_buf.Pop(); // pop the signal value off of the buffer
-  
-  const cString& string_to_match = ctx.GetTaskEntry()->GetArguments().GetString(0);
+	tBuffer<int> temp_buf(ctx.GetOutputBuffer());
+	
+	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);
@@ -1953,12 +2019,7 @@
   int num_matched = 0;
   int test_output;
   int max_num_matched = 0;
-//	int max_org_id; 
   int num_real=0;
-	int my_string; 
-	int donated_string;
-	std::pair < int, int > best_string; 
-	cString name;
 	
   if (!binary)
   {
@@ -1983,16 +2044,21 @@
 			if (string_to_match[j]=='0' && temp_buf[j]==0 ||
 					string_to_match[j]=='1' && temp_buf[j]==1)
 				num_matched++;
+			if (temp_buf[j]==0) { 
+				int q = 0; 
+			}
+			if (temp_buf[j]==1) { 
+				int p = 1;
+			}
+			
     }
     max_num_matched = num_matched;
-//		max_org_id = ctx.GetOrganism()->GetID();
-		my_string = num_matched;
 		
   }
-
   
+	
   bool used_received = false;
-/*  if (ctx.GetReceivedMessages()) {
+  if (ctx.GetReceivedMessages()) {
     tBuffer<int> received(*(ctx.GetReceivedMessages()));
     for (int i = 0; i < received.GetNumStored(); i++) {
       test_output = received[i];
@@ -2004,91 +2070,34 @@
         if ((string_to_match[string_index]=='0' && !(test_output & k)) ||
             (string_to_match[string_index]=='1' && (test_output & k))) num_matched++;
       }
-*/ 
-	best_string = ctx.GetOrganism()->MatchString(string_to_match);
-	num_matched = best_string.first;
-	donated_string = num_matched;
-	if (num_matched > max_num_matched) {
-		max_num_matched = num_matched;
-//		max_org_id = best_string.second;
-		used_received = true;
+      
+      if (num_matched > max_num_matched) {
+        max_num_matched = num_matched;
+        used_received = true;
+      }
+    }
 		
-		// update stats
-		name = "[useddonated"; 
-		name += string_to_match;
-		name += "]";
-		m_world->GetStats().AddStringBitsMatchedValue(name, max_num_matched);
-		
-	} else {
-		// update stats
-		name = "[usedmy"; 
-		name += string_to_match;
-		name += "]";
-		m_world->GetStats().AddStringBitsMatchedValue(name, max_num_matched);
 	}
-
+	
+	// Update the organism's tag. 
+	ctx.GetOrganism()->UpdateTag(string_to_match.AsInt(), max_num_matched);
 	// Update stats
-	
-	name = "[popavmine"; 
+	cString name;
+	name = "[produced"; 
 	name += string_to_match;
 	name += "]";
-	m_world->GetStats().AddStringBitsMatchedValue(name, my_string);
-	name = "[popavdonated"; 
-	name += string_to_match;
-	name += "]";
-	m_world->GetStats().AddStringBitsMatchedValue(name, donated_string);
-	name = "[score"; 
-	name += string_to_match;
-	name += "]";
 	m_world->GetStats().AddStringBitsMatchedValue(name, max_num_matched);
 	
-	
-	// Update the reputation of the organism whose string we used!
-	// Check if it the organisms string: 
-/*	cOrganism * neighbor = ctx.GetOrganism()->GetNeighbor();
-	if (max_org_id == ctx.GetOrganism()->GetID()) { 
-		ctx.GetOrganism()->IncReputation(); 
-	} else { 
-		// Rotate through neigbhors and look for the organism that donated
-		// the string
-		const int num_neighbors = ctx.GetOrganism()->GetNeighborhoodSize();
-		for (int i = 0; i < num_neighbors; i++){
-			// Check if this neigbhor donated the string
-			neighbor = ctx.GetOrganism()->GetNeighbor();
-					
-			if ((neighbor != NULL) && (neighbor->GetID() == max_org_id)){
-				neighbor->IncReputation();
-			}
-					
-			ctx.GetOrganism()->Rotate(1);
-		}
-		
-	}
-	*/
-	
-	name = "[resets]";
 	// if the organism hasn't donated, then zero out its reputation. 
 	if ((ctx.GetOrganism()->GetReputation() > 0) && 
 			(ctx.GetOrganism()->GetNumberOfDonations() == 0)) {
-						ctx.GetOrganism()->SetReputation(0);
-		m_world->GetStats().AddStringBitsMatchedValue(name, 1);
+		ctx.GetOrganism()->SetReputation(0);
 	}
-			
 	
-	
-	
-  double bonus = 0.0;
+	double bonus = 0.0;
   // return value between 0 & 1 representing the percentage of string that was matched
-	double base_bonus = 0.0; 
 	
-	if (m_world->GetConfig().MATCH_PERCENT.Get() == 1) {
-		// percent over 50% (Sherri)
-		base_bonus = static_cast<double>(max_num_matched) * 2.0 / static_cast<double>(string_to_match.GetSize()) - 1;
-	} else if (m_world->GetConfig().MATCH_PERCENT.Get() == 2) {
-		// percent (hjg)
-		base_bonus = static_cast<double>(max_num_matched) / static_cast<double>(string_to_match.GetSize());
-	}
-	
+  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;
@@ -2101,12 +2110,11 @@
     else
       m_world->GetStats().AddMarketOwnItemUsed();
   }
+  return bonus;
 	
-  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-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/main/cTaskLib.h	2008-12-15 16:48:49 UTC (rev 3047)
@@ -250,6 +250,8 @@
   double Task_MatchStr(cTaskContext& ctx) const;
   void Load_MatchNumber(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);
   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;	
 
   void Load_SortInputs(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);
   double Task_SortInputs(cTaskContext& ctx) const;

Modified: branches/hjg-dev/source/tools/tBuffer.h
===================================================================
--- branches/hjg-dev/source/tools/tBuffer.h	2008-12-15 15:51:50 UTC (rev 3046)
+++ branches/hjg-dev/source/tools/tBuffer.h	2008-12-15 16:48:49 UTC (rev 3047)
@@ -66,6 +66,15 @@
     last_total = in.last_total;
     return *this;
   }
+	
+	void Cat(const tBuffer<T>& b) {
+		for(int i=0; i<b.GetCapacity(); ++i) {
+			Add(b[i]);
+		}
+//		for i in b:
+//			Add(i)
+		
+	}
 
   void Clear() { offset = 0; total = 0; last_total = 0; }
   void ZeroNumAdds() { last_total = total; total = 0; }




More information about the Avida-cvs mailing list