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

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Wed Apr 30 13:14:50 PDT 2008


Author: beckma24
Date: 2008-04-30 16:14:50 -0400 (Wed, 30 Apr 2008)
New Revision: 2565

Modified:
   branches/jobScheduling/source/cpu/cHardwareCPU.cc
   branches/jobScheduling/source/cpu/cHardwareCPU.h
   branches/jobScheduling/source/main/cDeme.cc
   branches/jobScheduling/source/main/cDeme.h
   branches/jobScheduling/source/main/cPopulation.cc
   branches/jobScheduling/source/main/cStats.cc
   branches/jobScheduling/source/main/cStats.h
Log:
Added ablity for an attack to remove energy from and organism.

Modified: branches/jobScheduling/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/jobScheduling/source/cpu/cHardwareCPU.cc	2008-04-30 18:17:20 UTC (rev 2564)
+++ branches/jobScheduling/source/cpu/cHardwareCPU.cc	2008-04-30 20:14:50 UTC (rev 2565)
@@ -251,6 +251,7 @@
     tInstLibEntry<tMethod>("move-to-event", &cHardwareCPU::Inst_MoveToEvent, nInstFlag::STALL),
     tInstLibEntry<tMethod>("if-event-in-unoccupied-neighbor-cell", &cHardwareCPU::Inst_IfNeighborEventInUnoccupiedCell),
     tInstLibEntry<tMethod>("if-event-in-faced-cell", &cHardwareCPU::Inst_IfFacingEventCell),
+    tInstLibEntry<tMethod>("if-event-in-current-cell", &cHardwareCPU::Inst_IfEventInCell),
     
     // Threading instructions
     tInstLibEntry<tMethod>("fork-th", &cHardwareCPU::Inst_ForkThread),
@@ -4124,6 +4125,14 @@
   return true;
 }
 
+bool cHardwareCPU::Inst_IfEventInCell(cAvidaContext& ctx) {
+  if(organism->GetCellData() > 0) { 
+      return true;
+  }
+  IP().Advance();
+  return true;
+}
+
 // Multi-threading.
 bool cHardwareCPU::Inst_ForkThread(cAvidaContext& ctx)
 {

Modified: branches/jobScheduling/source/cpu/cHardwareCPU.h
===================================================================
--- branches/jobScheduling/source/cpu/cHardwareCPU.h	2008-04-30 18:17:20 UTC (rev 2564)
+++ branches/jobScheduling/source/cpu/cHardwareCPU.h	2008-04-30 20:14:50 UTC (rev 2565)
@@ -507,6 +507,7 @@
   bool Inst_MoveToEvent(cAvidaContext& ctx);
   bool Inst_IfNeighborEventInUnoccupiedCell(cAvidaContext& ctx);
   bool Inst_IfFacingEventCell(cAvidaContext& ctx);
+  bool Inst_IfEventInCell(cAvidaContext& ctx);
 
   // Multi-threading...
 

Modified: branches/jobScheduling/source/main/cDeme.cc
===================================================================
--- branches/jobScheduling/source/main/cDeme.cc	2008-04-30 18:17:20 UTC (rev 2564)
+++ branches/jobScheduling/source/main/cDeme.cc	2008-04-30 20:14:50 UTC (rev 2565)
@@ -38,6 +38,7 @@
   _id = id;
   cell_ids = in_cells;
   birth_count = 0;
+  birth_count_perslot = 0;
   org_count = 0;
   m_world = world;
 
@@ -101,11 +102,18 @@
       cResource* res = m_world->GetEnvironment().GetResourceLib().GetResource("CELL_ENERGY");
       
       while(eventCell != -1) {
-        if(event.GetEventID() == m_world->GetPopulation().GetCell(GetCellID(eventCell)).GetCellData()){
+        cPopulationCell& cell = m_world->GetPopulation().GetCell(GetCellID(eventCell));
+        if(event.GetEventID() == cell.GetCellData()){
+          if(cell.IsOccupied()) {
+            // remove energy from organism
+            cPhenotype& orgPhenotype = cell.GetOrganism()->GetPhenotype();
+            orgPhenotype.ReduceEnergy(orgPhenotype.GetStoredEnergy()*m_world->GetConfig().ATTACK_DECAY_RATE.Get());
+          }
+          //remove energy from cell... organism might not takeup all of a cell's energy
           tArray<double> cell_resources = deme_resource_count.GetCellResources(eventCell);  // uses global cell_id; is this a problem
           cell_resources[res->GetID()] *= m_world->GetConfig().ATTACK_DECAY_RATE.Get();
           deme_resource_count.ModifyCell(cell_resources, eventCell);
-        }        
+        }
         eventCell = event.GetNextEventCellID();
       }
     }
