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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Tue Dec 30 08:11:54 PST 2008


Author: hjg
Date: 2008-12-30 11:11:54 -0500 (Tue, 30 Dec 2008)
New Revision: 3081

Modified:
   branches/hjg-dev/source/main/cOrganism.cc
   branches/hjg-dev/source/main/cOrganism.h
   branches/hjg-dev/source/main/cTaskLib.cc
Log:
Cleaned up string matching code in cOrganism

Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc	2008-12-30 16:01:19 UTC (rev 3080)
+++ branches/hjg-dev/source/main/cOrganism.cc	2008-12-30 16:11:54 UTC (rev 3081)
@@ -85,7 +85,6 @@
 	, m_k(0)
   , m_failed_reputation_increases(0)
   , m_tag(make_pair(-1, 0))
-  , m_strcatter(0)
 {
   m_hardware = m_world->GetHardwareManager().Create(this);
 
@@ -860,60 +859,7 @@
 }
 
 
-void cOrganism::ReceiveString(tBuffer<int> str, int org_id) 
-{ 
-//	m_all_received_messages.push_back(new_donation); 
-	donor_list.insert(org_id); 
-	m_all_received_messages.push_back(make_pair(str, org_id));
-	m_num_donate_received++;
-}
 
-/* Return an int that represents the largest number of bits
- matched by any of the strings received. */
-std::pair < int, int > cOrganism::MatchString(const cString& string_to_match) 
-{
-  int num_matched = 0;
-  int max_num_matched = 0;
-	int org_id = 0;
-	
-	if (m_all_received_messages.size()) {
-	
-		for (unsigned int k = 0; k < m_all_received_messages.size(); k++) {
-			tBuffer<int> received = m_all_received_messages[k].first;
-			num_matched = 0;
-			/*for (int j = 0; j < string_to_match.GetSize(); j++)
-			{
-				if (string_to_match[j]=='0' && received[j]==0 ||
-						string_to_match[j]=='1' && received[j]==1)
-					num_matched++;
-			}*/
-			num_matched = MatchStringsHelper(received, string_to_match);
-			if (num_matched > max_num_matched){
-				max_num_matched = num_matched;
-				org_id = m_all_received_messages[k].second;
-			}
-		}
-		
-	}
-	return make_pair(max_num_matched, org_id);
-}
-
-/* Return the number of bits matched in the two strings. This is 
- generalized so that it can be used not just by the task, but also
- by the donate-string instruction. */
-int cOrganism::MatchStringsHelper(tBuffer<int> org_string, const cString& string_to_match)
-{
-	int num_matched = 0;
-	for (int j = 0; j < string_to_match.GetSize(); j++)
-	{
-		if (string_to_match[j]=='0' && org_string[j]==0 ||
-				string_to_match[j]=='1' && org_string[j]==1)
-			num_matched++;
-	}
-	return num_matched;
-}
-
-
 /* Increase the reputation of all of the organisms that donated to this
  organism. Then, clear the donors list.*/
 void cOrganism::PraiseDonors()
@@ -951,57 +897,6 @@
 }
 
 
-// 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;
-}
-
 /* See if the output buffer matches the string */
 int cOrganism::MatchOutputBuffer(cString string_to_match)
 {

Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h	2008-12-30 16:01:19 UTC (rev 3080)
+++ branches/hjg-dev/source/main/cOrganism.h	2008-12-30 16:11:54 UTC (rev 3081)
@@ -492,15 +492,7 @@
 	void DecK() { m_k--; }
 	// was the organism a donor
 	bool IsDonor(int neighbor_id); 
-	// Receive a string
-	void ReceiveString(tBuffer<int> str, int org_id); 
-	// Return the maximum number of characters and the organism id matched by the received strings
-	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); 
+
 	// Check if buffer contains this string; return # bits correct
 	int MatchOutputBuffer(cString string_to_match);
 
@@ -521,8 +513,8 @@
 	// Get tag
 	int GetTagLabel() { return m_tag.first; }
 	pair < int, int > GetTag() { return m_tag; }
-	void SetStringCatter(bool val) { m_strcatter = val; }
-	bool GetStringCatter() { return m_strcatter; }
+	
+	
 	void SetOutputNegative1();
 	void AddDonatedLineage(int lin) { donating_lineages.insert(lin); }
 	int GetNumberOfDonatedLineages() { return donating_lineages.size(); }
@@ -548,11 +540,9 @@
 	// reputation minimum for donation/rotation 
 	// based on Nowak89
 	int m_k;
-	vector < std::pair < tBuffer<int>, int > > m_all_received_messages;
 	// int number of reputation increase failures
 	int m_failed_reputation_increases;
 	std::pair < int, int > m_tag;
-	bool m_strcatter; 
 	
   // -------- End of reputation support --------
 

Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc	2008-12-30 16:01:19 UTC (rev 3080)
+++ branches/hjg-dev/source/main/cTaskLib.cc	2008-12-30 16:11:54 UTC (rev 3081)
@@ -1949,7 +1949,6 @@
 double cTaskLib::Task_MatchStr(cTaskContext& ctx) const
 {
 	
-	if (ctx.GetOrganism()->GetStringCatter()) return 0;
 	
 	// These even out the stats tracking.
 	m_world->GetStats().AddTag(ctx.GetTaskEntry()->GetArguments().GetInt(2), 0);
@@ -2014,20 +2013,8 @@
 		ctx.GetOrganism()->SetReputation(0);
 	}
  
- 
-	std::pair < int, int > best_string; 
-	int donated_string;
 
 
-		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;
-		}
-
-
 	double bonus = 0.0;
 	double base_bonus = 0.0; 
 




More information about the Avida-cvs mailing list