[Avida-SVN] r2552 - in branches/jobScheduling/source: cpu main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Thu Apr 24 12:08:03 PDT 2008


Author: beckma24
Date: 2008-04-24 15:08:03 -0400 (Thu, 24 Apr 2008)
New Revision: 2552

Modified:
   branches/jobScheduling/source/cpu/cHardwareCPU.cc
   branches/jobScheduling/source/main/cAvidaConfig.h
   branches/jobScheduling/source/main/cDeme.cc
   branches/jobScheduling/source/main/cPopulation.cc
Log:
Created attacks that consume energy from a cell until it is killed.  Other minor fixes to instructions

Modified: branches/jobScheduling/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/jobScheduling/source/cpu/cHardwareCPU.cc	2008-04-24 14:47:26 UTC (rev 2551)
+++ branches/jobScheduling/source/cpu/cHardwareCPU.cc	2008-04-24 19:08:03 UTC (rev 2552)
@@ -4095,7 +4095,7 @@
     organism->Rotate(1);
   }
   assert(organism->GetFacing() == orginalFacing);
-  
+  Inst_Move(ctx);
   GetRegister(reg_used) = 0;
   return true;
 }

Modified: branches/jobScheduling/source/main/cAvidaConfig.h
===================================================================
--- branches/jobScheduling/source/main/cAvidaConfig.h	2008-04-24 14:47:26 UTC (rev 2551)
+++ branches/jobScheduling/source/main/cAvidaConfig.h	2008-04-24 19:08:03 UTC (rev 2552)
@@ -319,6 +319,7 @@
   CONFIG_ADD_VAR(DEMES_NUM_X, int, 0, "Simulated number of demes in X dimension. Only used for migration. ");
   CONFIG_ADD_VAR(DEMES_SEED_METHOD, int, 0, "Deme seeding method.\n0=maintain old consistency\n1=new method using genotypes");
   CONFIG_ADD_VAR(DEMES_DIVIDE_METHOD, int, 0, "Deme divide method. Only works with DEMES_SEED_METHOD 1\n0=replace and target demes\n1= replace target deme, reset source deme to founders\n2=replace target deme, leave source deme unchanged");
+  CONFIG_ADD_VAR(DEMES_PREFER_EMPTY, int, 0, "Give empty demes preference as targets of deme replication?");
 
   CONFIG_ADD_GROUP(REPRODUCTION_GROUP, "Birth and Death");
   CONFIG_ADD_VAR(BIRTH_METHOD, int, 0, "Which organism should be replaced on birth?\n0 = Random organism in neighborhood\n1 = Oldest in neighborhood\n2 = Largest Age/Merit in neighborhood\n3 = None (use only empty cells in neighborhood)\n4 = Random from population (Mass Action)\n5 = Oldest in entire population\n6 = Random within deme\n7 = Organism faced by parent\n8 = Next grid cell (id+1)\n9 = Largest energy used in entire population\n10 = Largest energy used in neighborhood");

Modified: branches/jobScheduling/source/main/cDeme.cc
===================================================================
--- branches/jobScheduling/source/main/cDeme.cc	2008-04-24 14:47:26 UTC (rev 2551)
+++ branches/jobScheduling/source/main/cDeme.cc	2008-04-24 19:08:03 UTC (rev 2552)
@@ -23,6 +23,7 @@
 
 #include "cDeme.h"
 #include "cClassificationManager.h"
+#include "cEnvironment.h"
 #include "cGenotype.h"
 #include "cOrganism.h"
 #include "cPhenotype.h"
@@ -93,20 +94,45 @@
 
   for(int i = 0; i < cell_events.GetSize(); i++) {
     cDemeCellEvent& event = cell_events[i];
-    if(event.GetDelay() == _age) {
+    
+    if(event.IsActive() && event.GetDelay() < _age && _age <= event.GetDelay()+event.GetDuration()) {
+      //remove energy from cells  (should be done with outflow, but this will work for now)
+      int eventCell = event.GetNextEventCellID();
+      cResource* res = m_world->GetEnvironment().GetResourceLib().GetResource("CELL_ENERGY");
+      
+      while(eventCell != -1) {
+        if(event.GetEventID() == m_world->GetPopulation().GetCell(GetCellID(eventCell)).GetCellData()){
+          tArray<double> cell_resources = deme_resource_count.GetCellResources(eventCell);  // uses global cell_id; is this a problem
+          cell_resources[res->GetID()] *= -0.05;
+          deme_resource_count.ModifyCell(cell_resources, eventCell);
+        }        
+        eventCell = event.GetNextEventCellID();
+      }
+    }
+    
+    
+    
+    if(!event.IsActive() && event.GetDelay() == _age) {
       event.ActivateEvent(); //start event
       int eventCell = event.GetNextEventCellID();
       while(eventCell != -1) {
         // place event ID in cells' data
         m_world->GetPopulation().GetCell(GetCellID(eventCell)).SetCellData(event.GetEventID());
+
+        //TODO // increase outflow of energy from these cells if not event currently present
+        
+        
         eventCell = event.GetNextEventCellID();
       }
-    } else if(event.GetDelay()+event.GetDuration() == _age) {
+    } else if(event.IsActive() && 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);
+
+        //  TODO // remove energy outflow from these cells
+
         }
         eventCell = event.GetNextEventCellID();
       }
@@ -173,6 +199,8 @@
   eventsKilledThisSlot = 0;
   consecutiveSuccessfulEventPeriods = 0;
   
+  //TODO // remove energy outflow from these cells
+
   if(resetResources)
     deme_resource_count.ReinitializeResources(additional_resource);
 }
@@ -345,6 +373,9 @@
         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);
+          
+        //  TODO // remove energy outflow from these cells
+
         }
         eventCell = event.GetNextEventCellID();
       }

Modified: branches/jobScheduling/source/main/cPopulation.cc
===================================================================
--- branches/jobScheduling/source/main/cPopulation.cc	2008-04-24 14:47:26 UTC (rev 2551)
+++ branches/jobScheduling/source/main/cPopulation.cc	2008-04-24 19:08:03 UTC (rev 2552)
@@ -1210,12 +1210,33 @@
     }
     
     // Pick a target deme to replicate to, making sure that 
-    // we don't try to replicate over ourself.
-    int target_id = source_deme.GetID();
-    const int num_demes = GetNumDemes();
-    while(target_id == source_deme.GetID()) {
-      target_id = m_world->GetRandom().GetUInt(num_demes);
+    // we don't try to replicate over ourself, i.e. DEMES_REPLACE_PARENT 0
+    
+    int target_id = -1;
+    if (m_world->GetConfig().DEMES_PREFER_EMPTY.Get()) {
+    
+      //@JEB -- use empty_cell_id_array to hold empty demes
+      //so we don't have to allocate a list
+      int num_empty = 0;
+      for (int i=0; i<GetNumDemes(); i++) {
+        if (GetDeme(i).IsEmpty()) {
+          empty_cell_id_array[num_empty] = i;
+          num_empty++;
+        }
+      }  
+      if (num_empty > 0) {
+        target_id = empty_cell_id_array[m_world->GetRandom().GetUInt(num_empty)];
+      }
     }
+    
+    // if we haven't found one yet, choose a random one
+    if (target_id == -1) {
+      target_id = source_deme.GetID();
+      const int num_demes = GetNumDemes();
+      while(target_id == source_deme.GetID()) {
+        target_id = m_world->GetRandom().GetUInt(num_demes);
+      }
+    }
   
     ReplaceDeme(source_deme, deme_array[target_id]);
 }




More information about the Avida-cvs mailing list