[Avida-SVN] r2653 - in development/source: actions main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Mon Jun 16 13:19:35 PDT 2008


Author: beckma24
Date: 2008-06-16 16:19:35 -0400 (Mon, 16 Jun 2008)
New Revision: 2653

Modified:
   development/source/actions/PopulationActions.cc
   development/source/main/cDeme.cc
   development/source/main/cDeme.h
   development/source/main/cPopulationCell.cc
   development/source/main/cResourceCount.cc
   development/source/main/cResourceCount.h
Log:
Added attack/energy fitness function

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2008-06-16 17:39:50 UTC (rev 2652)
+++ development/source/actions/PopulationActions.cc	2008-06-16 20:19:35 UTC (rev 2653)
@@ -1259,7 +1259,23 @@
   virtual double Fitness(const cDeme& deme) = 0;
 };
 
+class cAbstractCompeteDemes_AttackKillAndEnergyConserve : public cAbstractCompeteDemes {
 
+  public:
+    cAbstractCompeteDemes_AttackKillAndEnergyConserve(cWorld* world, const cString& args) : cAbstractCompeteDemes(world, args) { }
+
+    static const cString GetDescription() { return "No Arguments"; }
+  
+    double Fitness(const cDeme& deme) {    
+      double eventsKilled = static_cast<double>(deme.GetEventsKilled());
+      double totalEvents  = static_cast<double>(deme.GetEventsTotal());
+      double energyRemaining = deme.CalculateTotalEnergy();
+      double initialEnergy = deme.CalculateTotalInitialEnergyResources();
+      double fitnessOfDeme = ((eventsKilled / totalEvents) + (energyRemaining / initialEnergy)) / 2.0;
+      return fitnessOfDeme;
+    }
+};
+
 /* This Action will check if any demes have met the critera to be replicated
    and do so.  There are several bases this can be checked on:
 
@@ -1948,6 +1964,9 @@
   action_lib->Register<cActionDivideDemes>("DivideDemes");
   action_lib->Register<cActionResetDemes>("ResetDemes");
   action_lib->Register<cActionCopyDeme>("CopyDeme");
+
+/****AbstractCompeteDemes sub-classes****/
+  action_lib->Register<cAbstractCompeteDemes_AttackKillAndEnergyConserve>("CompeteDemes_AttackKillAndEnergyConserve");
   
   action_lib->Register<cActionNewTrial>("NewTrial");
   action_lib->Register<cActionCompeteOrganisms>("CompeteOrganisms");

Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc	2008-06-16 17:39:50 UTC (rev 2652)
+++ development/source/main/cDeme.cc	2008-06-16 20:19:35 UTC (rev 2653)
@@ -151,6 +151,7 @@
     
     
     if(!event.IsActive() && event.GetDelay() == _age) {
+      eventsTotal++;
       event.ActivateEvent(); //start event
       int eventCell = event.GetNextEventCellID();
       while(eventCell != -1) {
@@ -252,6 +253,7 @@
   cur_normalized_time_used = 0;
   injected_count = 0;
   birth_count_perslot = 0;
+  eventsTotal = 0;
   eventsKilled = 0;
   eventsKilledThisSlot = 0;
   eventKillAttempts = 0;
@@ -548,7 +550,7 @@
   return false;
 }
 
-double cDeme::CalculateTotalEnergy() {
+double cDeme::CalculateTotalEnergy() const {
   assert(m_world->GetConfig().ENERGY_ENABLED.Get());
     
   double energy_sum = 0.0;
@@ -567,6 +569,17 @@
   return energy_sum;
 }
 
+double cDeme::CalculateTotalInitialEnergyResources() const {
+  assert(m_world->GetConfig().ENERGY_ENABLED.Get());
+    
+  double energy_sum = 0.0;
+  for(int i = 0; i < energy_res_ids.GetSize(); i++) {
+    energy_sum += deme_resource_count.GetInitialResourceValue(i);
+  }
+  return energy_sum;
+}
+
+
 // --- Founder list management --- //
 
 void cDeme::AddFounder(cGenotype& _in_genotype, cPhenotype * _in_phenotype) {

Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h	2008-06-16 17:39:50 UTC (rev 2652)
+++ development/source/main/cDeme.h	2008-06-16 20:19:35 UTC (rev 2653)
@@ -71,6 +71,7 @@
   double cur_normalized_time_used; // normalized by merit and number of orgs
   double last_normalized_time_used; 
   double total_energy_testament; //! total amount of energy from suicide organisms for offspring deme
+  int eventsTotal;
   unsigned int eventsKilled;
   unsigned int eventsKilledThisSlot;
   unsigned int eventKillAttempts;
@@ -121,7 +122,7 @@
   cDeme() : _id(0), width(0), cur_birth_count(0), last_birth_count(0), cur_org_count(0), last_org_count(0), injected_count(0), birth_count_perslot(0),
             _age(0), generation(0), total_org_energy(0.0),
             time_used(0), gestation_time(0), cur_normalized_time_used(0.0), last_normalized_time_used(0.0), total_energy_testament(0.0),
-            eventsKilled(0), eventsKilledThisSlot(0), eventKillAttempts(0), eventKillAttemptsThisSlot(0),
+            eventsTotal(0), eventsKilled(0), eventsKilledThisSlot(0), eventKillAttempts(0), eventKillAttemptsThisSlot(0),
             consecutiveSuccessfulEventPeriods(0), sleeping_count(0),
             avg_founder_generation(0.0), generations_per_lifetime(0.0),
             deme_resource_count(0), m_germline_genotype_id(0) { ; }
@@ -172,6 +173,7 @@
   bool IsFull() const { return cur_org_count == cell_ids.GetSize(); }
 
   int GetSlotFlowRate() const;
+  int GetEventsTotal() const { return eventsTotal; }
   int GetEventsKilled() const { return eventsKilled; }
   int GetEventsKilledThisSlot() const { return eventsKilledThisSlot;}
   int GetEventKillAttempts() const { return eventKillAttempts; }
@@ -241,7 +243,8 @@
   bool KillCellEvent(const int eventID);
   cDemeCellEvent* GetCellEvent(const int i) { return &cell_events[i]; };
   
-  double CalculateTotalEnergy();
+  double CalculateTotalEnergy() const;
+  double CalculateTotalInitialEnergyResources() const;
   double GetTotalEnergyTestament() { return total_energy_testament; }
   void IncreaseTotalEnergyTestament(double increment) { total_energy_testament += increment; }
   

Modified: development/source/main/cPopulationCell.cc
===================================================================
--- development/source/main/cPopulationCell.cc	2008-06-16 17:39:50 UTC (rev 2652)
+++ development/source/main/cPopulationCell.cc	2008-06-16 20:19:35 UTC (rev 2653)
@@ -208,7 +208,8 @@
 
   // For the moment, the cell doesn't keep track of much...
   cOrganism * out_organism = m_organism;
-  if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1 && m_world->GetConfig().FRAC_ENERGY_TRANSFER.Get() > 0.0) {
+  if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1 && m_world->GetConfig().FRAC_ENERGY_TRANSFER.Get() > 0.0
+      && m_world->GetConfig().FRAC_ENERGY_DECAY_AT_DEME_BIRTH.Get() != 1.0) { // hack
     m_world->GetPopulation().GetDeme(m_deme_id).GiveBackCellEnergy(m_cell_id, m_organism->GetPhenotype().GetStoredEnergy() * m_world->GetConfig().FRAC_ENERGY_TRANSFER.Get());
   }
   m_organism = NULL;

Modified: development/source/main/cResourceCount.cc
===================================================================
--- development/source/main/cResourceCount.cc	2008-06-16 17:39:50 UTC (rev 2652)
+++ development/source/main/cResourceCount.cc	2008-06-16 20:19:35 UTC (rev 2653)
@@ -494,6 +494,6 @@
 
 void cResourceCount::ReinitializeResources(double additional_resource){
   for(int i = 0; i < resource_name.GetSize(); i++) {
-    Set(i, resource_initial[i]+additional_resource);
+    Set(i, resource_initial[i]+additional_resource); //will cause problem if more than one resource is used.
   }
 }

Modified: development/source/main/cResourceCount.h
===================================================================
--- development/source/main/cResourceCount.h	2008-06-16 17:39:50 UTC (rev 2652)
+++ development/source/main/cResourceCount.h	2008-06-16 20:19:35 UTC (rev 2653)
@@ -106,6 +106,7 @@
   void ResizeSpatialGrids(int in_x, int in_y);
   cSpatialResCount GetSpatialResource(int id) { return spatial_resource_count[id]; }
   void ReinitializeResources(double additional_resource);
+  double GetInitialResourceValue(int resourceID) const { return resource_initial[resourceID]; }
   cString GetResName(int id) { return resource_name[id]; }
 };
 




More information about the Avida-cvs mailing list