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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Sat Dec 20 14:37:42 PST 2008


Author: hjg
Date: 2008-12-20 17:37:42 -0500 (Sat, 20 Dec 2008)
New Revision: 3067

Modified:
   branches/hjg-dev/source/cpu/cHardwareCPU.cc
   branches/hjg-dev/source/cpu/cHardwareCPU.h
   branches/hjg-dev/source/cpu/cTestCPUInterface.h
   branches/hjg-dev/source/main/cOrgInterface.h
   branches/hjg-dev/source/main/cPopulationInterface.cc
   branches/hjg-dev/source/main/cPopulationInterface.h
   branches/hjg-dev/source/main/cTaskLib.cc
   branches/hjg-dev/source/main/cTaskLib.h
Log:
Added a task that just rewards for being a member of a specific lineage. Also, added a rotate-to-reputation-lineage instruction.

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-12-20 04:05:52 UTC (rev 3066)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc	2008-12-20 22:37:42 UTC (rev 3067)
@@ -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-rep-lineage", &cHardwareCPU::Inst_RotateToGreatestReputationWithDifferentLineage, nInstFlag::STALL),
 		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),
@@ -7234,7 +7235,15 @@
 	return true;	
 }
 
+/* Rotate to face the organism with the highest reputation that has
+ a different lineage. */
+bool cHardwareCPU::Inst_RotateToGreatestReputationWithDifferentLineage(cAvidaContext& ctx)
+{
+	organism->GetOrgInterface().RotateToGreatestReputationWithDifferentLineage(organism->GetLineageLabel());
+	return true;	
+}
 
+
 /* Rotate to face the organism with the highest reputation and then
 	immediately donate */
 bool cHardwareCPU::Inst_RotateToGreatestReputationAndDonate(cAvidaContext& ctx) 

Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-12-20 04:05:52 UTC (rev 3066)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h	2008-12-20 22:37:42 UTC (rev 3067)
@@ -705,6 +705,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 the organims with the greatest reputation that has a different tag
+	bool Inst_RotateToGreatestReputationWithDifferentLineage(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

Modified: branches/hjg-dev/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/hjg-dev/source/cpu/cTestCPUInterface.h	2008-12-20 04:05:52 UTC (rev 3066)
+++ branches/hjg-dev/source/cpu/cTestCPUInterface.h	2008-12-20 22:37:42 UTC (rev 3067)
@@ -95,6 +95,7 @@
 	
 	void RotateToGreatestReputation(){ }
 	void RotateToGreatestReputationWithDifferentTag(int tag){ }
+	void RotateToGreatestReputationWithDifferentLineage(int tag){ }	
 	void RotateToReputationK(int k){ }
 };
 

Modified: branches/hjg-dev/source/main/cOrgInterface.h
===================================================================
--- branches/hjg-dev/source/main/cOrgInterface.h	2008-12-20 04:05:52 UTC (rev 3066)
+++ branches/hjg-dev/source/main/cOrgInterface.h	2008-12-20 22:37:42 UTC (rev 3067)
@@ -106,6 +106,7 @@
   
 	virtual void RotateToGreatestReputation() =0;
 	virtual void RotateToGreatestReputationWithDifferentTag(int tag) =0;
+	virtual void RotateToGreatestReputationWithDifferentLineage(int line) =0;
 	virtual void RotateToReputationK(int k) =0;
 	
 };

Modified: branches/hjg-dev/source/main/cPopulationInterface.cc
===================================================================
--- branches/hjg-dev/source/main/cPopulationInterface.cc	2008-12-20 04:05:52 UTC (rev 3066)
+++ branches/hjg-dev/source/main/cPopulationInterface.cc	2008-12-20 22:37:42 UTC (rev 3067)
@@ -471,6 +471,66 @@
 	
 }
 