@@ -150,8 +158,12 @@
       
       (m_world->GetStats().FlowRateTuples())[(*iter).second].orgCount.Add(GetOrgCount());
       (m_world->GetStats().FlowRateTuples())[(*iter).second].eventsKilled.Add(GetEventsKilledThisSlot());
+      (m_world->GetStats().FlowRateTuples())[(*iter).second].attemptsToKillEvents.Add(GetEventKillAttemptsThisSlot());
       (m_world->GetStats().FlowRateTuples())[(*iter).second].AvgEnergyUsageRatio.Add(energyUsage.Average());
+      (m_world->GetStats().FlowRateTuples())[(*iter).second].totalBirths.Add(birth_count_perslot);
+      birth_count_perslot = 0;
       eventsKilledThisSlot = 0;
+      eventKillAttemptsThisSlot = 0;
       break;
     }
   }
@@ -194,9 +206,13 @@
   _age = 0;
   time_used = 0;
   birth_count = 0;
+  birth_count_perslot = 0;
   cur_normalized_time_used = 0;
   eventsKilled = 0;
   eventsKilledThisSlot = 0;
+  eventKillAttempts = 0;
+  eventKillAttemptsThisSlot = 0;
+  
   consecutiveSuccessfulEventPeriods = 0;
   
   //TODO // remove energy outflow from these cells
@@ -357,11 +373,16 @@
   for(int i = m_total_events_per_slot_min; i <= m_total_events_per_slot_max; i+=flow_level_increment) {
     (stats.FlowRateTuples())[i].orgCount.Clear();
     (stats.FlowRateTuples())[i].eventsKilled.Clear();
+    (stats.FlowRateTuples())[i].attemptsToKillEvents.Clear();
     (stats.FlowRateTuples())[i].AvgEnergyUsageRatio.Clear();
+    (stats.FlowRateTuples())[i].totalBirths.Clear();
+
   }
 }
 
 bool cDeme::KillCellEvent(const int eventID) {
+  eventKillAttemptsThisSlot++;
+
   if(eventID <= 0)
     return false;
   for(int i = 0; i < cell_events.GetSize(); i++) {
@@ -382,6 +403,7 @@
       event.DeactivateEvent();  //event over
       eventsKilled++;
       eventsKilledThisSlot++;
+      eventKillAttempts++;
       return true;
     }
   }

Modified: branches/jobScheduling/source/main/cDeme.h
===================================================================
--- branches/jobScheduling/source/main/cDeme.h	2008-04-30 18:17:20 UTC (rev 2564)
+++ branches/jobScheduling/source/main/cDeme.h	2008-04-30 20:14:50 UTC (rev 2565)
@@ -53,6 +53,7 @@
 
 // The following should be moved to cDemePhenotype
   int birth_count; //!< Number of organisms that have been born into this deme since reset.
+  int birth_count_perslot;
   int org_count; //!< Number of organisms are currently in this deme.
   int _age; //!< Age of this deme, in updates.
   int generation; //!< Generation of this deme
@@ -64,6 +65,8 @@
   double last_normalized_time_used; 
   unsigned int eventsKilled;
   unsigned int eventsKilledThisSlot;
+  unsigned int eventKillAttempts;
+  unsigned int eventKillAttemptsThisSlot;
   unsigned int consecutiveSuccessfulEventPeriods;
   cDoubleSum energyUsage;
   
@@ -87,9 +90,10 @@
   cMerit _next_merit; //!< Deme merit that will be inherited upon deme replication.
   
 public:
