[Avida-SVN] r2152 - in branches/collect: Avida.xcodeproj source/actions source/cpu source/main tests/energy_deme_level_res

blwalker at myxo.css.msu.edu blwalker at myxo.css.msu.edu
Tue Oct 23 20:34:18 PDT 2007


Author: blwalker
Date: 2007-10-23 23:34:18 -0400 (Tue, 23 Oct 2007)
New Revision: 2152

Added:
   branches/collect/source/main/cDemeCellEvent.cc
   branches/collect/source/main/cDemeCellEvent.h
Removed:
   branches/collect/tests/energy_deme_level_res/expected/
Modified:
   branches/collect/Avida.xcodeproj/project.pbxproj
   branches/collect/source/actions/EnvironmentActions.cc
   branches/collect/source/actions/PopulationActions.cc
   branches/collect/source/actions/PrintActions.cc
   branches/collect/source/cpu/cHardwareBase.cc
   branches/collect/source/cpu/cHardwareCPU.cc
   branches/collect/source/cpu/cHardwareCPU.h
   branches/collect/source/main/cAvidaConfig.h
   branches/collect/source/main/cDeme.cc
   branches/collect/source/main/cDeme.h
   branches/collect/source/main/cOrganism.cc
   branches/collect/source/main/cPhenotype.cc
   branches/collect/source/main/cPhenotype.h
   branches/collect/source/main/cPopulation.cc
   branches/collect/source/main/cPopulationCell.cc
   branches/collect/source/main/cPopulationCell.h
Log:

Porting development 2053:2070 to the collect branch.

Note: This will not build properly, as r2070 contains a problem with CMakeLists.txt (subsequently fixed in r2073).


Modified: branches/collect/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/collect/Avida.xcodeproj/project.pbxproj	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/Avida.xcodeproj/project.pbxproj	2007-10-24 03:34:18 UTC (rev 2152)
@@ -195,6 +195,7 @@
 		70F9FC100C469DD70083B788 /* cASTDumpVisitor.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70F9FC0F0C469DC10083B788 /* cASTDumpVisitor.cc */; };
 		B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */; };
 		B4FA25A90C5EB7880086D4B5 /* cPhenPlastGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */; };
+		B516AF840C91E2D400023D53 /* cDemeCellEvent.cc in Sources */ = {isa = PBXBuildFile; fileRef = B516AF790C91E24600023D53 /* cDemeCellEvent.cc */; };
 		DCD8AC1F0C8A7C30004CBE6F /* cAnalyzeGenotypeTreeStats.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCA4BEC10C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.cc */; };
 /* End PBXBuildFile section */
 
@@ -211,6 +212,23 @@
 		};
 /* End PBXBuildRule section */
 
+/* Begin PBXBuildStyle section */
+		B516AF180C91DC7700023D53 /* Development */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = NO;
+			};
+			name = Development;
+		};
+		B516AF190C91DC7700023D53 /* Deployment */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+			};
+			name = Deployment;
+		};
+/* End PBXBuildStyle section */
+
 /* Begin PBXContainerItemProxy section */
 		56F555DA0C3B36FC00E2E929 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
@@ -818,6 +836,8 @@
 		B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPlasticPhenotype.cc; sourceTree = "<group>"; };
 		B4FA25820C5EB6510086D4B5 /* cPlasticPhenotype.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cPlasticPhenotype.h; sourceTree = "<group>"; };
 		B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPhenPlastGenotype.cc; sourceTree = "<group>"; };
+		B516AF790C91E24600023D53 /* cDemeCellEvent.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = cDemeCellEvent.cc; path = source/main/cDemeCellEvent.cc; sourceTree = SOURCE_ROOT; };
+		B516AF7A0C91E24600023D53 /* cDemeCellEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = cDemeCellEvent.h; path = source/main/cDemeCellEvent.h; sourceTree = SOURCE_ROOT; };
 		DCA4BEC10C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cAnalyzeGenotypeTreeStats.cc; sourceTree = "<group>"; };
 		DCA4BEC20C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeGenotypeTreeStats.h; sourceTree = "<group>"; };
 		DCC30FCF0762539D008F7A48 /* Doxyfile */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = Doxyfile; sourceTree = "<group>"; };
@@ -1336,6 +1356,8 @@
 				70C1EFA308C39F2100F50912 /* cHardwareBase.cc */,
 				70C1EF9E08C39F0E00F50912 /* cHardwareBase.h */,
 				70C1EFA508C39F2100F50912 /* cHardwareCPU.cc */,
+				B516AF790C91E24600023D53 /* cDemeCellEvent.cc */,
+				B516AF7A0C91E24600023D53 /* cDemeCellEvent.h */,
 				70C1EFA008C39F0E00F50912 /* cHardwareCPU.h */,
 				423335880BC067E3000DF681 /* cHardwareGX.cc */,
 				423335890BC067E3000DF681 /* cHardwareGX.h */,
@@ -1774,6 +1796,12 @@
 		DCC30C4D0762532C008F7A48 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
+			buildSettings = {
+			};
+			buildStyles = (
+				B516AF180C91DC7700023D53 /* Development */,
+				B516AF190C91DC7700023D53 /* Deployment */,
+			);
 			hasScannedForEncodings = 0;
 			mainGroup = DCC30C490762532C008F7A48;
 			productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;
@@ -1957,6 +1985,7 @@
 				70436B6C0C36C98900A05ABA /* PlatformExpert.cc in Sources */,
 				B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */,
 				B4FA25A90C5EB7880086D4B5 /* cPhenPlastGenotype.cc in Sources */,
