[Avida-SVN] r2106 - in branches/movement: . source/actions source/cpu source/main

grabow38 at myxo.css.msu.edu grabow38 at myxo.css.msu.edu
Tue Sep 25 06:35:54 PDT 2007


Author: grabow38
Date: 2007-09-25 09:35:53 -0400 (Tue, 25 Sep 2007)
New Revision: 2106

Modified:
   branches/movement/CMakeLists.txt
   branches/movement/source/actions/PrintActions.cc
   branches/movement/source/cpu/cHardwareCPU.cc
   branches/movement/source/cpu/cHardwareCPU.h
   branches/movement/source/main/cOrganism.cc
   branches/movement/source/main/cOrganism.h
   branches/movement/source/main/cPhenotype.cc
   branches/movement/source/main/cPhenotype.h
   branches/movement/source/main/cPopulation.cc
   branches/movement/source/main/cStats.cc
   branches/movement/source/main/cStats.h
Log:
Merged development changes r2099:2105 into branches/movement

Modified: branches/movement/CMakeLists.txt
===================================================================
--- branches/movement/CMakeLists.txt	2007-09-25 00:23:17 UTC (rev 2105)
+++ branches/movement/CMakeLists.txt	2007-09-25 13:35:53 UTC (rev 2106)
@@ -35,7 +35,7 @@
     SET(COMPILER_OPTIMIZATION_FLAGS "-ffast-math -fno-rtti -funroll-loops -fstrict-aliasing -OPT:Olimit=0")
   ELSE (CMAKE_CXX_COMPILER MATCHES ".*pathCC.*")
     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")
+    SET(COMPILER_OPTIMIZATION_FLAGS "-ffast-math -fno-rtti -funroll-loops -fstrict-aliasing -ftree-vectorize")
   ENDIF (CMAKE_CXX_COMPILER MATCHES ".*pathCC.*")
 
   INCLUDE(CheckCSourceCompiles)

Modified: branches/movement/source/actions/PrintActions.cc
===================================================================
--- branches/movement/source/actions/PrintActions.cc	2007-09-25 00:23:17 UTC (rev 2105)
+++ branches/movement/source/actions/PrintActions.cc	2007-09-25 13:35:53 UTC (rev 2106)
@@ -90,8 +90,8 @@
 STATS_OUT_FILE(PrintSenseData,              sense.dat           );
 STATS_OUT_FILE(PrintSenseExeData,           sense_exe.dat       );
 STATS_OUT_FILE(PrintSleepData,              sleep.dat          );
+STATS_OUT_FILE(PrintMovementData,           move.dat            );
 
-
 #define POP_OUT_FILE(METHOD, DEFAULT)                                                     /*  1 */ \
 class cAction ## METHOD : public cAction {                                                /*  2 */ \
 private:                                                                                  /*  3 */ \
@@ -2625,6 +2625,7 @@
   action_lib->Register<cActionPrintSenseData>("PrintSenseData");
   action_lib->Register<cActionPrintSenseExeData>("PrintSenseExeData");
   action_lib->Register<cActionPrintSleepData>("PrintSleepData");
+  action_lib->Register<cActionPrintMovementData>("PrintMovementData");
 
   // Population Out Files
   action_lib->Register<cActionPrintPhenotypeData>("PrintPhenotypeData");

Modified: branches/movement/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/movement/source/cpu/cHardwareCPU.cc	2007-09-25 00:23:17 UTC (rev 2105)
+++ branches/movement/source/cpu/cHardwareCPU.cc	2007-09-25 13:35:53 UTC (rev 2106)
@@ -206,6 +206,8 @@
     // Data collection
     tInstLibEntry<tMethod>("collect-cell-data", &cHardwareCPU::Inst_CollectCellData),
 
+    tInstLibEntry<tMethod>("sense-target", &cHardwareCPU::Inst_SenseTargetDist), // @LMG
+	
     tInstLibEntry<tMethod>("donate-rnd", &cHardwareCPU::Inst_DonateRandom),
     tInstLibEntry<tMethod>("donate-kin", &cHardwareCPU::Inst_DonateKin),
     tInstLibEntry<tMethod>("donate-edt", &cHardwareCPU::Inst_DonateEditDist),
@@ -307,34 +309,34 @@
     tInstLibEntry<tMethod>("h-divide0.001", &cHardwareCPU::Inst_HeadDivide0_001),
     
     // High-level instructions