-  cDeme() : _id(0), width(0), birth_count(0), org_count(0), _age(0), generation(0), total_org_energy(0.0), total_energy_testament(0.0),
+  cDeme() : _id(0), width(0), birth_count(0), birth_count_perslot(0), org_count(0), _age(0), generation(0), total_org_energy(0.0), total_energy_testament(0.0),
             time_used(0), gestation_time(0), cur_normalized_time_used(0.0), last_normalized_time_used(0.0), 
-            eventsKilled(0), eventsKilledThisSlot(0), consecutiveSuccessfulEventPeriods(0), deme_resource_count(0), m_germline_genotype_id(0) { ; }
+            eventsKilled(0), eventsKilledThisSlot(0), eventKillAttempts(0), eventKillAttemptsThisSlot(0),
+            consecutiveSuccessfulEventPeriods(0), deme_resource_count(0), m_germline_genotype_id(0) { ; }
   ~cDeme() { ; }
 
   void Setup(int id, const tArray<int>& in_cells, int in_width = -1, cWorld* world = NULL);
@@ -111,7 +115,7 @@
   //! Kills all organisms currently in this deme.
   void KillAll();
   int GetBirthCount() const { return birth_count; }
-  void IncBirthCount() { birth_count++; }
+  void IncBirthCount() { birth_count++; birth_count_perslot++; }
 
   int GetOrgCount() const { return org_count; }
   void IncOrgCount() { org_count++; }
@@ -122,6 +126,8 @@
   int GetSlotFlowRate() const;
   int GetEventsKilled() const { return eventsKilled; }
   int GetEventsKilledThisSlot() const { return eventsKilledThisSlot;}
+  int GetEventKillAttempts() const { return eventKillAttempts; }
+  int GetEventKillAttemptsThisSlot() const { return eventKillAttemptsThisSlot; }
   int GetConsecutiveSuccessfulEventPeriods() const { return consecutiveSuccessfulEventPeriods;}
   
   bool IsEmpty() const { return org_count == 0; }

Modified: branches/jobScheduling/source/main/cPopulation.cc
===================================================================
--- branches/jobScheduling/source/main/cPopulation.cc	2008-04-30 18:17:20 UTC (rev 2564)
+++ branches/jobScheduling/source/main/cPopulation.cc	2008-04-30 20:14:50 UTC (rev 2565)
@@ -2891,6 +2891,7 @@
   stats.SumDemeNormalizedTimeUsed().Clear();
   stats.SumDemeMerit().Clear();
   stats.SumDemeEventsKilled().Clear();
+  stats.SumDemeAttemptsToKillEvents() .Clear();
   
   for(int i = 0; i < GetNumDemes(); i++) {
     cDeme& deme = GetDeme(i);
@@ -2905,6 +2906,7 @@
     stats.SumDemeNormalizedTimeUsed().Add(deme.GetLastNormalizedTimeUsed());
     stats.SumDemeMerit().Add(deme.GetDemeMerit().GetDouble());
     stats.SumDemeEventsKilled().Add(deme.GetEventsKilled());
+    stats.SumDemeAttemptsToKillEvents().Add(deme.GetEventKillAttempts());
   }
 }
 

Modified: branches/jobScheduling/source/main/cStats.cc
===================================================================
--- branches/jobScheduling/source/main/cStats.cc	2008-04-30 18:17:20 UTC (rev 2564)
+++ branches/jobScheduling/source/main/cStats.cc	2008-04-30 20:14:50 UTC (rev 2565)
@@ -586,7 +586,8 @@
   df.Write(sum_deme_gestation_time.Average(),               "Gestation Time");
   df.Write(sum_deme_normalized_time_used.Average(),         "Time Used (normalized by org fitness)");
   df.Write(sum_deme_events_killed.Average(),                "Events killed");
-
+  df.Write(sum_deme_events_kill_attempts.Average(),         "Attempts to kill event");
+  
   df.Endl();
 }
 
@@ -604,12 +605,16 @@
     string flow_rate_str(oss.str());
     string flow_rate_pop_size_str(flow_rate_str+" deme pop size");
     string flow_rate_events_killed_str(flow_rate_str+" events killed");
