[Avida-SVN] r2786 - branches/movement/source/main

welsberr at myxo.css.msu.edu welsberr at myxo.css.msu.edu
Sun Sep 14 17:34:43 PDT 2008


Author: welsberr
Date: 2008-09-14 20:34:42 -0400 (Sun, 14 Sep 2008)
New Revision: 2786

Modified:
   branches/movement/source/main/cPopulation.cc
   branches/movement/source/main/cPopulationCell.h
Log:
Add cell visit setting and incrementing.

Modified: branches/movement/source/main/cPopulation.cc
===================================================================
--- branches/movement/source/main/cPopulation.cc	2008-09-15 00:09:41 UTC (rev 2785)
+++ branches/movement/source/main/cPopulation.cc	2008-09-15 00:34:42 UTC (rev 2786)
@@ -144,6 +144,8 @@
   // Setup the cells.  Do things that are not dependent upon topology here.
   for(int i=0; i<num_cells; ++i) {
     cell_array[i].Setup(world, i, environment.GetMutRates(), i%world_x, i/world_x);
+	// @WRE: Initialize visits. 14-Sep-2008
+	cell_array[i].SetVisits(0);
     // Setup the reaper queue.
     if (world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST) {
       reaper_queue.Push(&(cell_array[i]));
@@ -889,35 +891,37 @@
 
 void cPopulation::SwapCells(cPopulationCell & cell1, cPopulationCell & cell2)
 {
-    // Sanity checks: Don't process if the cells are the same and 
-    // don't bother trying to move when given a cell that isn't there
-    //cout << "SwapCells: testing if cell1 and cell2 are non-null" << endl;
-    //if (!(NULL != cell1) || !(NULL != cell2)) return;
-    if ((&cell1 == NULL) || (&cell2 == NULL)) return;
-    //cout << "SwapCells: testing if cell1 and cell2 are different" << endl;  
-    if (cell1.GetID() == cell2.GetID()) return;
-    // Clear current contents of cells
-    //cout << "SwapCells: clearing cell contents" << endl;
-    cOrganism * org1 = cell1.RemoveOrganism();
-    cOrganism * org2 = cell2.RemoveOrganism();
-    // @WRE additions for movement logging
-    int x = 0;
-    int y = 0;
-    int x1 = 0;
-    int y1 = 0;
-    int cid = 0;
+  // Sanity checks: Don't process if the cells are the same and 
+  // don't bother trying to move when given a cell that isn't there
+  //cout << "SwapCells: testing if cell1 and cell2 are non-null" << endl;
+  //if (!(NULL != cell1) || !(NULL != cell2)) return;
+  if ((&cell1 == NULL) || (&cell2 == NULL)) return;
+  //cout << "SwapCells: testing if cell1 and cell2 are different" << endl;  
+  if (cell1.GetID() == cell2.GetID()) return;
+  // Clear current contents of cells
+  //cout << "SwapCells: clearing cell contents" << endl;
+  cOrganism * org1 = cell1.RemoveOrganism();
+  cOrganism * org2 = cell2.RemoveOrganism();
+  // @WRE additions for movement logging
+  int x = 0;
+  int y = 0;
+  int x1 = 0;
+  int y1 = 0;
+  int cid = 0;
 
-    //cout << "SwapCells: organism 2 is non-null, fix up source cell" << endl;
-    if (org2 != NULL) {
+  //cout << "SwapCells: organism 2 is non-null, fix up source cell" << endl;
+  if (org2 != NULL) {
 	cell1.InsertOrganism(org2);
 	schedule->Adjust(cell1.GetID(), org2->GetPhenotype().GetMerit());
-    } else {
+  } else {
 	schedule->Adjust(cell1.GetID(), cMerit(0));
-    }
-    //cout << "SwapCells: organism 1 is non-null, fix up dest cell" << endl;
-    if (org1 != NULL) {
+  }
+  //cout << "SwapCells: organism 1 is non-null, fix up dest cell" << endl;
+  if (org1 != NULL) {
 	cell2.InsertOrganism(org1);
 	schedule->Adjust(cell2.GetID(), org1->GetPhenotype().GetMerit());
+    // @WRE: Visit bookkeeping
+	cell2.IncVisits();
 	// @WRE additions for movement logging
 	cell1.GetPosition(x1,y1);
 	cell2.GetPosition(x,y);
@@ -926,26 +930,26 @@
 	// @LMG, config option for movement tracking, using movement logging above
 	// Output some information
 	if( m_world->GetConfig().MOVT_TRACK_ON.Get() ) {
-		const int world_x = m_world->GetConfig().WORLD_X.Get();
-		int target_cell_id = org1->GetTargetCellID();
-		int target_x = target_cell_id % world_x;
-		int target_y = target_cell_id / world_x;
+	  const int world_x = m_world->GetConfig().WORLD_X.Get();
+	  int target_cell_id = org1->GetTargetCellID();
+	  int target_x = target_cell_id % world_x;
+	  int target_y = target_cell_id / world_x;
 		
-	    ofstream movelog;
-	    movelog.open("data/movelog.txt",ios::app);
-	    // By columns: org ID, from cell xy, to cell xy
-	    movelog << cid << " " <<
-		x1 << " " <<
+	  ofstream movelog;
+	  movelog.open("data/movelog.txt",ios::app);
+	  // By columns: org ID, from cell xy, to cell xy
+	  movelog << cid << " " <<
+	    x1 << " " <<
 		y1 << " " <<
 		x << " " <<
 		y << " " <<
 		target_x << " " <<
 		target_y << " " << endl;
 	    movelog.close();
-		}
-    } else {
+	}
+  } else {
 	schedule->Adjust(cell2.GetID(), cMerit(0));
-    }
+  }
     //cout << "SwapCells: Done." << endl;
 }
 

Modified: branches/movement/source/main/cPopulationCell.h
===================================================================
--- branches/movement/source/main/cPopulationCell.h	2008-09-15 00:09:41 UTC (rev 2785)
+++ branches/movement/source/main/cPopulationCell.h	2008-09-15 00:34:42 UTC (rev 2786)
@@ -100,6 +100,8 @@
   inline void GetPosition(int& x, int& y) { x = m_x; y = m_y; } // Retrieves the position (x,y) coordinates of this cell.
   inline int GetVisits() { return m_visits; } // @WRE: Retrieves the number of visits for this cell.
   inline void IncVisits() { m_visits++; } // @WRE: Increments the visit count for a cell
+  inline void SetVisits(int visitcnt) { m_visits = visitcnt; } // @WRE: Sets the number of visits for this cell.
+
   inline const cMutationRates& MutationRates() const { assert(m_mut_rates); return *m_mut_rates; }
   inline cMutationRates& MutationRates() { assert(m_mut_rates); return *m_mut_rates; }
   




More information about the Avida-cvs mailing list