[Avida-SVN] r3317 - in development/source: cpu main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Fri Jun 12 12:28:02 PDT 2009


Author: hjg
Date: 2009-06-12 15:28:02 -0400 (Fri, 12 Jun 2009)
New Revision: 3317

Modified:
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/main/cAvidaConfig.h
   development/source/main/cEnvironment.cc
   development/source/main/cEnvironment.h
   development/source/main/cPopulation.cc
   development/source/main/cStats.cc
   development/source/main/cTaskLib.cc
   development/source/main/cTaskLib.h
Log:
Modified group formation code to force organisms to pick actual group ids and to be born into a group.

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2009-06-12 13:32:19 UTC (rev 3316)
+++ development/source/cpu/cHardwareCPU.cc	2009-06-12 19:28:02 UTC (rev 3317)
@@ -8933,13 +8933,22 @@
 	int opinion;
 	// Check if the org is currently part of a group
 	assert(m_organism != 0);
+	
+	// check if this is a valid group
+	if (m_world->GetConfig().USE_FORM_GROUPS.Get() == 2) { 
+		int prop_group_id =   GetRegister(FindModifiedRegister(REG_BX));
+		if (!(m_world->GetEnvironment().IsGroupID(prop_group_id))){
+			return true;
+		}
+	}
+
+	
   if(m_organism->HasOpinion()) {
 		opinion = m_organism->GetOpinion().first;
 		// subtract org from group
 		m_world->GetPopulation().LeaveGroup(opinion);
   }
 	
-	
 	// Call the set opinion instruction, which does all the dirty work.
 	Inst_SetOpinion(ctx);
 	
@@ -8981,6 +8990,9 @@
 	return true;
 }
 
+
+
+
 /*! Create a link to the currently-faced cell.
  */
 bool cHardwareCPU::Inst_CreateLinkByFacing(cAvidaContext& ctx) {
@@ -9007,3 +9019,5 @@
 	m_organism->GetOrgInterface().CreateLinkByIndex(GetRegister(idxreg), GetRegister(wreg));
   return true;
 }
+
+

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2009-06-12 13:32:19 UTC (rev 3316)
+++ development/source/cpu/cHardwareCPU.h	2009-06-12 19:28:02 UTC (rev 3317)
@@ -29,6 +29,7 @@
 #include <iomanip>
 #include <vector>
 
+
 #ifndef cCodeLabel_h
 #include "cCodeLabel.h"
 #endif
@@ -176,6 +177,7 @@
   int m_epigenetic_saved_reg[NUM_REGISTERS];
   cCPUStack m_epigenetic_saved_stack;
   // Epigenetic State -->
+	
 
   bool SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst);
   
@@ -963,3 +965,5 @@
 }
 
 #endif
+
+

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2009-06-12 13:32:19 UTC (rev 3316)
+++ development/source/main/cAvidaConfig.h	2009-06-12 19:28:02 UTC (rev 3317)
@@ -644,7 +644,7 @@
   CONFIG_ADD_VAR(MATCH_ALREADY_PRODUCED, int, 0, "0=off\n1=on");
 	
 	CONFIG_ADD_GROUP(GROUP_FORMATION_GROUP, "Group Formation Settings");
-  CONFIG_ADD_VAR(USE_FORM_GROUPS, bool, 0, "Enable organisms to form groups. 0/1 (off/on)");
+  CONFIG_ADD_VAR(USE_FORM_GROUPS, int, 0, "Enable organisms to form groups. 0=off,\n 1=on no restrict,\n 2=on restrict to defined");
 	
 	// -------- Deme network config options --------
 	CONFIG_ADD_VAR(DEME_NETWORK_TYPE, int, 0, "0=topology, structure of network determines fitness.");

Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc	2009-06-12 13:32:19 UTC (rev 3316)
+++ development/source/main/cEnvironment.cc	2009-06-12 19:28:02 UTC (rev 3317)
@@ -1524,3 +1524,15 @@
   return true;
 }
 
+/* 
+ helper function that checks if this is a valid group id. The ids are specified 
+ in the environment file as tasks.
+ */
+bool cEnvironment::IsGroupID(int test_id) 
+{
+	bool val = false;
+	if (possible_group_ids.find(test_id) != possible_group_ids.end())
+		val = true;
+	return val;
+	
+}

Modified: development/source/main/cEnvironment.h
===================================================================
--- development/source/main/cEnvironment.h	2009-06-12 13:32:19 UTC (rev 3316)
+++ development/source/main/cEnvironment.h	2009-06-12 19:28:02 UTC (rev 3317)
@@ -61,7 +61,10 @@
 # endif
 #endif
 
+#include <set>
 
+
+
 class cAvidaContext;
 class cReaction;
 class cReactionRequisite;