+    string flow_rate_events_attempted_to_kill_str(flow_rate_str+" events attempted to kill");
     string flow_rate_exe_ratio_str(flow_rate_str+" exe ratio");
+    string flow_rate_total_births_str(flow_rate_str+" total births");
     
     df.Write((*iter).first, flow_rate_str.c_str());
     df.Write((*iter).second.orgCount.Average(), flow_rate_pop_size_str.c_str());
     df.Write((*iter).second.eventsKilled.Average(), flow_rate_events_killed_str.c_str());
+    df.Write((*iter).second.attemptsToKillEvents.Average(), flow_rate_events_attempted_to_kill_str.c_str());
     df.Write((*iter).second.AvgEnergyUsageRatio.Average(), flow_rate_exe_ratio_str.c_str());
+    df.Write((*iter).second.totalBirths.Average(), flow_rate_total_births_str.c_str());
     
   }
   df.Endl();
@@ -618,7 +623,9 @@
   for(map<int, flow_rate_tuple >::iterator iter = flow_rate_tuples.begin(); iter != flow_rate_tuples.end(); iter++) {
     (*iter).second.orgCount.Clear();
     (*iter).second.eventsKilled.Clear();
+    (*iter).second.attemptsToKillEvents.Clear();
     (*iter).second.AvgEnergyUsageRatio.Clear();
+    (*iter).second.totalBirths.Clear();
   }
 }
 

Modified: branches/jobScheduling/source/main/cStats.h
===================================================================
--- branches/jobScheduling/source/main/cStats.h	2008-04-30 18:17:20 UTC (rev 2564)
+++ branches/jobScheduling/source/main/cStats.h	2008-04-30 20:14:50 UTC (rev 2565)
@@ -75,7 +75,9 @@
 struct flow_rate_tuple {
   cIntSum orgCount;
   cIntSum eventsKilled;
+  cIntSum attemptsToKillEvents;
   cDoubleSum AvgEnergyUsageRatio;
+  cIntSum totalBirths;
 };
 
 class cStats
@@ -281,6 +283,7 @@
   cDoubleSum sum_deme_normalized_time_used;
   cDoubleSum sum_deme_merit;
   cIntSum sum_deme_events_killed;
+  cIntSum sum_deme_events_kill_attempts;
   
   cDoubleSum EnergyTestamentToFutureDeme;
   cDoubleSum EnergyTestamentToNeighborOrganisms;
@@ -434,7 +437,8 @@
   cIntSum& SumDemeGestationTime()   { return sum_deme_gestation_time; }
   cDoubleSum& SumDemeNormalizedTimeUsed()   { return sum_deme_normalized_time_used; }
   cDoubleSum& SumDemeMerit()   { return sum_deme_merit; }
-  cIntSum& SumDemeEventsKilled()          { return sum_deme_events_killed; }
+  cIntSum& SumDemeEventsKilled()          { return sum_deme_events_killed; }  
+  cIntSum& SumDemeAttemptsToKillEvents()          { return sum_deme_events_kill_attempts; }
   
   cDoubleSum& SumEnergyTestamentToFutureDeme() { return EnergyTestamentToFutureDeme;}
   cDoubleSum& SumEnergyTestamentToNeighborOrganisms() { return EnergyTestamentToNeighborOrganisms; }
@@ -485,6 +489,8 @@
   const cDoubleSum& SumDemeNormalizedTimeUsed() const  { return sum_deme_normalized_time_used; }
   const cDoubleSum& SumDemeMerit()  const  { return sum_deme_merit; }
   const cIntSum& SumDemeEventsKilled() const          { return sum_deme_events_killed; }
+  const cIntSum& SumDemeAttemptsToKillEvents() const  { return sum_deme_events_kill_attempts; }
+
   
   const cDoubleSum& SumEnergyTestamentToFutureDeme() const { return EnergyTestamentToFutureDeme;}
   const cDoubleSum& SumEnergyTestamentToNeighborOrganisms() const { return EnergyTestamentToNeighborOrganisms; }




More information about the Avida-cvs mailing list