+				B516AF840C91E2D400023D53 /* cDemeCellEvent.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: branches/collect/source/actions/EnvironmentActions.cc
===================================================================
--- branches/collect/source/actions/EnvironmentActions.cc	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/actions/EnvironmentActions.cc	2007-10-24 03:34:18 UTC (rev 2152)
@@ -455,8 +455,40 @@
   }
 };
 
+class cActionDelayedDemeEvent : public cAction
+{
+private:
+  int m_x1, m_y1, m_x2, m_y2; // bounding box of event in deme
+  int m_delay; // deme age when event occurs
+  int m_duration; // length of event; subverted when deme is reset
+  
+public:
+  cActionDelayedDemeEvent(cWorld* world, const cString& args) : cAction(world, args), m_x1(-1), m_y1(-1), m_x2(-1), m_y2(-1), m_delay(-1), m_duration(-1)
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_x1 = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_y1 = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_x2 = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_y2 = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_delay = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_duration = largs.PopWord().AsInt();
+  }
+  
+  static const cString GetDescription() { return "Arguments: <int x1> <int y1> <int x2> <int y2> <int delay> <int duraion>"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    cPopulation& pop = m_world->GetPopulation();
+    int numDemes = pop.GetNumDemes();
+    for(int i = 0; i < numDemes; i++) {
+      pop.GetDeme(i).SetCellEvent(m_x1, m_y1, m_x2, m_y2, m_delay, m_duration);
+    }
+  }
+};
+
 void RegisterEnvironmentActions(cActionLibrary* action_lib)
 {
+  action_lib->Register<cActionDelayedDemeEvent>("DelayedDemeEvent");
   action_lib->Register<cActionInjectResource>("InjectResource");
   action_lib->Register<cActionInjectScaledResource>("InjectScaledResource");
   action_lib->Register<cActionOutflowScaledResource>("OutflowScaledResource");

Modified: branches/collect/source/actions/PopulationActions.cc
===================================================================
--- branches/collect/source/actions/PopulationActions.cc	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/actions/PopulationActions.cc	2007-10-24 03:34:18 UTC (rev 2152)
@@ -988,6 +988,7 @@
     'all'       - ...all non-empty demes in the population.
     'full_deme' - ...demes that have been filled up.
     'corners'   - ...demes with upper left and lower right corners filled.
+    'deme-age'  - ...demes that are a certain age
 */
 
 class cActionReplicateDemes : public cAction

Modified: branches/collect/source/actions/PrintActions.cc
===================================================================
--- branches/collect/source/actions/PrintActions.cc	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/actions/PrintActions.cc	2007-10-24 03:34:18 UTC (rev 2152)
@@ -2126,7 +2126,96 @@
   }
 };
 
+class cActionDumpEnergyGrid : public cAction
+{
+private:
+  cString m_filename;
+  
+public:
+  cActionDumpEnergyGrid(cWorld* world, const cString& args) : cAction(world, args), m_filename("")
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_filename = largs.PopWord();  
+  }
+  static const cString GetDescription() { return "Arguments: [string fname='']"; }
+  void Process(cAvidaContext& ctx)
+  {
+    cString filename(m_filename);
+    if (filename == "") filename.Set("grid_energy.%d.dat", m_world->GetStats().GetUpdate());
+    ofstream& fp = m_world->GetDataFileOFStream(filename);
+    
+    for (int i = 0; i < m_world->GetPopulation().GetWorldY(); i++) {
+      for (int j = 0; j < m_world->GetPopulation().GetWorldX(); j++) {
+        cPopulationCell& cell = m_world->GetPopulation().GetCell(i * m_world->GetPopulation().GetWorldX() + j);
+        double cell_energy = (cell.IsOccupied()) ? cell.GetOrganism()->GetPhenotype().GetStoredEnergy() : 0.0;
+        fp << cell_energy << " ";
+      }
+      fp << endl;
+    }
+    m_world->GetDataFileManager().Remove(filename);
+  }
+};
 
+class cActionDumpExecutionRatioGrid : public cAction
+{
+private:
+  cString m_filename;
+  
+public:
+  cActionDumpExecutionRatioGrid(cWorld* world, const cString& args) : cAction(world, args), m_filename("")
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_filename = largs.PopWord();  
+  }
+  static const cString GetDescription() { return "Arguments: [string fname='']"; }
+  void Process(cAvidaContext& ctx)
+  {
+    cString filename(m_filename);
+    if (filename == "") filename.Set("grid_exe_ratio.%d.dat", m_world->GetStats().GetUpdate());
+    ofstream& fp = m_world->GetDataFileOFStream(filename);
+    
+    for (int i = 0; i < m_world->GetPopulation().GetWorldY(); i++) {
+      for (int j = 0; j < m_world->GetPopulation().GetWorldX(); j++) {
+        cPopulationCell& cell = m_world->GetPopulation().GetCell(i * m_world->GetPopulation().GetWorldX() + j);
+        double cell_executionRatio = (cell.IsOccupied()) ? cell.GetOrganism()->GetPhenotype().GetEnergyUsageRatio() : 1.0;
+        fp << cell_executionRatio << " ";
+      }
+      fp << endl;
+    }
+    m_world->GetDataFileManager().Remove(filename);
+  }
+};
+
+class cActionDumpCellDataGrid : public cAction
+{
+private:
+  cString m_filename;
+  
+public:
+  cActionDumpCellDataGrid(cWorld* world, const cString& args) : cAction(world, args), m_filename("")
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_filename = largs.PopWord();  
+  }
+  static const cString GetDescription() { return "Arguments: [string fname='']"; }
+  void Process(cAvidaContext& ctx)
+  {
+    cString filename(m_filename);
+    if (filename == "") filename.Set("grid_cell_data.%d.dat", m_world->GetStats().GetUpdate());
+    ofstream& fp = m_world->GetDataFileOFStream(filename);
+    
+    for (int i = 0; i < m_world->GetPopulation().GetWorldY(); i++) {
+      for (int j = 0; j < m_world->GetPopulation().GetWorldX(); j++) {
+        cPopulationCell& cell = m_world->GetPopulation().GetCell(i * m_world->GetPopulation().GetWorldX() + j);
+        double cell_data = cell.GetCellData();
+        fp << cell_data << " ";
+      }
+      fp << endl;
+    }
+    m_world->GetDataFileManager().Remove(filename);
+  }
+};
+
 class cActionDumpFitnessGrid : public cAction
 {
 private:
@@ -2250,6 +2339,35 @@
   }
 };
 
