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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Thu Oct 9 10:32:23 PDT 2008


Author: hjg
Date: 2008-10-09 13:32:23 -0400 (Thu, 09 Oct 2008)
New Revision: 2822

Modified:
   branches/hjg-dev/CMakeLists.txt
   branches/hjg-dev/source/actions/EnvironmentActions.cc
   branches/hjg-dev/source/cpu/cHardwareCPU.cc
   branches/hjg-dev/source/cpu/cHardwareCPU.h
   branches/hjg-dev/source/main/cOrganism.cc
   branches/hjg-dev/source/main/cOrganism.h
   branches/hjg-dev/source/main/cTaskLib.cc
   branches/hjg-dev/source/main/cTaskLib.h
Log:
reverted branch to 2808 to undo a bug

Modified: branches/hjg-dev/CMakeLists.txt
===================================================================
--- branches/hjg-dev/CMakeLists.txt	2008-10-08 20:23:14 UTC (rev 2821)
+++ branches/hjg-dev/CMakeLists.txt	2008-10-09 17:32:23 UTC (rev 2822)
@@ -38,8 +38,8 @@
       SET(COMPILER_WARNING_FLAGS "")
       SET(COMPILER_OPTIMIZATION_FLAGS "")
     ELSE (CMAKE_CXX_COMPILER MATCHES ".*icpc.*")
-      SET(COMPILER_WARNING_FLAGS "-Wno-unknown-pragmas -Wconversion -Wno-trigraphs")
-      SET(COMPILER_OPTIMIZATION_FLAGS "-ffast-math -fno-rtti -funroll-loops -fstrict-aliasing ")
+      SET(COMPILER_WARNING_FLAGS "-Wextra -Wno-unknown-pragmas -Wconversion -Wno-trigraphs")
+      SET(COMPILER_OPTIMIZATION_FLAGS "-ffast-math -fno-rtti -funroll-loops -fstrict-aliasing -ftree-vectorize -fvisibility-inlines-hidden")
     ENDIF (CMAKE_CXX_COMPILER MATCHES ".*icpc.*")
   ENDIF (CMAKE_CXX_COMPILER MATCHES ".*pathCC.*")
 

Modified: branches/hjg-dev/source/actions/EnvironmentActions.cc
===================================================================
--- branches/hjg-dev/source/actions/EnvironmentActions.cc	2008-10-08 20:23:14 UTC (rev 2821)
+++ branches/hjg-dev/source/actions/EnvironmentActions.cc	2008-10-09 17:32:23 UTC (rev 2822)
@@ -22,7 +22,7 @@
  *
  */
 
-#include <cmath>
+#include "math.h"
 #include "EnvironmentActions.h"
 
 #include "cAction.h"