-    tInstLibEntry<tMethod>("repro", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-sex", &cHardwareCPU::Inst_ReproSex),
-    tInstLibEntry<tMethod>("repro-A", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-B", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-C", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-D", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-E", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-F", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-G", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-H", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-I", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-J", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-K", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-L", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-M", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-N", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-O", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-P", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-Q", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-R", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-S", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-T", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-U", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-V", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-W", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-X", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-Y", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-Z", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-sex", &cHardwareCPU::Inst_ReproSex),
+   // tInstLibEntry<tMethod>("repro-A", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-B", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-C", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-D", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-E", &cHardwareCPU::Inst_Repro),
+  // tInstLibEntry<tMethod>("repro-F", &cHardwareCPU::Inst_Repro),
+  // tInstLibEntry<tMethod>("repro-G", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-H", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-I", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-J", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-K", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-L", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-M", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-N", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-O", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-P", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-Q", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-R", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-S", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-T", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-U", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-V", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-W", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-X", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-Y", &cHardwareCPU::Inst_Repro),
+   // tInstLibEntry<tMethod>("repro-Z", &cHardwareCPU::Inst_Repro),
 
     tInstLibEntry<tMethod>("put-repro", &cHardwareCPU::Inst_TaskPutRepro),
     tInstLibEntry<tMethod>("metabolize", &cHardwareCPU::Inst_TaskPutResetInputsRepro),        
@@ -3100,6 +3102,101 @@
   return true;
 }
 
+// Sense distance to target cell @LMG
+bool cHardwareCPU::Inst_SenseTargetDist(cAvidaContext& ctx)
+{
+  double r = 0;  // Reward factor, eventually will be configurable
+
+  // Get the size of the world, organism and target cell IDs, calculate (x, y)s
+  const int world_x = m_world->GetConfig().WORLD_X.Get();
+
+  int target_id = organism->GetTargetCellID();
+  // Check for a good target cell ID
+  if (target_id == -1) {
+    cout << "Target ID not initialized for this cell." << endl;
+    return true;
+  }
+
+  if (target_id < 0 || target_id > world_x * world_x ) {
+    cout << "Invalid target initialization for this cell." << endl;
+	return true;
+  }
+	
+  // Get the target and organism (x, y)
+  int target_x_coord = target_id % world_x;
+  int target_y_coord = target_id / world_x;
+
+  int org_id = organism->GetCellID();
+  if (org_id < 0) {
+   // cout << "Invalid cell id." << endl;
+	return true;
+  }
+  
+  int org_x_coord = org_id % world_x;
+  int org_y_coord = org_id / world_x;
+
+  //cout << endl << "Org. " << organism->GetID() << " Cell ID " << org_id << " Current (x, y): (" << org_x_coord << ", " << org_y_coord << ")" << endl;
+  //cout << "Target cell: " << target_id << " Target (x, y): (" << target_x_coord << ", " << target_y_coord << ')' << endl; 
+  // Calculate current squared distance
+  int cur_dist = (org_x_coord - target_x_coord) * (org_x_coord - target_x_coord) + 
+				 (org_y_coord - target_y_coord) * (org_y_coord - target_y_coord);
+
+  // Get initial, best, last distances
+  int init_dist = organism->GetPhenotype().GetInitDistance();
+  int best_dist = organism->GetPhenotype().GetBestDistance();
+  int last_dist = organism->GetPhenotype().GetLastDistance();
+
+  // Check for valid best distance value
+  if (best_dist > world_x * world_x * 2) { 
+   //cout << "Bad best distance for Org. " << organism->GetID() << " : " << best_dist 
+   //     << " > " << world_x * world_x * 2 << endl
+//		<< "Target ID: " << target_id << " Target (x, y): (" << target_x_coord << ", " << target_y_coord << ')' << endl;
+	return true;
+  }
+	
+// cout << "Current dist: " << cur_dist << " Last dist: " << last_dist << " Best dist: " << best_dist 
+// 	  << " Init dist: " << init_dist << endl;
+  
+  // Update phenotype info
+  int x_diff = abs(org_x_coord - target_x_coord);
+  int y_diff = abs(org_y_coord - target_y_coord);
+  organism->GetPhenotype().SetCurNumStepsTarget(x_diff, y_diff);
+   // cout << "X diff, Y diff: " << x_diff << "  " << y_diff << " Current steps from target: " << organism->GetPhenotype().GetCurNumStepsTarget() << endl;
+  
+  // Calculate best and current distance ratios
+  double best_ratio = 1 - (double)best_dist/(double)init_dist;
+  double current_ratio = 1 - (double)cur_dist/(double)init_dist;
+  //cout << "Best %: " << best_ratio << " Current %: " << current_ratio << endl;
+  //cout << "Last best ratio: " << organism->GetPhenotype().GetLastBestDistanceRatio() << endl;
+
+  if (cur_dist < best_dist) {
+    r = 10;
+    organism->GetPhenotype().SetBestDistance(cur_dist);
+	organism->GetPhenotype().SetCurBestDistanceRatio(current_ratio);
+	//cout << " New best dist: " << organism->GetPhenotype().GetBestDistance() << endl;
+	
+	// Get current bonus, calculate new bonus and update
+    double cur_bonus = organism->GetPhenotype().GetCurBonus();
+    //cout << "Old bonus: " << cur_bonus;
+  
+    cur_bonus *= exp2((current_ratio - best_ratio) * r);
+    organism->GetPhenotype().SetCurBonus(cur_bonus);
+    //cout << " New bonus: " << cur_bonus << endl;
+	//cout << " Reward = " << r << endl;
+  }
+  
+  // Put current and last distances into registers for future use
+  const int reg1_used = FindModifiedRegister(REG_CX);
+  GetRegister(reg1_used) = cur_dist;
+  const int reg2_used = FindModifiedRegister(REG_BX);
+  GetRegister(reg2_used) = last_dist;
+
+  // Set current distance as new value for last distance to target
+  organism->GetPhenotype().SetLastDistance(cur_dist);
+  
+  return true;
+}
+
 void cHardwareCPU::DoDonate(cOrganism* to_org)
 {
   assert(to_org != NULL);

Modified: branches/movement/source/cpu/cHardwareCPU.h
===================================================================
--- branches/movement/source/cpu/cHardwareCPU.h	2007-09-25 00:23:17 UTC (rev 2105)
+++ branches/movement/source/cpu/cHardwareCPU.h	2007-09-25 13:35:53 UTC (rev 2106)
@@ -442,6 +442,7 @@
   bool Inst_SenseMult100(cAvidaContext& ctx);
   bool DoSense(cAvidaContext& ctx, int conversion_method, double base);
   bool Inst_CollectCellData(cAvidaContext& ctx);
+  bool Inst_SenseTargetDist(cAvidaContext& ctx); // @LMG
 
   void DoDonate(cOrganism * to_org);
   void DoEnergyDonate(cOrganism* to_org);

Modified: branches/movement/source/main/cOrganism.cc
===================================================================
--- branches/movement/source/main/cOrganism.cc	2007-09-25 00:23:17 UTC (rev 2105)
+++ branches/movement/source/main/cOrganism.cc	2007-09-25 13:35:53 UTC (rev 2106)
@@ -272,6 +272,68 @@
   }
 }
 