+class cActionDumpSleepGrid : public cAction
+{
+private:
+  cString m_filename;
+  
+public:
+  cActionDumpSleepGrid(cWorld* world, const cString& args) : cAction(world, args), m_filename("")
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_filename = largs.PopWord();  
+  }
+  static const cString GetDescription() { return "Arguments: [string fname='']"; }
+  void Process(cAvidaContext& ctx)
+  {
+    cString filename(m_filename);
+    if (filename == "") filename.Set("grid_sleep.%d.dat", m_world->GetStats().GetUpdate());
+    ofstream& fp = m_world->GetDataFileOFStream(filename);
+    
+    for (int i = 0; i < m_world->GetPopulation().GetWorldY(); i++) {
+      for (int j = 0; j < m_world->GetPopulation().GetWorldX(); j++) {
+        cPopulationCell& cell = m_world->GetPopulation().GetCell(i * m_world->GetPopulation().GetWorldX() + j);
+        double cell_energy = (cell.IsOccupied()) ? cell.GetOrganism()->IsSleeping() : 0.0;
+        fp << cell_energy << " ";
+      }
+      fp << endl;
+    }
+    m_world->GetDataFileManager().Remove(filename);
+  }
+};
 
 class cActionDumpTaskGrid : public cAction
 {
@@ -2567,6 +2685,10 @@
   action_lib->Register<cActionDumpTaskGrid>("DumpTaskGrid");
   action_lib->Register<cActionDumpDonorGrid>("DumpDonorGrid");
   action_lib->Register<cActionDumpReceiverGrid>("DumpReceiverGrid");
+  action_lib->Register<cActionDumpEnergyGrid>("DumpEnergyGrid");
+  action_lib->Register<cActionDumpExecutionRatioGrid>("DumpExecutionRatioGrid");
+  action_lib->Register<cActionDumpCellDataGrid>("DumpCellDataGrid");
+  action_lib->Register<cActionDumpSleepGrid>("DumpSleepGrid");
   
   // Print Settings
   action_lib->Register<cActionSetVerbose>("SetVerbose");

Modified: branches/collect/source/cpu/cHardwareBase.cc
===================================================================
--- branches/collect/source/cpu/cHardwareBase.cc	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/cpu/cHardwareBase.cc	2007-10-24 03:34:18 UTC (rev 2152)
@@ -817,8 +817,11 @@
 }
 
 bool cHardwareBase::Inst_DoubleEnergyUsage(cAvidaContext& ctx) {
-  organism->GetPhenotype().DoubleEnergyUsage();
-  return true;
+  double energy_req = inst_energy_cost[IP().GetNextInst().GetOp()]
+                        * cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy() * organism->GetPhenotype().GetEnergyUsageRatio() * 2.0, m_world)
+                        / 100.0; //compensate by factor of 100
+
+  return organism->GetPhenotype().DoubleEnergyUsage(energy_req);
 }
 
 bool cHardwareBase::Inst_HalfEnergyUsage(cAvidaContext& ctx) {
@@ -826,7 +829,6 @@
   return true;
 }
 
-
 // This method will test to see if all costs have been paid associated
 // with executing an instruction and only return true when that instruction
 // should proceed.
@@ -840,6 +842,7 @@
     double energy_req = inst_energy_cost[cur_inst.GetOp()] * (organism->GetPhenotype().GetMerit().GetDouble() / 100.0); //compensate by factor of 100
 
     if (energy_req > 0.0) { 
+      int cellID = organism->GetCellID();
       if (organism->GetPhenotype().GetStoredEnergy() >= energy_req) {
         inst_energy_cost[cur_inst.GetOp()] = 0;
         // subtract energy used from current org energy.
@@ -847,7 +850,6 @@
         
         // tracking sleeping organisms
         cString instName = m_world->GetHardwareManager().GetInstSet().GetName(cur_inst);
-        int cellID = organism->GetCellID();
         if( instName == cString("sleep") || instName == cString("sleep1") || instName == cString("sleep2") ||
             instName == cString("sleep3") || instName == cString("sleep4")) {
           cPopulation& pop = m_world->GetPopulation();
@@ -857,7 +859,8 @@
           pop.GetCell(cellID).GetOrganism()->SetSleeping(true);
           m_world->GetStats().incNumAsleep(pop.GetCell(cellID).GetDemeID());
         }
-      } else { // not enough energy
+      } else {
+        organism->GetPhenotype().SetToDie();
         return false;
       }
     }

Modified: branches/collect/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.cc	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/cpu/cHardwareCPU.cc	2007-10-24 03:34:18 UTC (rev 2152)
@@ -50,6 +50,7 @@
 
 #include <climits>
 #include <fstream>
+#include <cmath>
 
 using namespace std;
 
@@ -203,7 +204,9 @@
     tInstLibEntry<tMethod>("sense", &cHardwareCPU::Inst_SenseLog2),           // If you add more sense instructions
     tInstLibEntry<tMethod>("sense-unit", &cHardwareCPU::Inst_SenseUnit),      // and want to keep stats, also add
     tInstLibEntry<tMethod>("sense-m100", &cHardwareCPU::Inst_SenseMult100),   // the names to cStats::cStats() @JEB
-    
+    // Data collection
+    tInstLibEntry<tMethod>("collect-cell-data", &cHardwareCPU::Inst_CollectCellData),
+
     tInstLibEntry<tMethod>("collect", &cHardwareCPU::Inst_Collect),
     
     tInstLibEntry<tMethod>("donate-rnd", &cHardwareCPU::Inst_DonateRandom),
@@ -223,11 +226,12 @@
     tInstLibEntry<tMethod>("rotate-r", &cHardwareCPU::Inst_RotateR),
     tInstLibEntry<tMethod>("rotate-left-one", &cHardwareCPU::Inst_RotateLeftOne),
     tInstLibEntry<tMethod>("rotate-right-one", &cHardwareCPU::Inst_RotateRightOne),
-
     tInstLibEntry<tMethod>("rotate-label", &cHardwareCPU::Inst_RotateLabel),
     
     tInstLibEntry<tMethod>("set-cmut", &cHardwareCPU::Inst_SetCopyMut),
     tInstLibEntry<tMethod>("mod-cmut", &cHardwareCPU::Inst_ModCopyMut),
