[Avida-SVN] r3068 - in branches/hjg-dev/source: . cpu main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Sun Dec 21 10:32:44 PST 2008


Author: hjg
Date: 2008-12-21 13:32:44 -0500 (Sun, 21 Dec 2008)
New Revision: 3068

Modified:
   branches/hjg-dev/source/cpu/cHardwareCPU.cc
   branches/hjg-dev/source/cpu/cHardwareCPU.h
   branches/hjg-dev/source/defs.h
   branches/hjg-dev/source/main/cOrganism.cc
   branches/hjg-dev/source/main/cOrganism.h
Log:
integration of basic indirect model with strings.

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-12-20 22:37:42 UTC (rev 3067)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-12-21 18:32:44 UTC (rev 3068)
@@ -482,7 +482,7 @@
 		tInstLibEntry<tMethod>("rotate-to-tag", &cHardwareCPU::Inst_RotateToDifferentTag, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("if-donor",  &cHardwareCPU::Inst_IfDonor, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("str-cat",  &cHardwareCPU::Inst_StrCatOrg, nInstFlag::STALL),
-	
+		tInstLibEntry<tMethod>("prod-string",  &cHardwareCPU::Inst_ProduceString, nInstFlag::STALL),
 
     // Must always be the last instruction in the array
     tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
@@ -7006,8 +7006,7 @@
 		int spec_neighbor = neighbor->GetLineageLabel();
 		
 		if (spec_self != spec_neighbor) {
-			m_world->GetStats().IncDonateToDonor();
-			Inst_DonateFacingRawMaterialsOneType(ctx);	
+			Inst_DonateFacingRawMaterials(ctx);	
 		}
 	}
 	return true;
@@ -7019,17 +7018,15 @@
   
 	// Get faced neighbor
   cOrganism * neighbor = organism->GetNeighbor();
+	int cost = m_world->GetConfig().ALT_COST.Get(); 
+
 	
   // Donate only if we have found a neighbor.
   if (neighbor != NULL) {
-	
-	// update stats
-	m_world->GetStats().IncDonateToFacing();
 
-	
     // Subtract raw materials from the organism (currently subtracts 1 resource...)
 	// fails if the organism does not have any more resources
-	if (organism->SubtractSelfRawMaterials(1)) {
+	if (organism->SubtractSelfRawMaterials(cost)) {
 	
 		// sometimes the donation will fail. 
 		// get the probability of failure
@@ -7042,7 +7039,7 @@
 		}
 	
 	
-		neighbor->AddOtherRawMaterials(1, organism->GetID()); 
+		neighbor->AddOtherRawMaterials(cost, organism->GetID()); 
 		
 		// rotate recipient to face donor 
 		// by rotating until the recipient faces the donor
@@ -7492,3 +7489,27 @@
 	organism->SetStringCatter(true);
 	return true;
 }
+
+
+/* Check if the string in the organisms buffer corresponds to the 
+ string it is producing. If so, -1 out the buffer and increment the 
+ number of raw materials the organism has. Otherwise, do nothing. */
+bool cHardwareCPU::Inst_ProduceString(cAvidaContext& ctx)
+{
+
+	int num = 0;
+	// For the time being this instruction is hardcoded for 2 strings and
+	// two species.
+	if (organism->GetLineageLabel() == 0) {
+		num = organism->MatchOutputBuffer(cString("0000")); 
+	} else if (organism->GetLineageLabel() == 1) { 
+		num =  organism->MatchOutputBuffer(cString("1111")); 
+	}
+	
+	if (num == 4) {
+		organism->AddSelfRawMaterials(1); 
+		organism->SetOutputNegative1() ; 
+	}
+	return true;
+}
+

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-12-20 22:37:42 UTC (rev 3067)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-12-21 18:32:44 UTC (rev 3068)
@@ -700,7 +700,6 @@
 	// Donate a string to the neighbor if it was a donor
 	bool Inst_DonateStringIfDonor(cAvidaContext& ctx);
 	
-	
 	// Rotate to the organims with the greatest reputation
 	bool Inst_RotateToGreatestReputation(cAvidaContext& ctx);	
 	// Rotate to the organims with the greatest reputation that has a different tag
@@ -721,6 +720,8 @@
 	bool Inst_IfDonor(cAvidaContext& ctx);
 	// Indicate that the organism is a string catter
 	bool Inst_StrCatOrg(cAvidaContext& ctx);
+	// Produce string
+	bool Inst_ProduceString(cAvidaContext& ctx);
 	
   // Get the organism's raw material level
   bool Inst_GetAmountOfRawMaterials(cAvidaContext& ctx);

Modified: branches/hjg-dev/source/defs.h
===================================================================
--- branches/hjg-dev/source/defs.h	2008-12-20 22:37:42 UTC (rev 3067)
+++ branches/hjg-dev/source/defs.h	2008-12-21 18:32:44 UTC (rev 3068)
@@ -71,7 +71,7 @@
 
 // Number of distinct input and outputs stored in the IOBufs (to test tasks)
 const int INPUT_SIZE_DEFAULT = 3;
-const int OUTPUT_SIZE_DEFAULT = 1;
+const int OUTPUT_SIZE_DEFAULT = 4;
 #define RECEIVED_MESSAGES_SIZE 10
 const int MARKET_SIZE = 10000;
 

Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc	2008-12-20 22:37:42 UTC (rev 3067)
+++ branches/hjg-dev/source/main/cOrganism.cc	2008-12-21 18:32:44 UTC (rev 3068)
@@ -1002,3 +1002,25 @@
 	return max_num_matched;
 }
 
+/* See if the output buffer matches the string */
+int cOrganism::MatchOutputBuffer(cString string_to_match)
+{
+	tBuffer<int> org_str (GetOutputBuf());
+	int num_matched =0; 
+	for (int j = 0; j < string_to_match.GetSize(); j++)
+	{
+		if (string_to_match[j]=='0' && org_str[j]==0 ||
+				string_to_match[j]=='1' && org_str[j]==1)
+			num_matched++;
+	}
+	return num_matched;
+}
+
+
+void cOrganism::SetOutputNegative1() 
+{ 
+	for (int i=0; i<GetOutputBuf().GetCapacity(); i++) {
+		AddOutput(-1);
+	}
+	m_output_buf.Clear(); 
+}

Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h	2008-12-20 22:37:42 UTC (rev 3067)
+++ branches/hjg-dev/source/main/cOrganism.h	2008-12-21 18:32:44 UTC (rev 3068)
@@ -113,7 +113,6 @@
   tBuffer<int> m_input_buf;
   tBuffer<int> m_output_buf;
   tBuffer<int> m_received_messages;
-//	vector < tBuffer<int> >  m_all_received_messages;
   tList<tListNode<cSaleItem> > m_sold_items;
 
   // Communication
@@ -262,6 +261,7 @@
   void ClearInput() { m_input_buf.Clear(); }
   void ResetInput() {m_input_pointer = 0; m_input_buf.Clear(); };
   void AddOutput(int val) { m_output_buf.Add(val); }
+	void ClearOutput() { m_output_buf.Clear(); }
 	tBuffer<int> GetOuptput() { return m_output_buf; }
 
   // --------  Divide Methods  --------
@@ -454,6 +454,8 @@
 	bool AddOtherRawMaterials(int amount, int donor_id);
 	// receive raw materials 
 	bool AddRawMaterials(int amount, int donor_id);
+	// receive raw materials 
+	void AddSelfRawMaterials(int amount) { m_self_raw_materials += amount;}
 	// retrieve the organism's own amount of raw materials
 	int GetSelfRawMaterials() { return m_self_raw_materials; }
 	// retrieve the amount of raw materials collected from others
@@ -499,7 +501,11 @@
 	
 	// 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);
+
 	
+	
 	// Praise all donors of this organism and then clear the list
 	void PraiseDonors(); 
 	// Get number of failed reputation increases
@@ -517,6 +523,7 @@
 	pair < int, int > GetTag() { return m_tag; }
 	void SetStringCatter(bool val) { m_strcatter = val; }
 	bool GetStringCatter() { return m_strcatter; }
+	void SetOutputNegative1();
 
 	
 protected:




More information about the Avida-cvs mailing list