+void cOrganism::SetTargetCell()
+{
+  // @LMG
+  const int threshold = 50; // Distance threshold for target cell, right now totally arbitrary 
+			      
+  // Check the world geometry, return if not a grid
+  int geometry = m_world->GetConfig().WORLD_GEOMETRY.Get();
+  if (geometry != nGeometry::GRID) { cout << "Not a grid, cannot make target cell" << endl; return; }
+  //SetOrgInterface(m_interface);
+
+  bool good = false; // Just a loop flag
+
+  // Get organism's cell ID, find the (x, y)
+  const int world_x = m_world->GetConfig().WORLD_X.Get();
+  const int world_y = m_world->GetConfig().WORLD_Y.Get();
+  int id = m_interface->GetCellID();
+  int x_coord = id % world_x;
+  int y_coord = id / world_x;
+  int size = world_x * world_y;
+  
+  while (good == false) {
+    // Pick a random target cell
+    target_cell_id = m_world->GetRandom().GetUInt(size);
+    // target_cell_id = 20;
+	
+    // Make sure target different from current cell
+    if (id == target_cell_id) continue;
+  
+    // Get the target (x, y)
+    int target_x_coord =  target_cell_id % world_x;
+    int target_y_coord =  target_cell_id / world_x;
+
+    // Calculate distance; use distance squared to keep value integer
+    int temp_dist = (x_coord - target_x_coord) * (x_coord - target_x_coord) + 
+	                (y_coord - target_y_coord) * (y_coord - target_y_coord);
+  
+    if (temp_dist > size * 2) { cout << "Distance bigger than world: " << temp_dist << endl; continue; }
+	
+	//m_phenotype.SetInitialDistance(temp_dist);
+	//m_phenotype.SetLastDistance(temp_dist);
+    //m_phenotype.SetBestDistance(temp_dist);
+	  
+    if (temp_dist > threshold) {
+	  good = true;
+	  
+	  m_phenotype.SetInitialDistance(temp_dist);
+	  m_phenotype.SetLastDistance(temp_dist);
+	  m_phenotype.SetBestDistance(temp_dist);
+	  
+	  // Find and set the number of steps to the target
+	  int x_diff = abs(x_coord - target_x_coord);
+	  int y_diff = abs(y_coord - target_y_coord);
+	  //int bigger = (x_diff >= y_diff) ? x_diff : y_diff;	  
+	  m_phenotype.SetCurNumStepsTarget(x_diff, y_diff);
+	}
+  }	
+  // cout << "Cell ID " << id << ", org. ID " << m_id <<" Target cell: " << target_cell_id << endl;
+  
+  // cout << "Org. ID " << m_id <<" Target cell: " << target_cell_id << endl;
+
+}
+
 void cOrganism::NetGet(cAvidaContext& ctx, int& value, int& seq)
 {
   assert(m_net);

Modified: branches/movement/source/main/cOrganism.h
===================================================================
--- branches/movement/source/main/cOrganism.h	2007-09-25 00:23:17 UTC (rev 2105)
+++ branches/movement/source/main/cOrganism.h	2007-09-25 13:35:53 UTC (rev 2106)
@@ -123,6 +123,9 @@
   bool m_is_sleeping;      // Is this organisms sleeping?
   bool m_is_dead;          // Is this organism dead?
   
+  // Target (destination) cell info @LMG
+  int target_cell_id;		// Cell ID of target cell
+  
   class cNetSupport
   {
   public:
@@ -234,11 +237,15 @@
   void ClearInput() { m_input_buf.Clear(); }
   void AddOutput(int val) { m_output_buf.Add(val); }
 
+
   // --------  Divide Methods  --------
   bool Divide_CheckViable();
   bool ActivateDivide(cAvidaContext& ctx);
   
-  
+  // --------  Target (destination) Cell Methods  @LMG --------
+  void SetTargetCell();  // Sets the target cell ID for this organism
+  int GetTargetCellID() { return target_cell_id; }   // Returns the target cell ID
+    
   // --------  Networking Support  --------
   void NetGet(cAvidaContext& ctx, int& value, int& seq);
   void NetSend(cAvidaContext& ctx, int value);

Modified: branches/movement/source/main/cPhenotype.cc
===================================================================
--- branches/movement/source/main/cPhenotype.cc	2007-09-25 00:23:17 UTC (rev 2105)
+++ branches/movement/source/main/cPhenotype.cc	2007-09-25 13:35:53 UTC (rev 2106)
@@ -59,6 +59,7 @@
   , last_reaction_add_reward(m_world->GetEnvironment().GetReactionLib().GetSize())  
   , last_inst_count(world->GetHardwareManager().GetInstSet().GetSize())
   , last_sense_count(m_world->GetStats().GetSenseSize())
+  , target_best_dist(100000)  // @LMG for movement tracking
 {
 }
 
@@ -113,8 +114,11 @@
   cur_inst_count           = in_phen.cur_inst_count;                 
   cur_sense_count          = in_phen.cur_sense_count;                 
   sensed_resources         = in_phen.sensed_resources;            
-  cur_task_time            = in_phen.cur_task_time;   
-  
+  cur_task_time            = in_phen.cur_task_time;
+  cur_best_dist_ratio	   = in_phen.cur_best_dist_ratio;  // @ LMG
+  cur_num_steps_target	   = in_phen.cur_num_steps_target;
+  cur_steps_away		   = in_phen. cur_steps_away;
+
   // Dynamically allocated m_task_states requires special handling
   tList<cTaskState*> hash_values;
   tList<void*>       hash_keys;
@@ -140,7 +144,10 @@
   last_reaction_add_reward = in_phen.last_reaction_add_reward; 
   last_inst_count          = in_phen.last_inst_count;	  
   last_sense_count         = in_phen.last_sense_count;   
-  last_fitness             = in_phen.last_fitness;            
+  last_fitness             = in_phen.last_fitness; 
+  last_best_dist_ratio	   = in_phen.last_best_dist_ratio; // @ LMG
+  last_num_steps_target	   = in_phen.last_num_steps_target;
+  last_steps_away		   = in_phen.last_steps_away;		  
   
   // 4. Records from this organisms life...
   num_divides              = in_phen.num_divides;      
@@ -150,8 +157,10 @@
   age                      = in_phen.age;               
   fault_desc               = in_phen.fault_desc;    
   neutral_metric           = in_phen.neutral_metric; 
-  life_fitness             = in_phen.life_fitness; 	
-                        
+  life_fitness             = in_phen.life_fitness;
+  target_best_dist		   = in_phen.target_best_dist; // @ LMG
+  target_last_dist		   = in_phen.target_last_dist;
+  target_init_dist		   = in_phen.target_init_dist; 	
   
   // 5. Status Flags...  (updated at each divide)
   to_die                  = in_phen.to_die;		 
@@ -298,6 +307,9 @@
   cur_trial_times_used.Resize(0); 
   trial_time_used = 0;
   trial_cpu_cycles_used = 0;
+  cur_best_dist_ratio	   = 0.0;  // @ LMG 09/19/07
+  cur_num_steps_target	   = 0;
+  cur_steps_away		   = 0;
   
   // Copy last values from parent
   last_merit_base           = parent_phenotype.last_merit_base;
@@ -313,6 +325,9 @@
   last_inst_count           = parent_phenotype.last_inst_count;
   last_sense_count          = parent_phenotype.last_sense_count;
   last_fitness              = CalcFitness(last_merit_base, last_bonus, gestation_time, last_cpu_cycles_used);
+  last_best_dist_ratio      = parent_phenotype.last_best_dist_ratio; // @ LMG for movement tracking
+  last_num_steps_target     = parent_phenotype.last_num_steps_target;
+  last_steps_away           = parent_phenotype.last_steps_away;
 
   // Setup other miscellaneous values...
   num_divides     = 0;
@@ -324,7 +339,7 @@
   fault_desc      = "";
   neutral_metric  = parent_phenotype.neutral_metric + m_world->GetRandom().GetRandNormal();
   life_fitness    = fitness; 
-
+  
   num_thresh_gb_donations = 0;
   num_thresh_gb_donations_last = parent_phenotype.num_thresh_gb_donations_last;
   num_quanta_thresh_gb_donations = 0;
@@ -433,6 +448,9 @@
   cur_trial_times_used.Resize(0); 
   trial_time_used = 0;
   trial_cpu_cycles_used = 0;
+  cur_best_dist_ratio = 0.0; // @ LMG
+  cur_num_steps_target	   = 0;
+  cur_steps_away		   = 0;
   
   // Copy last values from parent
   last_merit_base = genome_length;
@@ -447,7 +465,10 @@
   last_reaction_add_reward.SetAll(0);
   last_inst_count.SetAll(0);
   last_sense_count.SetAll(0);
-
+  last_best_dist_ratio = 0.0;  // Added for movement tracking @ LMG
+  last_num_steps_target = 0;
+  last_steps_away = 100000;
+  
   // Setup other miscellaneous values...
   num_divides     = 0;
   generation      = 0;
@@ -462,6 +483,8 @@
   num_thresh_gb_donations_last = 0;
   num_quanta_thresh_gb_donations = 0;
   num_quanta_thresh_gb_donations_last = 0;
+  
+  target_best_dist = 100000; // Added for movement tracking @LMG
 
   // Setup flags...
   is_injected   = true;
@@ -567,7 +590,10 @@
   last_reaction_add_reward  = cur_reaction_add_reward;
   last_inst_count           = cur_inst_count;
   last_sense_count          = cur_sense_count;
-
+  last_best_dist_ratio      = cur_best_dist_ratio; // @LMG for movement tracking
+  last_num_steps_target     = cur_num_steps_target;
+  last_steps_away           = cur_steps_away;
+  
   // Reset cur values.
   cur_bonus       = m_world->GetConfig().DEFAULT_BONUS.Get();
   cpu_cycles_used = 0;
@@ -583,6 +609,9 @@
   cur_inst_count.SetAll(0);
   cur_sense_count.SetAll(0);
   cur_task_time.SetAll(0.0);
+  cur_best_dist_ratio = 0.0;  // @LMG for movement tracking
+  cur_num_steps_target = 0; 
+  cur_steps_away = 0;
 
   // Setup other miscellaneous values...
   num_divides++;
@@ -1659,3 +1688,9 @@
   
   return false;
 }
+
+void cPhenotype::SetCurNumStepsTarget(int deltax, int deltay) // @ LMG
+{
+  assert(initialized == true);
+  cur_num_steps_target = (deltax >= deltay) ? deltax : deltay;
+}

Modified: branches/movement/source/main/cPhenotype.h
===================================================================
--- branches/movement/source/main/cPhenotype.h	2007-09-25 00:23:17 UTC (rev 2105)
+++ branches/movement/source/main/cPhenotype.h	2007-09-25 13:35:53 UTC (rev 2106)
@@ -127,6 +127,9 @@
   tArray<int> cur_trial_times_used;        // Time used in of various trials.; @JEB
   int trial_time_used;                        // like time_used, but reset every trial; @JEB
   int trial_cpu_cycles_used;                  // like cpu_cycles_used, but reset every trial; @JEB
+  double cur_best_dist_ratio;  // Best proportion of distance to target traveled @ LMG
+  int cur_num_steps_target;    // Current distance from target in steps @LMG
+  int cur_steps_away;		   // Current number of steps away from target @LMG
   
   // 3. These mark the status of "in progess" variables at the last divide.
   double last_merit_base;         // Either constant or based on genome length.
@@ -142,6 +145,9 @@
   tArray<int> last_inst_count;	  // Instruction exection counter
   tArray<int> last_sense_count;   // Total times resource combinations have been sensed; @JEB 
   double last_fitness;            // Used to determine sterilization.
+  double last_best_dist_ratio; // Best proportion of distance to target traveled as of last update @LMG
+  int last_num_steps_target;   // Last distance from target in steps @LMG
+  int last_steps_away;		   // Last steps away from target @LMG
   int last_cpu_cycles_used;
 
   // 4. Records from this organisms life...
@@ -154,7 +160,10 @@
   double neutral_metric; // Undergoes drift (gausian 0,1) per generation
   double life_fitness; 	 // Organism fitness during its lifetime, 
 		         // calculated based on merit just before the divide
-
+  int target_best_dist;  // Closest approach to target cell so far @LMG
+  int target_last_dist;  // Distance to target at last sense @LMG
+  int target_init_dist;  // Initial distance to target cell @LMG
+  
   // 5. Status Flags...  (updated at each divide)
   bool to_die;		 // Has organism has triggered something fatal?
   bool to_delete;        // Should this organism be deleted when finished?
@@ -382,8 +391,18 @@
   int CrossNum() const  { assert(initialized == true); return cross_num; }
   bool ChildFertile() const { assert(initialized == true); return child_fertile;}
   int GetChildCopiedSize() const { assert(initialized == true); return child_copied_size; }
+  
+  // @LMG, target distance accessors
+  int GetInitDistance() { assert(initialized == true); return target_init_dist; }
+  int GetLastDistance() { assert(initialized == true); return target_last_dist; }
+  int GetBestDistance() { assert(initialized == true); return target_best_dist; }
+  double GetCurBestDistanceRatio() { assert(initialized == true); return cur_best_dist_ratio; }
+  double GetLastBestDistanceRatio() { assert(initialized == true); return last_best_dist_ratio; }
+  int GetCurNumStepsTarget() { assert(initialized == true); return cur_num_steps_target; }
+  int GetLastNumStepsTarget() { assert(initialized == true); return last_num_steps_target; } 
+  int GetCurStepsAway() { assert(initialized == true); return cur_steps_away; }
+  int GetLastStepsAway() { assert(initialized == true); return last_steps_away; }
 
-
   ////////////////////  Accessors -- Modifying  ///////////////////
   void SetMerit(const cMerit& in_merit) { merit = in_merit; }
   void SetFitness(const double in_fit) { fitness = in_fit; }
@@ -457,6 +476,18 @@
   void ApplyToEnergyStore();
   double ExtractParentEnergy();
   
+  // @ LMG, modifiers for distances to target cell
+  void SetBestDistance(int in_target_dist) { assert(initialized == true); target_best_dist = in_target_dist; }
+  void SetLastDistance(int in_target_dist) { assert(initialized == true); target_last_dist = in_target_dist; }
+  void SetInitialDistance(int in_target_dist) { assert(initialized == true); target_init_dist = in_target_dist; }
+  void SetCurBestDistanceRatio(double in_cur_best) { assert(initialized == true); cur_best_dist_ratio = in_cur_best; }
+  void SetLastBestDistanceRatio(double in_last_best) { assert(initialized == true); last_best_dist_ratio = in_last_best; }
+  void SetCurNumStepsTarget(int deltax, int deltay);
+  void SetLastNumStepsTarget(int num_steps) { assert(initialized == true); last_num_steps_target = num_steps; }
+  void SetLastStepsAway(int num_steps) { assert(initialized == true); last_steps_away = num_steps; }
+  void SetCurStepsAway(int num_steps) { assert(initialized == true); cur_steps_away = num_steps; }
+
+  
   bool operator<(const cPhenotype& rhs) const;
   bool operator>(const cPhenotype& rhs) const;
   bool operator==(const cPhenotype& rhs) const;

Modified: branches/movement/source/main/cPopulation.cc
===================================================================
--- branches/movement/source/main/cPopulation.cc	2007-09-25 00:23:17 UTC (rev 2105)
+++ branches/movement/source/main/cPopulation.cc	2007-09-25 13:35:53 UTC (rev 2106)
@@ -322,6 +322,9 @@
   
   // If we're not about to kill the parent, do some extra work on it.
   if (parent_alive == true) {
+  
+    // Reset parent target cell @LMG 
+	parent_organism.SetTargetCell();
     
     // Reset inputs and re-calculate merit if required
     if (m_world->GetConfig().RESET_INPUTS_ON_DIVIDE.Get() > 0){
@@ -339,6 +342,7 @@
         parent_phenotype.SetFitness(parent_phenotype.GetMerit().CalcFitness(parent_phenotype.GetGestationTime())); //Update fitness
         delete test_cpu;
       }
+	  
     }
     schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit());
     