+    tInstLibEntry<tMethod>("get-cell-xy", &cHardwareCPU::Inst_GetCellPosition),
+    tInstLibEntry<tMethod>("dist-from-diag", &cHardwareCPU::Inst_GetDistanceFromDiagonal),
     // @WRE additions for movement
     tInstLibEntry<tMethod>("tumble", &cHardwareCPU::Inst_Tumble),
     tInstLibEntry<tMethod>("move", &cHardwareCPU::Inst_Move),
@@ -358,6 +362,8 @@
     // Promoter Model
     tInstLibEntry<tMethod>("promoter", &cHardwareCPU::Inst_Promoter),
     tInstLibEntry<tMethod>("terminate", &cHardwareCPU::Inst_Terminate),
+    tInstLibEntry<tMethod>("promoter", &cHardwareCPU::Inst_Promoter),
+    tInstLibEntry<tMethod>("terminate", &cHardwareCPU::Inst_Terminate),
     tInstLibEntry<tMethod>("regulate", &cHardwareCPU::Inst_Regulate),
     tInstLibEntry<tMethod>("numberate", &cHardwareCPU::Inst_Numberate),
     
@@ -368,7 +374,7 @@
     // Messaging
     tInstLibEntry<tMethod>("send-msg", &cHardwareCPU::Inst_SendMessage),
     tInstLibEntry<tMethod>("retrieve-msg", &cHardwareCPU::Inst_RetrieveMessage),
-    
+        
     // Placebo instructions
     tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip),
 
@@ -3217,6 +3223,13 @@
   return true;
 }
 
+bool cHardwareCPU::Inst_CollectCellData(cAvidaContext& ctx) {
+  int cellID = organism->GetCellID();
+  const int out_reg = FindModifiedRegister(REG_BX);
+  GetRegister(out_reg) = m_world->GetPopulation().GetCell(cellID).GetCellData();
+  return true;
+}
+
 void cHardwareCPU::DoDonate(cOrganism* to_org)
 {
   assert(to_org != NULL);
@@ -3248,12 +3261,12 @@
   
   //update energy store and merit of donor
   organism->GetPhenotype().ReduceEnergy(energy_given);
-  double senderMerit = cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy(), m_world) * organism->GetPhenotype().GetExecutionRatio();
+  double senderMerit = cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy()  * organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
   organism->UpdateMerit(senderMerit);
   
   // update energy store and merit of donee
   to_org->GetPhenotype().ReduceEnergy(-1.0*energy_given);
-  double receiverMerit = cMerit::EnergyToMerit(to_org->GetPhenotype().GetStoredEnergy(), m_world) * to_org->GetPhenotype().GetExecutionRatio();
+  double receiverMerit = cMerit::EnergyToMerit(to_org->GetPhenotype().GetStoredEnergy() * to_org->GetPhenotype().GetEnergyUsageRatio(), m_world);
   to_org->UpdateMerit(receiverMerit);
 }
 
@@ -4353,17 +4366,17 @@
 
 bool cHardwareCPU::Inst_Sleep(cAvidaContext& ctx) {
   cPopulation& pop = m_world->GetPopulation();
+  int cellID = organism->GetCellID();
   if(m_world->GetConfig().LOG_SLEEP_TIMES.Get() == 1) {
-    pop.AddEndSleep(organism->GetCellID(), m_world->GetStats().GetUpdate());
+    pop.AddEndSleep(cellID, m_world->GetStats().GetUpdate());
   }
-  int cellID = organism->GetCellID();
   organism->SetSleeping(false);  //this instruction get executed at the end of a sleep cycle
   m_world->GetStats().decNumAsleep(pop.GetCell(cellID).GetDemeID());
   if(m_world->GetConfig().APPLY_ENERGY_METHOD.Get() == 2) {
     organism->GetPhenotype().RefreshEnergy();
     organism->GetPhenotype().ApplyToEnergyStore();
-    double newMerit = cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy(), m_world) * organism->GetPhenotype().GetExecutionRatio();
-    pop.UpdateMerit(organism->GetCellID(), newMerit);
+    double newMerit = cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy() * organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
+    pop.UpdateMerit(cellID, newMerit);
   }
   return true;
 }
@@ -4374,13 +4387,40 @@
   return true;
 }
 
+bool cHardwareCPU::Inst_GetCellPosition(cAvidaContext& ctx) {
+  int absolute_cell_ID = organism->GetCellID();
+  int deme_id = organism->GetOrgInterface().GetDemeID();
+  std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);  
+  const int xreg = FindModifiedRegister(REG_BX);
+  const int yreg = FindNextRegister(xreg);
+  GetRegister(xreg) = pos.first;
+  GetRegister(yreg) = pos.second;
+  return true;
+}
 
+bool cHardwareCPU::Inst_GetDistanceFromDiagonal(cAvidaContext& ctx) {
+  int absolute_cell_ID = organism->GetOrgInterface().GetCellID();
+  int deme_id = organism->GetOrgInterface().GetDemeID();
+  std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);  
+  const int reg = FindModifiedRegister(REG_BX);
+  
+  if(pos.first > pos.second) {
+    GetRegister(reg) = (int)ceil((pos.first - pos.second)/2.0);
+  } else {
+    GetRegister(reg) = (int)floor((pos.first - pos.second)/2.0);
+  }
+//  std::cerr<<"x = "<<pos.first<<"  y = "<<pos.second<<"  ans = "<<GetRegister(reg)<<std::endl;
+  return true;
+}
+
 //// Promoter Model ////
 
 bool cHardwareCPU::Inst_Promoter(cAvidaContext& ctx)
 {
   // Promoters don't do anything themselves
   return true;
+//  std::cerr<<"x = "<<pos.first<<"  y = "<<pos.second<<"  ans = "<<GetRegister(reg)<<std::endl;
+  return true;
 }
 
 // Move the instruction ptr to the next active promoter
@@ -4564,7 +4604,6 @@
   return code;
 }
 