+/* Rotate an organism to face the neighbor with the highest reputation 
+ where the neighbor has a different tag than the organism*/
+void cPopulationInterface::RotateToGreatestReputationWithDifferentLineage(int line) 
+{
+	
+	cPopulationCell& cell = m_world->GetPopulation().GetCell(GetCellID());
+	int high_rep=-1; 
+	vector <int> high_rep_orgs;
+	
+	// loop to find the max reputation
+	for(int i=0; i<cell.ConnectionList().GetSize(); ++i) {
+		const cPopulationCell* faced_cell = cell.ConnectionList().GetFirst();
+		// cell->organism, if occupied, check reputation, etc.
+		if (IsNeighborCellOccupied()) {
+			cOrganism* cur_neighbor = faced_cell->GetOrganism();
+			
+			// if it has high reputation	
+			if ((cur_neighbor->GetLineageLabel() != line) && (cur_neighbor->GetReputation() >= high_rep)) {
+				if (cur_neighbor->GetReputation() > high_rep) {
+					high_rep = cur_neighbor->GetReputation();
+					high_rep_orgs.clear();
+				}
+				high_rep_orgs.push_back(cur_neighbor->GetID()); 
+			} 
+		}
+		
+		// check the next neighbor
+		cell.ConnectionList().CircNext();
+	}
+	
+	// Pick an organism to donate to
+	
+	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();
+			
+			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();
+			
+		}
+		
+		
+		
+	}
+	
+}
 
 
 /* Rotate an organism to face a neighbor with a reputation of >= k*/

Modified: branches/hjg-dev/source/main/cPopulationInterface.h
===================================================================
--- branches/hjg-dev/source/main/cPopulationInterface.h	2008-12-20 04:05:52 UTC (rev 3066)
+++ branches/hjg-dev/source/main/cPopulationInterface.h	2008-12-20 22:37:42 UTC (rev 3067)
@@ -110,6 +110,7 @@
 	// Reputation
 	void RotateToGreatestReputation();
 	void RotateToGreatestReputationWithDifferentTag(int tag);
+	void RotateToGreatestReputationWithDifferentLineage(int line);	
 	void RotateToReputationK(int k);
   
   void DivideOrgTestamentAmongDeme(double value);

Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc	2008-12-20 04:05:52 UTC (rev 3066)
+++ branches/hjg-dev/source/main/cTaskLib.cc	2008-12-20 22:37:42 UTC (rev 3067)
@@ -435,6 +435,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 == "lineage")
+    Load_LineageReward(name, info, envreqs, errors);
 
 
   // event tasks
@@ -3368,4 +3370,22 @@
 }
 
 
+/* Reward an organism for having a specific lineage */
+void cTaskLib::Load_LineageReward(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors)
+{
+  cArgSchema schema;
+  schema.AddEntry("lineage",0, -1);
+  cArgContainer* args = cArgContainer::Load(argstr, schema, errors);	
+  if (args) NewTask(name, "LineageReward", &cTaskLib::Task_LineageReward, 0, args);
+}
 
+double cTaskLib::Task_LineageReward(cTaskContext& ctx) const
+{
+	double bonus = 0.0;
+  int lineage = ctx.GetTaskEntry()->GetArguments().GetInt(0);
+	if (ctx.GetOrganism()->GetLineageLabel() == lineage) { 
+		bonus = 1.0;
+	}
+	return bonus;
+}
+

Modified: branches/hjg-dev/source/main/cTaskLib.h
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.h	2008-12-20 04:05:52 UTC (rev 3066)
+++ branches/hjg-dev/source/main/cTaskLib.h	2008-12-20 22:37:42 UTC (rev 3067)
@@ -318,6 +318,8 @@
 	double Task_GoodReputation(cTaskContext& ctx) const;
   double Task_ConsumeRawMaterials(cTaskContext& ctx) const;	
   double Task_UseManyOrgsRawMaterials(cTaskContext& ctx) const;
+	void Load_LineageReward(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors);
+  double Task_LineageReward(cTaskContext& ctx) const;	
 
 };
 




More information about the Avida-cvs mailing list