@@ -513,6 +517,9 @@
     } 
     in_organism->GetPhenotype().SetCurBonusInstCount(num_rewarded_instructions);
   }
+  
+  // @LMG for moving to target 
+  in_organism->SetTargetCell();
 }
 
 // @WRE 2007/07/05 Helper function to take care of side effects of Avidian 
@@ -2095,6 +2102,9 @@
   stats.SumCopySize().Clear();
   stats.SumExeSize().Clear();
   stats.SumMemSize().Clear();
+  stats.SumBestDistance().Clear();   // @LMG
+  stats.SumNumStepsTarget().Clear();
+  stats.SumStepsAway().Clear();
   
   stats.ZeroTasks();
   stats.ZeroRewards();
@@ -2112,6 +2122,13 @@
   int num_threads = 0;
   int num_modified = 0;
   
+  stats.SetNumHalfwayToTarget(0);	// @LMG counts for movement stats
+  stats.SetNumStepsLessthan10(0);
+  stats.SetNumStepsLessthan5(0);
+  stats.SetNumLessthanHalfway(0);
+  stats.SetNumLessthan10Percent(0);
+  stats.SetNumNoMovement(0);
+  
   // Maximums...
   cMerit max_merit(0);
   double max_fitness = 0;
@@ -2156,6 +2173,18 @@
     stats.SumExeSize().Add(phenotype.GetExecutedSize());
     stats.SetGenoMapElement(i, organism->GetGenotype()->GetID());
     