-
 /*! Send a message to the organism that is currently faced by this cell,
 where the label field of sent message is from register ?BX?, and the data field
 is from register ~?BX?.

Modified: branches/collect/source/cpu/cHardwareCPU.h
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.h	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/cpu/cHardwareCPU.h	2007-10-24 03:34:18 UTC (rev 2152)
@@ -441,9 +441,9 @@
   bool Inst_SenseUnit(cAvidaContext& ctx);
   bool Inst_SenseMult100(cAvidaContext& ctx);
   bool DoSense(cAvidaContext& ctx, int conversion_method, double base);
-  
   bool FindModifiedResource(int& start_index, int& end_index);
   bool Inst_Collect(cAvidaContext& ctx);
+  bool Inst_CollectCellData(cAvidaContext& ctx);
 
   void DoDonate(cOrganism * to_org);
   void DoEnergyDonate(cOrganism* to_org);
@@ -473,6 +473,8 @@
   bool Inst_RotateLabel(cAvidaContext& ctx);
   bool Inst_SetCopyMut(cAvidaContext& ctx);
   bool Inst_ModCopyMut(cAvidaContext& ctx);
+  bool Inst_GetCellPosition(cAvidaContext& ctx);
+  bool Inst_GetDistanceFromDiagonal(cAvidaContext& ctx);
   // @WRE additions for movement
   bool Inst_Tumble(cAvidaContext& ctx);
   bool Inst_Move(cAvidaContext& ctx);

Modified: branches/collect/source/main/cAvidaConfig.h
===================================================================
--- branches/collect/source/main/cAvidaConfig.h	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/main/cAvidaConfig.h	2007-10-24 03:34:18 UTC (rev 2152)
@@ -299,7 +299,7 @@
   CONFIG_ADD_VAR(DEMES_HAVE_MERIT, int, 0, "Whether demes have merit; 0=no");
   CONFIG_ADD_VAR(GERMLINE_COPY_MUT, double, 0.0075, "Prob. of copy mutations occuring during\ngermline replication.");
   CONFIG_ADD_VAR(GERMLINE_REPLACES_SOURCE, int, 0, "Whether the source germline is updated\non replication; 0=no.");
-  CONFIG_ADD_VAR(GERMLINE_RANDOM_PLACEMENT, int, 0, "Whether the seed for a germline is placed\n randomly within the deme; 0=no.");
+  CONFIG_ADD_VAR(GERMLINE_RANDOM_PLACEMENT, int, 0, "Defines how the seed for a germline is placed\n within the deme;\n0 = organisms is placed in center of deme, no orientation\n1 = organisms is placed in center of deme and oriented\n2 = organism is randomly placed in deme, no orientation");
   CONFIG_ADD_VAR(MAX_DEME_AGE, int, 500, "The maximum age of a deme (in updates) to be\nused for age-based replication (default=500).");  
   
   CONFIG_ADD_GROUP(REPRODUCTION_GROUP, "Birth and Death");

Modified: branches/collect/source/main/cDeme.cc
===================================================================
--- branches/collect/source/main/cDeme.cc	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/main/cDeme.cc	2007-10-24 03:34:18 UTC (rev 2152)
@@ -22,15 +22,17 @@
  */
 
 #include "cDeme.h"
+#include "cPopulation.h"
 #include "cPopulationCell.h"
 #include "cResource.h"
+#include "cWorld.h"
 
-
-void cDeme::Setup(const tArray<int> & in_cells, int in_width)
+void cDeme::Setup(const tArray<int> & in_cells, int in_width, cWorld* world)
 {
   cell_ids = in_cells;
   birth_count = 0;
   org_count = 0;
+  m_world = world;
 
   // If width is negative, set it to the full number of cells.
   width = in_width;
@@ -60,11 +62,36 @@
   return std::make_pair(cellid % GetWidth(), cellid / GetWidth());
 }
 
+void cDeme::ProcessUpdate() {
+  for(int i = 0; i < cell_events.GetSize(); i++) {
+    cDemeCellEvent& event = cell_events[i];
+    if(event.GetDelay() == _age) {
+      event.ActivateEvent(m_world); //start event
+      int eventCell = event.GetNextEventCellID();
+      while(eventCell != -1) {
+        // place event ID in cells' data
+        m_world->GetPopulation().GetCell(GetCellID(eventCell)).SetCellData(event.GetEventID());
+        eventCell = event.GetNextEventCellID();
+      }
+    } else if(event.GetDelay()+event.GetDuration() == _age) {
+      int eventCell = event.GetNextEventCellID();
+      while(eventCell != -1) {
+        if(event.GetEventID() == m_world->GetPopulation().GetCell(GetCellID(eventCell)).GetCellData()) { // eventID == CellData
+          //set cell data to 0
+          m_world->GetPopulation().GetCell(GetCellID(eventCell)).SetCellData(0);
+          eventCell = event.GetNextEventCellID();
+        }
+      }
+      event.DeactivateEvent();  //event over
+    }
+  }
+  ++_age;
+}
 
 void cDeme::Reset() 
 {
   birth_count = 0; 
-  _age = 0;
+  _age = 0;  
   //clear cell energy
   
   deme_resource_count.ReinitializeResources();
@@ -141,3 +168,8 @@
   }
   deme_resource_count.ModifyCell(cell_resources, relative_cell_id);
 }
+
+void cDeme::SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration) {
+  cDemeCellEvent demeEvent = cDemeCellEvent(x1, y1, x2, y2, delay, duration, width);
+  cell_events.Push(demeEvent);
+}

Modified: branches/collect/source/main/cDeme.h
===================================================================
--- branches/collect/source/main/cDeme.h	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/main/cDeme.h	2007-10-24 03:34:18 UTC (rev 2152)
@@ -24,12 +24,14 @@
 #ifndef cDeme_h
 #define cDeme_h
 
+#include "cDemeCellEvent.h"
 #include "cGermline.h"
 #include "tArray.h"
 #include "cResourceCount.h"
 #include "cStringList.h"
 
 class cResource;