@@ -554,7 +554,7 @@
 	void Process(cAvidaContext& ctx)
 	{
 		int time = m_world->GetStats().GetUpdate();
-		double m_res_count = -1*(0.4*tanh((double)(time-182500)/50000)+0.5)*(0.5*sin(time/58.091)+0.5)+1;
+		double m_res_count = -1*(0.4*tanh((time-182500)/50000)+0.5)*(0.5*sin(time/58.091)+0.5)+1;
 		cResource* res = m_world->GetEnvironment().GetResourceLib().GetResource(m_res_name);
 		if (res != NULL)
 			m_world->GetPopulation().SetResource(res->GetID(), m_res_count);
@@ -582,7 +582,7 @@
 	void Process(cAvidaContext& ctx)
 	{
 		int time = m_world->GetStats().GetUpdate();
-		double m_res_count = -m_scale*(tanh((double)(time-182500)/50000)+1)*(0.5*sin(time/58.091)+0.5)+1;
+		double m_res_count = -m_scale*(tanh((time-182500)/50000)+1)*(0.5*sin(time/58.091)+0.5)+1;
 		if(m_res_count < 0.0)
 			m_res_count = 0.0;
 		cResource* res = m_world->GetEnvironment().GetResourceLib().GetResource(m_res_name);
@@ -614,7 +614,7 @@
 	void Process(cAvidaContext& ctx)
 	{
 		int time = m_world->GetStats().GetUpdate();
-		double m_res_count = -m_scale*(tanh((double)(time-1825000)/500000)+1)*(0.5*sin(time/58.091)+0.5)+1;
+		double m_res_count = -m_scale*(tanh((time-1825000)/500000)+1)*(0.5*sin(time/58.091)+0.5)+1;
 		if(m_res_count < 0.0)
 			m_res_count = 0.0;
 		cResource* res = m_world->GetEnvironment().GetResourceLib().GetResource(m_res_name);

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-10-08 20:23:14 UTC (rev 2821)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-10-09 17:32:23 UTC (rev 2822)
@@ -449,15 +449,11 @@
     // These are STALLs because opinions are only relevant with respect to time.
     tInstLibEntry<tMethod>("set-opinion", &cHardwareCPU::Inst_SetOpinion, nInstFlag::STALL),
     tInstLibEntry<tMethod>("get-opinion", &cHardwareCPU::Inst_GetOpinion, nInstFlag::STALL),
-    tInstLibEntry<tMethod>("get-neighbor-opinion", &cHardwareCPU::Inst_GetNeighborOpinion, nInstFlag::STALL),
 	
 	// Reputation instructions
 	tInstLibEntry<tMethod>("donate-frm", &cHardwareCPU::Inst_DonateFacingRawMaterials, nInstFlag::STALL),
-//	tInstLibEntry<tMethod>("if-donor", &cHardwareCPU::Inst_IfDonor, nInstFlag::STALL),
-	tInstLibEntry<tMethod>("sense-self-rm", &cHardwareCPU::Inst_SenseSelfRawMaterialAmount, nInstFlag::STALL),
 
 
-
     // Must always be the last instruction in the array
     tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
   };
@@ -6674,33 +6670,7 @@
   return true;
 }
 
-/*! Sense the organism's (facing) neighbor's current opinion, placing the opinion 
- in register ?BX? and the age of that opinion (in updates) in register !?BX?.  If 
- the organism has no opinion, do nothing.
- */
-bool cHardwareCPU::Inst_GetNeighborOpinion(cAvidaContext& ctx)
-{
-  // Get faced neighbor
-  cOrganism * neighbor = organism->GetNeighbor();
 
-  // track if an organism has checked reputation
-  organism->CheckedReputation();
-  
-  const int opinion_reg = FindModifiedRegister(REG_BX);
-  const int age_reg = FindNextRegister(opinion_reg);
-  
-  if(neighbor != NULL && neighbor->HasOpinion()) {
-    GetRegister(opinion_reg) = neighbor->GetOpinion().first;
-    GetRegister(age_reg) = m_world->GetStats().GetUpdate() - neighbor->GetOpinion().second;
-  } else {
-	// the neighbor has not donated, thus set to 0.
-	GetRegister(opinion_reg) = 0;
-    GetRegister(age_reg) = m_world->GetStats().GetUpdate();  
-  }
-  return true;
-}
-
-
 /* Donate raw materials to the facing organism. */
 bool cHardwareCPU::Inst_DonateFacingRawMaterials(cAvidaContext& ctx)
 {
@@ -6719,51 +6689,16 @@
     // Subtract raw materials from the organism (currently subtracts 1 resource...)
 	// fails if the organism does not have any more resources
 	if (organism->SubtractSelfRawMaterials(1)) {
-		neighbor->AddOtherRawMaterials(1, organism->GetID()); 
+		neighbor->AddOtherRawMaterials(1); 
 		
 		// rotate recipient to face donor 
 		// by rotating until the recipient faces the donor
+		// adding a new comment.
 		while (neighbor->GetNeighbor() != organism) {
 			neighbor->Rotate(1);
 		}
-		
-		// update the donor's reputation by incrementing by 1.
-		// check for a reputation
-		if (organism->HasOpinion()) {
-			organism->SetOpinion(organism->GetOpinion().first + 1);
-		} else {
-			organism->SetOpinion(1);
-		}
 	}
 	isSuccessful = true;
   }
   return isSuccessful;
 }  
-
-
-/* Check if the neighbor organism that you are facing has previously donated 
-to you. If so, */
-/*bool cHardwareCPU::Inst_IfDonor(cAvidaContext& ctx)
-{
-	if (organism->IsNeighborCellOccupied()) {
-		if (!(organism->IsDonor(organism->GetNeighbor()->GetID())))
-				IP().Advance();
-	} else {
-		IP().Advance();
-	}
-	return true;
-}*/
-
-/* Put the amout of raw materials this organism has into its 
-?BX? register. */
-
-bool cHardwareCPU::Inst_SenseSelfRawMaterialAmount(cAvidaContext& ctx)
-{
-  const int raw_mat_reg = FindModifiedRegister(REG_BX);
-  GetRegister(raw_mat_reg) = organism->GetSelfRawMaterials();
-
-  return true;
-}
-
-
-

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-10-08 20:23:14 UTC (rev 2821)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-10-09 17:32:23 UTC (rev 2822)
@@ -665,8 +665,6 @@
   bool Inst_SetOpinion(cAvidaContext& ctx);
   //! Retrieve this organism's current opinion.
   bool Inst_GetOpinion(cAvidaContext& ctx);
-  //! Retrieve the opinion of the facing neighbor.
-  bool Inst_GetNeighborOpinion(cAvidaContext& ctx);
   
   
   // -------- Reputation support --------
@@ -676,8 +674,6 @@
   reputation based cooperation.
   */ 
   bool Inst_DonateFacingRawMaterials(cAvidaContext& ctx);