+	stats.SumBestDistance().Add(organism->GetPhenotype().GetLastBestDistanceRatio()); // @LMG
+	stats.SumNumStepsTarget().Add(organism->GetPhenotype().GetLastNumStepsTarget());
+	stats.SumStepsAway().Add(organism->GetPhenotype().GetLastStepsAway());
+	
+	if (organism->GetPhenotype().GetLastBestDistanceRatio() >= 0.5) stats.IncNumHalfwayToTarget(); // @LMG
+	else stats.IncNumLessthanHalfway();
+	
+	if (organism->GetPhenotype().GetLastBestDistanceRatio() < 0.1 ) stats.IncNumLessthan10Percent();
+	if (organism->GetPhenotype().GetLastBestDistanceRatio() == 0.0 ) stats.IncNumNoMovement();
+	if (organism->GetPhenotype().GetLastNumStepsTarget() <= 10) stats.IncNumStepsLessthan10();
+	if (organism->GetPhenotype().GetLastNumStepsTarget() <= 5) stats.IncNumStepsLessthan5();
+	
 #if INSTRUCTION_COUNT
     for (int j = 0; j < m_world->GetNumInstructions(); j++) {
       stats.SumExeInst()[j].Add(organism->GetPhenotype().GetLastInstCount()[j]);

Modified: branches/movement/source/main/cStats.cc
===================================================================
--- branches/movement/source/main/cStats.cc	2007-09-25 00:23:17 UTC (rev 2105)
+++ branches/movement/source/main/cStats.cc	2007-09-25 13:35:53 UTC (rev 2106)
@@ -473,6 +473,7 @@
   sense_last_count.SetAll(0);
   sense_last_exe_count.SetAll(0);
 
+  
   reaction_add_reward.SetAll(0);
 
   dom_merit = 0;
@@ -482,6 +483,16 @@
 
   num_resamplings = 0;
   num_failedResamplings = 0;
+  
+  //sum_best_distance.Clear();	// @LMG, movement stats
+  sum_num_steps_target.Clear();
+  sum_steps_away.Clear();
+  num_halfway_to_target = 0;
+  num_steps_lessthan_10 = 0;
+  num_steps_lessthan_5 = 0;
+  num_lessthan_halfway = 0;
+  num_lessthan_10_percent = 0;
+  num_no_movement = 0;
 
 }
 