+class cWorld;
 
 /*! Demes are groups of cells in the population that are somehow bound together
 as a unit.  The deme object is used from within cPopulation to manage these 
@@ -38,6 +40,7 @@
 class cDeme
 {
 private:
+  cWorld* m_world;
   tArray<int> cell_ids;
   int width; //!< Width of this deme.
   int birth_count; //!< Number of organisms that have been born into this deme since reset.
@@ -51,11 +54,13 @@
   cResourceCount deme_resource_count; //!< Resources available to the deme
   tArray<int> energy_res_ids; //!< IDs of energy resources
   
+  tArray<cDemeCellEvent> cell_events;
+  
 public:
   cDeme() : width(0), birth_count(0), org_count(0), _age(0), deme_resource_count(0) { ; }
   ~cDeme() { ; }
 
-  void Setup(const tArray<int>& in_cells, int in_width = -1);
+  void Setup(const tArray<int>& in_cells, int in_width = -1, cWorld* world = NULL);
 
   int GetSize() const { return cell_ids.GetSize(); }
   int GetCellID(int pos) const { return cell_ids[pos]; }
@@ -85,7 +90,7 @@
   
   // -= Update support =-
   //! Called once, at the end of every update.
-  void ProcessUpdate() { ++_age; }
+  void ProcessUpdate();
   /*! Returns the age of this deme, updates.  Age is defined as the number of 
     updates since the last time Reset() was called. */
   int GetAge() const { return _age; }
@@ -100,6 +105,8 @@
   void UpdateDemeRes() { deme_resource_count.GetResources(); }
   void Update(double time_step) { deme_resource_count.Update(time_step); }
   int GetRelativeCellID(int absolute_cell_id) { return absolute_cell_id % GetSize(); } //!< assumes all demes are the same size
+
+  void SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration);
 };
 
 #endif

Copied: branches/collect/source/main/cDemeCellEvent.cc (from rev 2070, development/source/main/cDemeCellEvent.cc)
===================================================================
--- branches/collect/source/main/cDemeCellEvent.cc	                        (rev 0)
+++ branches/collect/source/main/cDemeCellEvent.cc	2007-10-24 03:34:18 UTC (rev 2152)
@@ -0,0 +1,41 @@
+#include "cDemeCellEvent.h"
+#include "cWorld.h"
+
+cDemeCellEvent::cDemeCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, int width) : 
+  m_delay(delay)
+  , m_duration(duration)
+  , m_iter(0)
+  , m_active(false)
+{
+  assert(x1 <= x2);
+  assert(y1 <= y2);
+  assert(y1 < width && y2 < width);
+  assert(delay >= 0);
+  assert(duration >= 0);
+  m_event_cells.ResizeClear((x2-x1+1) * (y2-y1+1));
+  
+  int i = 0;
+  for(int j = y1; j <= y2; j++) {
+    for(int k = x1; k <= x2; k++) {
+      m_event_cells[i] = j*width+k;
+      i++;
+    }
+  }
+}
+
+int cDemeCellEvent::GetNextEventCellID() {
+  if(m_active && m_iter < m_event_cells.GetSize()) {
+    return m_event_cells[m_iter++];
+  }
+  m_iter = 0;
+  return -1;
+}
+
+void cDemeCellEvent::ActivateEvent(cWorld* m_world) {
+  m_eventID = m_world->GetRandom().GetInt(0x7FFFFFFF);
+  m_active = true;
+}
+
+void cDemeCellEvent::DeactivateEvent() {
+  m_active = false;
+}

Copied: branches/collect/source/main/cDemeCellEvent.h (from rev 2070, development/source/main/cDemeCellEvent.h)
===================================================================
--- branches/collect/source/main/cDemeCellEvent.h	                        (rev 0)
+++ branches/collect/source/main/cDemeCellEvent.h	2007-10-24 03:34:18 UTC (rev 2152)
@@ -0,0 +1,24 @@
+#ifndef cDemeCellEvent_h
+#define cDemeCellEvent_h
+
+#include "tArray.h"
+class cWorld;
+
+class cDemeCellEvent {
+private:
+  tArray<int> m_event_cells;
+  int m_delay, m_duration, m_eventID, m_iter;
+  bool m_active;
+  
+public:
+  cDemeCellEvent() { cDemeCellEvent(-1, -1, -1, -1, 0, 0, 0); }
+  cDemeCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, int width);
+  int GetNextEventCellID();
+  int GetDelay() { return m_delay; }
+  int GetDuration() { return m_duration; }
+  int GetEventID() { return m_eventID; }
+
+  void ActivateEvent(cWorld* m_world);
+  void DeactivateEvent();
+};
+#endif

Modified: branches/collect/source/main/cOrganism.cc
===================================================================
--- branches/collect/source/main/cOrganism.cc	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/main/cOrganism.cc	2007-10-24 03:34:18 UTC (rev 2152)
@@ -288,7 +288,7 @@
   if(m_world->GetConfig().ENERGY_ENABLED.Get() && m_world->GetConfig().APPLY_ENERGY_METHOD.Get() == 1 && task_completed) {
     m_phenotype.RefreshEnergy();
     m_phenotype.ApplyToEnergyStore();
-    double newMerit = cMerit::EnergyToMerit(GetPhenotype().GetStoredEnergy(), m_world) * GetPhenotype().GetExecutionRatio();
+    double newMerit = cMerit::EnergyToMerit(GetPhenotype().GetStoredEnergy() * GetPhenotype().GetEnergyUsageRatio(), m_world);
     if(newMerit != -1) {
       m_interface->UpdateMerit(newMerit);
     }

Modified: branches/collect/source/main/cPhenotype.cc
===================================================================
--- branches/collect/source/main/cPhenotype.cc	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/main/cPhenotype.cc	2007-10-24 03:34:18 UTC (rev 2152)
@@ -1458,6 +1458,19 @@
   energy_store = max(0.0, min(value, (double) m_world->GetConfig().ENERGY_CAP.Get()));
 }
 
+bool cPhenotype::DoubleEnergyUsage(double energy_req) {
+  if(GetStoredEnergy() < energy_req) {
+    return false;
+  }
+  executionRatio *= 2.0;
+  return true;
+}
+
+void cPhenotype::HalfEnergyUsage() {
+  executionRatio *= 0.5;
+}
+
+
 /**
 Credit organism with energy reward, but only update energy store if APPLY_ENERGY_METHOD = "on task completion" (1)
  */
