[Avida-SVN] r2416 - branches/movement/source/main
grabow38 at myxo.css.msu.edu
grabow38 at myxo.css.msu.edu
Mon Mar 3 08:26:48 PST 2008
Author: grabow38
Date: 2008-03-03 11:26:48 -0500 (Mon, 03 Mar 2008)
New Revision: 2416
Modified:
branches/movement/source/main/cPopulation.cc
Log:
Added movement logging configuration option.
Modified: branches/movement/source/main/cPopulation.cc
===================================================================
--- branches/movement/source/main/cPopulation.cc 2008-03-03 16:04:12 UTC (rev 2415)
+++ branches/movement/source/main/cPopulation.cc 2008-03-03 16:26:48 UTC (rev 2416)
@@ -812,8 +812,66 @@
return receive_value;
}
+// ***
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;
+
+ //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 {
+ schedule->Adjust(cell1.GetID(), cMerit(0));
+ }
+ //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 additions for movement logging
+ cell1.GetPosition(x1,y1);
+ cell2.GetPosition(x,y);
+ cid = org1->GetID();
+
+ // @LMG, config option for movement tracking
+ // Output some information
+ if( m_world->GetConfig().MOVT_TRACK_ON.Get() ) {
+ 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 << " " << endl;
+ movelog.close();
+ }
+ } else {
+ schedule->Adjust(cell2.GetID(), cMerit(0));
+ }
+ //cout << "SwapCells: Done." << endl;
+}
+
+// ***
+/*
+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;
@@ -841,6 +899,7 @@
}
//cout << "SwapCells: Done." << endl;
}
+*/
// CompeteDemes probabilistically copies demes into the next generation
// based on their fitness. How deme fitness is estimated is specified by
More information about the Avida-cvs
mailing list