-//  bool Inst_IfDonor(cAvidaContext& ctx);
-  bool Inst_SenseSelfRawMaterialAmount(cAvidaContext& ctx);
 
 };
 

Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc	2008-10-08 20:23:14 UTC (rev 2821)
+++ branches/hjg-dev/source/main/cOrganism.cc	2008-10-09 17:32:23 UTC (rev 2822)
@@ -759,24 +759,19 @@
 
 /* Called when raw materials are received from others. Amount is the number of resources received.
 The boolean flag is used to indicate if the reception was successful, which should always
-be the case... Additionally, we add the donor to a set*/
+be the case... */
 
-bool cOrganism::AddOtherRawMaterials (int amount, int donor_id) {
+bool cOrganism::AddOtherRawMaterials (int amount) {
 	bool isSuccessful = true;
 	InitReputation();
 	m_other_raw_materials += amount;
-	donor_list.insert(donor_id);
 	return isSuccessful;
 }
 
+/* Called when a orgaism receives a donation in order to turn the recipient to 
+face its donor. It is designed to work in conjunction with the fact that an 
+orgaism donates to the neighbor it is facing. */
+void cOrganism::RotateToFaceOrganism(cOrganism& org) {
+//	this->GetWorld()->GetPopulation().GetCell(this->GetCellID()).ConnectionList().Front().ConnectionList().Rotate(org);
 
-/* Check if the id of this neighbor indicates that it has previously donated
-to this organism.*/
-bool cOrganism::IsDonor(int neighbor_id)
-{
-	bool success = false;
-	if (donor_list.find(neighbor_id) != donor_list.end())
-		success = true;
-	return success;
-
 }

Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h	2008-10-08 20:23:14 UTC (rev 2821)
+++ branches/hjg-dev/source/main/cOrganism.h	2008-10-09 17:32:23 UTC (rev 2822)
@@ -29,7 +29,6 @@
 #include <iostream>
 #include <string>
 #include <vector>
-#include <set>
 
 #ifndef cCPUMemory_h
 #include "cCPUMemory.h"
@@ -447,28 +446,22 @@
 	// donate raw materials to others
 	bool SubtractSelfRawMaterials(int amount); 
 	// receive raw materials from others
-	bool AddOtherRawMaterials(int amount, int donor_id);
+	bool AddOtherRawMaterials(int amount);
 	// retrieve the organism's own amount of raw materials
 	int GetSelfRawMaterials() {InitReputation(); return m_self_raw_materials; }
 	// retrieve the amount of raw materials collected from others
 	int GetOtherRawMaterials() {InitReputation(); return m_other_raw_materials; }
-	// Has previously donated to this organism
-	bool IsDonor(int neighbor_id);
-	// Has checked reputation
-	void CheckedReputation() {InitReputation(); checkedReputation=true; }
-	bool HasCheckedReputation() { InitReputation(); return checkedReputation; }
+	// Rotate the organism to face a specific neighboring organism. 
+	// This functionality is used to turn the donation recipient to the donor.	
+	void RotateToFaceOrganism(cOrganism& org); 
 		
 protected:
 	// Initialize reputation support
-	inline void InitReputation() {if (!m_self_raw_materials) {m_self_raw_materials = 100; m_other_raw_materials =0; checkedReputation =false;}}
+	inline void InitReputation() {if (!m_self_raw_materials) {m_self_raw_materials = 100; m_other_raw_materials =0; }}
 	// The organism's own raw materials
 	int m_self_raw_materials; 
 	// The raw materials an oranism has collected from others
 	int m_other_raw_materials;
-	// a list of organism id's that have previously donated to this organism
-	set<int> donor_list;
-	// whether an organism has used the check reputation functionality
-	bool checkedReputation;
   
   // -------- End of reputation support --------
 

Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc	2008-10-08 20:23:14 UTC (rev 2821)
+++ branches/hjg-dev/source/main/cTaskLib.cc	2008-10-09 17:32:23 UTC (rev 2822)
@@ -420,8 +420,6 @@
   // reputation based tasks
   else if(name == "use_raw_mat")
     NewTask(name, "Use raw materials from self and other", &cTaskLib::Task_UseRawMaterials);
-  else if(name == "check_rep")
-    NewTask(name, "Check a neighbor's reputation", &cTaskLib::Task_CheckReputation);
 
   // event tasks
   if(name == "move_to_event")
@@ -3076,11 +3074,3 @@
 	}
 	return bonus;
 }
-
-
-/* This task rewards an organism for checking out the reputation of 
-another organism.*/
-double cTaskLib::Task_CheckReputation(cTaskContext& ctx) const {
-	return (double) ctx.GetOrganism()->HasCheckedReputation();
-}
-

Modified: branches/hjg-dev/source/main/cTaskLib.h
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.h	2008-10-08 20:23:14 UTC (rev 2821)
+++ branches/hjg-dev/source/main/cTaskLib.h	2008-10-09 17:32:23 UTC (rev 2822)
@@ -299,8 +299,6 @@
   
   // reputation
   double Task_UseRawMaterials(cTaskContext& ctx) const;
-  double Task_CheckReputation(cTaskContext& ctx) const;
-
 };
 
 




More information about the Avida-cvs mailing list