@@ -1505,13 +1518,9 @@
   ReduceEnergy(child_energy - 2*energy_given_at_birth); // 2*energy_given_at_birth: 1 in child_energy & 1 for parent
     
   //TODO: add energy_given_at_birth to Stored_energy
-  cMerit parentMerit = cMerit(cMerit::EnergyToMerit(GetStoredEnergy(), m_world) * GetExecutionRatio());
+  cMerit parentMerit = cMerit(cMerit::EnergyToMerit(GetStoredEnergy() * GetEnergyUsageRatio(), m_world));
   SetMerit(parentMerit);
   
-/*  if(m_world->GetConfig().ENERGY_VERBOSE.Get()) {
-    cerr<<"child merit: "<<merit_array[0]<<endl<<"child energy: "<< child_energy <<endl
-    <<"parent merit: "<<GetMerit()<<endl<<"parent energy: "<< GetStoredEnergy() <<endl;
-  }*/
   return child_energy;
 }
 

Modified: branches/collect/source/main/cPhenotype.h
===================================================================
--- branches/collect/source/main/cPhenotype.h	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/main/cPhenotype.h	2007-10-24 03:34:18 UTC (rev 2152)
@@ -280,7 +280,7 @@
 
   /////////////////////  Accessors -- Retrieving  ////////////////////
   const cMerit & GetMerit() const { assert(initialized == true); return merit; }
-  double GetExecutionRatio() const { assert(initialized == true); return executionRatio; }
+  double GetEnergyUsageRatio() const { assert(initialized == true); return executionRatio; }
   int GetGenomeLength() const { assert(initialized == true); return genome_length; }
   int GetCopiedSize() const { assert(initialized == true); return copied_size; }
   int GetExecutedSize() const { assert(initialized == true); return executed_size; }
@@ -474,8 +474,8 @@
   bool& ChildFertile() { assert(initialized == true); return child_fertile; }
   bool& IsMultiThread() { assert(initialized == true); return is_multi_thread; }
   
-  void DoubleEnergyUsage() { executionRatio *= 2.0; }
-  void HalfEnergyUsage() { executionRatio *= 0.5; }
+  bool DoubleEnergyUsage(double inst_energy_cost);
+  void HalfEnergyUsage();
   void RefreshEnergy();
   void ApplyToEnergyStore();
   double ExtractParentEnergy();

Modified: branches/collect/source/main/cPopulation.cc
===================================================================
--- branches/collect/source/main/cPopulation.cc	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/main/cPopulation.cc	2007-10-24 03:34:18 UTC (rev 2152)
@@ -119,7 +119,6 @@
   
   // Allocate the cells, resources, and market.
   cell_array.ResizeClear(num_cells);
-//  resource_count.ResizeSpatialGrids(world_x, world_y);
   market.Resize(MARKET_SIZE);
   
   // Setup the cells.  Do things that are not dependent upon topology here.
@@ -145,7 +144,7 @@
       deme_cells[offset] = cell_id;
       cell_array[cell_id].SetDemeID(deme_id);
     }
-    deme_array[deme_id].Setup(deme_cells, deme_size_x);
+    deme_array[deme_id].Setup(deme_cells, deme_size_x, m_world);
   }
   
   // Setup the topology.