@@ -1029,7 +1040,25 @@
   df.Endl();
 }
 
+void cStats::PrintMovementData(const cString& filename) // @ LMG
+ {
+ cDataFile& df = m_world->GetDataFile(filename);
+   
+ df.WriteComment("Avida movement information\n");
+ df.WriteTimeStamp();
+ df.Write(m_update, "Update");
+ df.Write(sum_best_distance.Average(), "Average best distance to target");
+ df.Write(sum_num_steps_target.Average(), "Average num. of steps to target");
+ //df.Write(sum_steps_away.Average(), "Average num. of steps moved away from target");
+ df.Write(num_no_movement, "Num. organisms at 0% distance to target");
+ df.Write(num_lessthan_10_percent, "Num. organisms < 10% distance to target");
+  df.Write(num_halfway_to_target, "Num. organisms >= 50% distance to target");
+ df.Write(num_steps_lessthan_10, "Num. organisms <= 10 steps from target");
+ df.Write(num_steps_lessthan_5, "Num. organisms <= 5 steps from target");
+ df.Endl();
+ }
 
+
 /*! This method is called whenever an organism successfully sends a message.  Success,
 in this case, means that the message has been delivered to the receive buffer of
 the organism that this message was sent to. */

Modified: branches/movement/source/main/cStats.h
===================================================================
--- branches/movement/source/main/cStats.h	2007-09-25 00:23:17 UTC (rev 2105)
+++ branches/movement/source/main/cStats.h	2007-09-25 13:35:53 UTC (rev 2106)
@@ -252,6 +252,17 @@
   tArray<int> sense_last_exe_count;
   tArray<cString> sense_names;
 
