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

connel42 at myxo.css.msu.edu connel42 at myxo.css.msu.edu
Thu May 21 08:26:24 PDT 2009


Author: connel42
Date: 2009-05-21 11:26:24 -0400 (Thu, 21 May 2009)
New Revision: 3252

Modified:
   development/source/actions/PopulationActions.cc
   development/source/main/cDeme.cc
   development/source/main/cDeme.h
Log:
Added deme treatment ages, kill action now using this and deme isTreatable()

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2009-05-21 01:43:49 UTC (rev 3251)
+++ development/source/actions/PopulationActions.cc	2009-05-21 15:26:24 UTC (rev 3252)
@@ -2869,7 +2869,7 @@
  */
 
 class cActionKillDemePercent : public cAction
-  {
+{
   private:
     double m_pctkills;
   public:
@@ -2882,29 +2882,73 @@
       assert(m_pctkills <= 1);
     }
     
-    static const cString GetDescription() { return "Arguments: [int pctkills=0.0]"; }
+    static const cString GetDescription() { return "Arguments: [double pctkills=0.0]"; }
     
     void Process(cAvidaContext& ctx)
     {
       int target_cell;
 
       for (int d = 0; d < m_world->GetPopulation().GetNumDemes(); d++) {
-        for (int c = 0; c < m_world->GetPopulation().GetDeme(d).GetWidth() * m_world->GetPopulation().GetDeme(d).GetHeight(); c++) {
-          target_cell = m_world->GetPopulation().GetDeme(d).GetCellID(c); 
+                
+        if(m_world->GetPopulation().GetDeme(d).IsTreatableNow()) {
+        
+          for (int c = 0; c < m_world->GetPopulation().GetDeme(d).GetWidth() * m_world->GetPopulation().GetDeme(d).GetHeight(); c++) {
+            target_cell = m_world->GetPopulation().GetDeme(d).GetCellID(c); 
           
-          if( m_world->GetRandom().GetDouble() < m_pctkills) {
-            m_world->GetPopulation().KillOrganism(m_world->GetPopulation().GetCell(target_cell));
-            m_world->GetStats().IncNumOrgsKilled();
-          }
+            if(ctx.GetRandom().P(m_pctkills)) {
+              m_world->GetPopulation().KillOrganism(m_world->GetPopulation().GetCell(target_cell));
+              m_world->GetStats().IncNumOrgsKilled();
+            }
           
-        } //End iterating through all cells
+          } //End iterating through all cells
+           
+        } //End if deme is treatable
         
       } //End iterating through all demes
       
     } //End Process()
-  };
+};
 
+/*
+ Set the ages at which treatable demes can be treated
+ 
+ Parameters:
+ - 1+ age numbers at which a deme may be treated (int)
+ */
 
+class cActionSetDemeTreatmentAges : public cAction
+{
+private:
+  std::set<int> treatment_ages;
+public:
+  static const cString GetDescription() { return "Arguments: <int treatment age>+"; }
+  
+  cActionSetDemeTreatmentAges(cWorld* world, const cString& args) : cAction(world, args)
+  {
+    cString largs(args);
+    while (largs.GetSize()) {
+      treatment_ages.insert(largs.PopWord().AsInt());
+    }
+  }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    for (int d = 0; d < m_world->GetPopulation().GetNumDemes(); d++) {
+      cDeme& deme = m_world->GetPopulation().GetDeme(d);
+      
+      if(deme.isTreatable()) {
+        for (std::set<int>::iterator it = treatment_ages.begin(); it != treatment_ages.end(); it++) {
+          deme.AddTreatmentAge(*it);
+        }
+      }
+      
+    } //End iterating through demes
+    
+  } //End Process()
+  
+};
+
+
 void RegisterPopulationActions(cActionLibrary* action_lib)
 {
   action_lib->Register<cActionInject>("Inject");
@@ -3013,4 +3057,5 @@
   action_lib->Register<cActionDisconnectCells>("disconnect_cells");
   action_lib->Register<cActionSwapCells>("swap_cells");
   action_lib->Register<cActionKillDemePercent>("KillDemePercent");
+  action_lib->Register<cActionSetDemeTreatmentAges>("SetDemeTreatmentAges");
 }

Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc	2009-05-21 01:43:49 UTC (rev 3251)
+++ development/source/main/cDeme.cc	2009-05-21 15:26:24 UTC (rev 3252)
@@ -853,3 +853,18 @@
   //  assert(false); // slots must be of equal size and fit perfectally in deme lifetime
   return 0;
 }
+
+
+// Return whether or not this deme is treatable at the given age (updates).  If a deme is not treatable,
+// this function will always return false.
+bool cDeme::IsTreatableAtAge(const int age) {
+  
+  if(isTreatable()) {
+    set<int>::iterator it;
+    it = treatment_ages.find(age);
+    if(it != treatment_ages.end()) return true;  
+  }
+  
+  return false;
+  
+} //End cDeme::IsTreatableAtAge()

Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h	2009-05-21 01:43:49 UTC (rev 3251)
+++ development/source/main/cDeme.h	2009-05-21 15:26:24 UTC (rev 3252)
@@ -24,6 +24,7 @@
 #ifndef cDeme_h
 #define cDeme_h
 
+#include <set>
 #include <vector>
 
 #include "cDemeCellEvent.h"
@@ -59,6 +60,7 @@
 
 	bool replicateDeme;
 	bool treatable;
+  std::set<int> treatment_ages;
 	
 // The following should be moved to cDemePhenotype / cPopulationPhenotype
   int cur_birth_count; //!< Number of organisms that have been born into this deme since reset.
@@ -201,6 +203,9 @@
 	
 	bool isTreatable() const { return treatable; }
 	void setTreatable(bool value) { treatable = value; }
+  void AddTreatmentAge(const int age) { treatment_ages.insert(age); }
+  bool IsTreatableAtAge(const int age);
+  bool IsTreatableNow() { return IsTreatableAtAge(_age); }
 
   int GetSlotFlowRate() const;
   int GetEventsTotal() const { return eventsTotal; }




More information about the Avida-cvs mailing list