@@ -195,11 +194,7 @@
   for(int i = 0; i < GetNumDemes(); i++) {
     cResourceCount tmp_deme_res_count(num_deme_res);
     GetDeme(i).SetDemeResourceCount(tmp_deme_res_count);
-    //TODO: make sure grid is the right grid/size
-    //GetDeme(i).GetDemeResourceCount().ResizeSpatialGrids(world_x, world_y);
-
     GetDeme(i).ResizeSpatialGrids(deme_size_x, deme_size_y);
-//    GetDeme(i).GetDemeResourceCount().
   }
 
   for (int i = 0; i < resource_lib.GetSize(); i++) {
@@ -1065,6 +1060,7 @@
 0: 'all'       - ...all non-empty demes in the population.
 1: 'full_deme' - ...demes that have been filled up.
 2: 'corners'   - ...demes with upper left and lower right corners filled.
+3: 'deme-age'  - ...demes who have reached their maximum age
 */
 
 void cPopulation::ReplicateDemes(int rep_trigger)
@@ -1170,18 +1166,33 @@
       source_deme.Reset();
       target_deme.Reset();
   
-      // Lineage label is wrong here; fix.
-      if(m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get()) {
-        InjectGenome(source_deme.GetCellID(m_world->GetRandom().GetInt(0, source_deme.GetSize()-1)),
-                     source_germline.GetLatest(), 0);
-        InjectGenome(target_deme.GetCellID(m_world->GetRandom().GetInt(0, target_deme.GetSize()-1)),
-                     target_germline.GetLatest(), 0);
+      int source_deme_inject_cell;
+      int target_deme_inject_cell;
+      
+      if(m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get() == 2) {
+        // organism is randomly placed in deme
+        source_deme_inject_cell = source_deme.GetCellID(m_world->GetRandom().GetInt(0, source_deme.GetSize()-1));
+        target_deme_inject_cell = target_deme.GetCellID(m_world->GetRandom().GetInt(0, target_deme.GetSize()-1));
       } else {
-        InjectGenome(source_deme.GetCellID(source_deme.GetSize()/2), source_germline.GetLatest(), 0);
-        InjectGenome(target_deme.GetCellID(target_deme.GetSize()/2), target_germline.GetLatest(), 0);
+        // organisms is placed in center of deme
+        source_deme_inject_cell = source_deme.GetCellID(source_deme.GetSize()/2);
+        target_deme_inject_cell = target_deme.GetCellID(target_deme.GetSize()/2);
       }
+      // Lineage label is wrong here; fix.
+      InjectGenome(source_deme_inject_cell, source_germline.GetLatest(), 0); // source deme
+      InjectGenome(target_deme_inject_cell, target_germline.GetLatest(), 0); // target deme
       
-      // Note: not rotating the clones.
+      if(m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get() == 1) {
+        // Rotate both injected cells to face northwest.
+        int offset = source_deme.GetCellID(0);
+        cell_array[source_deme_inject_cell].Rotate(cell_array[GridNeighbor(source_deme_inject_cell-offset,
+                                                              source_deme.GetWidth(),
+                                                              source_deme.GetHeight(), -1, -1)+offset]);
+        offset = target_deme.GetCellID(0);
+        cell_array[target_deme_inject_cell].Rotate(cell_array[GridNeighbor(target_deme_inject_cell-offset,
+                                                              target_deme.GetWidth(), 
+                                                              target_deme.GetHeight(), -1, -1)+offset]);
+      }
     } else {
       // Not using germline; choose a random organism from this deme.
       int cell1_id = -1;
@@ -1194,7 +1205,7 @@
         cGenome seed_genome = seed_org->GetGenome();
         int seed_lineage = seed_org->GetLineageLabel();
 
-        // Kill all the organisms in the source deme.  Orgs. in dest. deme are already killed
+        // Kill all the organisms in the source deme.  Orgs. in target deme have already been killed
         for (int i=0; i<source_deme.GetSize(); i++) {
           KillOrganism(cell_array[source_deme.GetCellID(i)]);
         }
@@ -1202,9 +1213,23 @@
         source_deme.Reset();
         target_deme.Reset();
 
-        InjectGenome(source_deme.GetCellID(source_deme.GetSize()/2), seed_genome, seed_lineage); // source deme
-        InjectGenome(target_deme.GetCellID(target_deme.GetSize()/2), seed_genome, seed_lineage); // destination deme
+        int source_deme_inject_cell = source_deme.GetCellID(source_deme.GetSize()/2);
+        int target_deme_inject_cell = target_deme.GetCellID(target_deme.GetSize()/2);
         
+        InjectGenome(source_deme_inject_cell, seed_genome, seed_lineage); // source deme
+        InjectGenome(target_deme_inject_cell, seed_genome, seed_lineage); // target deme
+        
+        // Rotate both injected cells to face northwest.
+        int offset = source_deme.GetCellID(0);
+        cell_array[source_deme_inject_cell].Rotate(cell_array[GridNeighbor(source_deme_inject_cell-offset,
+                                                              source_deme.GetWidth(),
+                                                              source_deme.GetHeight(), -1, -1)+offset]);
+        offset = target_deme.GetCellID(0);
+        cell_array[target_deme_inject_cell].Rotate(cell_array[GridNeighbor(target_deme_inject_cell-offset,
+                                                              target_deme.GetWidth(), 
+                                                              target_deme.GetHeight(), -1, -1)+offset]);
+
+        
       } else {
         cOrganism* seed = cell_array[cell1_id].GetOrganism();
         
@@ -1231,8 +1256,7 @@
         cell_array[cell3_id].Rotate(cell_array[GridNeighbor(cell3_id-offset,
                                                             source_deme.GetWidth(),
                                                             source_deme.GetHeight(), -1, -1)+offset]);
-                                                            
-                                          
+
         // This is in the wrong place.  Reset should be done after the demes are cleared and before the org. is injected.
         source_deme.Reset();
         target_deme.Reset();

Modified: branches/collect/source/main/cPopulationCell.cc
===================================================================
--- branches/collect/source/main/cPopulationCell.cc	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/main/cPopulationCell.cc	2007-10-24 03:34:18 UTC (rev 2152)
@@ -45,6 +45,7 @@
   , m_cell_id(in_cell.m_cell_id)
   , m_deme_id(in_cell.m_deme_id)
   , m_organism_count(in_cell.m_organism_count)
+  , m_cell_data(in_cell.m_cell_data)
 {
   // Copy the mutation rates into a new structure
   m_mut_rates = new cMutationRates(*in_cell.m_mut_rates);
@@ -64,6 +65,7 @@
   m_cell_id = in_cell.m_cell_id;
   m_deme_id = in_cell.m_deme_id;
   m_organism_count = in_cell.m_organism_count;
+  m_cell_data = in_cell.m_cell_data;
 
   // Copy the mutation rates, constructing the structure as necessary
   if (m_mut_rates == NULL)
@@ -84,6 +86,7 @@
   m_x = x;
   m_y = y;
   m_deme_id = -1;
+  m_cell_data = 0;
   
   if (m_mut_rates == NULL)
     m_mut_rates = new cMutationRates(in_rates);
@@ -179,7 +182,7 @@
     if(uptake_energy != 0.0) {
       // update energy and merit
       m_organism->GetPhenotype().ReduceEnergy(-1.0 * uptake_energy);
-      m_organism->GetPhenotype().SetMerit(cMerit(cMerit::EnergyToMerit(m_organism->GetPhenotype().GetStoredEnergy(), m_world) * m_organism->GetPhenotype().GetExecutionRatio()));
+      m_organism->GetPhenotype().SetMerit(cMerit(cMerit::EnergyToMerit(m_organism->GetPhenotype().GetStoredEnergy() * m_organism->GetPhenotype().GetEnergyUsageRatio(), m_world)));
     }
   }
 }

Modified: branches/collect/source/main/cPopulationCell.h
===================================================================
--- branches/collect/source/main/cPopulationCell.h	2007-10-24 03:05:21 UTC (rev 2151)
+++ branches/collect/source/main/cPopulationCell.h	2007-10-24 03:34:18 UTC (rev 2152)
@@ -59,6 +59,7 @@
   int m_cell_id;           // Unique id for position of cell in population.
   int m_deme_id;           // ID of the deme that this cell is part of.
   int m_organism_count;    // Total number of orgs to ever inhabit this cell.
+  int m_cell_data;         // "data" that is local to the cell and can be retrieaved by the org.
 
   // location in population
   int m_x; //!< The x-coordinate of the position of this cell in the environment.
@@ -98,6 +99,8 @@
   inline int GetID() const { return m_cell_id; }
   inline int GetDemeID() const { return m_deme_id; }
   inline int GetOrganismCount() const { return m_organism_count; }
+  inline int GetCellData() const { return m_cell_data; }
+  void SetCellData(const int data) { m_cell_data = data; }
 
   inline bool IsOccupied() const { return m_organism != NULL; }
 




More information about the Avida-cvs mailing list