+  // Stats for movement @LMG
+  cDoubleSum sum_best_distance;
+  cDoubleSum sum_num_steps_target;
+  cDoubleSum sum_steps_away;
+  int num_halfway_to_target;
+  int num_steps_lessthan_10;
+  int num_steps_lessthan_5;
+  int num_lessthan_halfway;
+  int num_lessthan_10_percent;
+  int num_no_movement;
+  
   tArray<int> numAsleep;
 
   cStats(); // @not_implemented
@@ -383,6 +394,10 @@
   cDoubleSum& SumExeSize()       { return sum_exe_size; }
   cDoubleSum& SumMemSize()       { return sum_mem_size; }
 
+  cDoubleSum& SumBestDistance()  { return sum_best_distance; } // @LMG
+  cDoubleSum& SumNumStepsTarget()  { return sum_num_steps_target; } // @LMG
+  cDoubleSum& SumStepsAway()     { return sum_steps_away; } // @LMG
+  
 #if INSTRUCTION_COUNT
   void ZeroInst();
 #endif
@@ -463,6 +478,19 @@
   void IncLastSenseExeCount(int res_comb_index, int count) 
     { sense_last_exe_count[res_comb_index]+= count; }
     
+  void SetNumHalfwayToTarget(int in_val) { num_halfway_to_target = in_val; }  //@LMG
+  void SetNumStepsLessthan10(int in_val) { num_steps_lessthan_10 = in_val; }
+  void SetNumStepsLessthan5(int in_val) { num_steps_lessthan_5 = in_val; }
+  void SetNumLessthanHalfway(int in_val) { num_lessthan_halfway = in_val; }
+  void SetNumLessthan10Percent(int in_val) { num_lessthan_10_percent = in_val; }
+  void SetNumNoMovement(int in_val) { num_no_movement = in_val; }
+  void IncNumHalfwayToTarget() { num_halfway_to_target++; }
+  void IncNumStepsLessthan10() { num_steps_lessthan_10++; }
+  void IncNumStepsLessthan5() { num_steps_lessthan_5++; }
+  void IncNumLessthanHalfway() { num_lessthan_halfway++; }
+  void IncNumLessthan10Percent() { num_lessthan_10_percent++;}
+  void IncNumNoMovement() { num_no_movement++; }
+  
   void SetReactions(const tArray<double> &_in) { reaction_count = _in; }
   void AddLastReactionAddReward(int _id, double _reward) { reaction_add_reward[_id] += _reward; }
   void ZeroRewards();
@@ -614,6 +642,9 @@
   void PrintMarketData(const cString& filename);
   void PrintSenseData(const cString& filename);
   void PrintSenseExeData(const cString& filename);
+  
+  void PrintMovementData(const cString& filename); // @ LMG
+
   void PrintSleepData(const cString& filename);
   
   // -------- Messaging support --------




More information about the Avida-cvs mailing list