@@ -187,6 +190,14 @@
   bool SetReactionTask(const cString& name, const cString& task);
   bool SetResourceInflow(const cString& name, double _inflow );
   bool SetResourceOutflow(const cString& name, double _outflow );
+	
+//--------------- used for spatial group formation
+public: 
+	void AddGroupID(int new_id) { possible_group_ids.insert(new_id); }
+	bool IsGroupID(int test_id);
+	
+protected:
+	std::set<int> possible_group_ids;
   
 };
 

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2009-06-12 13:32:19 UTC (rev 3316)
+++ development/source/main/cPopulation.cc	2009-06-12 19:28:02 UTC (rev 3317)
@@ -407,6 +407,17 @@
 			child_array[i]->SetReputation(parent_organism->GetReputation()); 
 		}
 		
+		
+		// If spatial groups are used, put the offspring in the 
+		// parents' group
+		if (m_world->GetConfig().USE_FORM_GROUPS.Get()){
+			assert(parent_organism->HasOpinion());
+			int group = parent_organism->GetOpinion().first;
+			child_array[i]->SetOpinion(group); 
+			JoinGroup(group);
+
+		}
+		
 	
 	}
 	

Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc	2009-06-12 13:32:19 UTC (rev 3316)
+++ development/source/main/cStats.cc	2009-06-12 19:28:02 UTC (rev 3317)
@@ -2551,7 +2551,7 @@
 {
 
 	cDataFile& df = m_world->GetDataFile(filename);
-	df.WriteComment("The number of groups, average, max, and min number of orgs in groups");
+	df.WriteComment("Information about the groups joined and used by the organisms");
 	
 	map<int,int> groups = m_world->GetPopulation().GetFormedGroups();
 	
@@ -2561,6 +2561,7 @@
 	double max_size = 0.0;
 	double min_size = 100000000000.0;
 	double active_groups = 0.0;
+	double groups_per_org = 0.0;
 	
 	for(itr = groups.begin();itr!=groups.end();itr++) {
 		double cur_size = itr->second;
@@ -2573,8 +2574,20 @@
 		}
 	}
 	
+	cOrganism* org; 
+	for(int i=0; i<m_world->GetPopulation().GetSize(); ++i) {
+    cPopulationCell& cell = m_world->GetPopulation().GetCell(i);
+		org = cell.GetOrganism();
+		
+    if(cell.IsOccupied()) {
+			org = cell.GetOrganism();
+			groups_per_org += org->HasOpinion();
+		}	
+	}
+	
 	avg_size = avg_size / groups.size();
 	avg_size_wout_empty = avg_size_wout_empty / active_groups;
+	groups_per_org = groups_per_org / m_world->GetPopulation().GetSize();
 	df.WriteTimeStamp();
 	df.Write(m_update,   "Update [update]");
 	df.Write((double)groups.size(), "number of groups [num]");
@@ -2583,6 +2596,7 @@
 	df.Write(max_size, "max size of groups [maxsize]");
 	df.Write(min_size, "min size of groups [minsize]");
 	df.Write(active_groups, "active groups [actgroup]");
+	df.Write(groups_per_org, "groups per org life [groupsperorg]");
 	
 	
 	df.Endl();

Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc	2009-06-12 13:32:19 UTC (rev 3316)
+++ development/source/main/cTaskLib.cc	2009-06-12 19:28:02 UTC (rev 3317)
@@ -37,6 +37,7 @@
 #include "cStateGrid.h"
 #include "tArrayUtils.h"
 #include "tHashTable.h"
+#include "cEnvironment.h"
 
 #include "platform.h"
 
@@ -3434,9 +3435,15 @@
   // Integer Arguments
   schema.AddEntry("group_size", 0, 1);
   schema.AddEntry("group_id", 1, 1);
+	
+
   
   cArgContainer* args = cArgContainer::Load(argstr, schema, errors);
   if (args) NewTask(name, "FormSpatialGroupWithID", &cTaskLib::Task_FormSpatialGroupWithID, 0, args);
+	
+	// Add this group id to the list in the instructions file. 
+	m_world->GetEnvironment().AddGroupID(args->GetInt(1));
+	
 }
 
 double cTaskLib::Task_FormSpatialGroupWithID(cTaskContext& ctx) const
@@ -3467,6 +3474,11 @@
 		}
 		
 	}
+	
+	if (reward < 0) 
+	{
+		int y = 0;
+	}
 
 	return reward;
 }

Modified: development/source/main/cTaskLib.h
===================================================================
--- development/source/main/cTaskLib.h	2009-06-12 13:32:19 UTC (rev 3316)
+++ development/source/main/cTaskLib.h	2009-06-12 19:28:02 UTC (rev 3317)
@@ -43,6 +43,7 @@
 #endif
 
 
+
 class cEnvReqs;
 class cString;
 class cWorld;




More information about the Avida-cvs mailing list