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

connel42 at myxo.css.msu.edu connel42 at myxo.css.msu.edu
Mon Dec 21 12:54:35 PST 2009


Author: connel42
Date: 2009-12-21 15:54:35 -0500 (Mon, 21 Dec 2009)
New Revision: 3573

Modified:
   development/source/actions/PopulationActions.cc
   development/source/main/avida.cc
   development/source/main/cStats.cc
   development/source/main/cStats.h
Log:
Changed some stats associated to organism kill events.  Removed unmaintained organism kill event (above threshold).  Added myself to the developer list.

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2009-12-21 20:41:18 UTC (rev 3572)
+++ development/source/actions/PopulationActions.cc	2009-12-21 20:54:35 UTC (rev 3573)
@@ -3933,80 +3933,35 @@
       
       assert(res_id != -1);
       
+      long cells_scanned = 0;
+      long orgs_killed = 0;
+      long cells_empty = 0;
+      
       for(int i=0; i < m_numkills; i++) {
         target_cell = m_world->GetRandom().GetInt(0, m_world->GetPopulation().GetSize()-1);
         level = m_world->GetPopulation().GetResourceCount().GetSpatialResource(res_id).GetAmount(target_cell);
+        cells_scanned++;
         
         if(level < m_threshold) {
           cPopulationCell& cell = pop.GetCell(target_cell);
           if (cell.IsOccupied()) {
             pop.KillOrganism(cell);
-            m_world->GetStats().IncNumOrgsKilled();
+            orgs_killed++;
           } else {
-            m_world->GetStats().IncNumUnoccupiedCellAttemptedToKill();
+            cells_empty++;
           }
         }
       }
       
-    } //End Process()
-  };
-
-
-/*
- Kill organisms in N randomly-chosen cells if the level of the given resource
- in the chosen cell is above the configured threshold
- 
- Parameters:
- - The number of cells to kill (default: 0)
- - The name of the resource
- - The amount of resource above which to execute the kill (default: 0)
- */
-
-class cActionKillNAboveResourceThreshold : public cAction
-  {
-  private:
-    cString m_resname;
-    int m_numkills;
-    double m_threshold;
-  public:
-    cActionKillNAboveResourceThreshold(cWorld* world, const cString& args) : cAction(world, args), m_numkills(0), m_threshold(0)
-    {
-      cString largs(args);
-      if (largs.GetSize()) m_numkills = largs.PopWord().AsInt();
-      if (largs.GetSize()) m_resname = largs.PopWord();
-      if (largs.GetSize()) m_threshold = largs.PopWord().AsDouble();
-    }
-    
-    static const cString GetDescription() { return "Arguments: [int numkills=0, string resource name, double threshold=0]"; }
-    
-    void Process(cAvidaContext& ctx)
-    {
-      double level;
-      int target_cell;
-      cPopulation& pop = m_world->GetPopulation();
-      int res_id = m_world->GetPopulation().GetResourceCount().GetResourceCountID(m_resname);
+      m_world->GetStats().AddNumCellsScannedAtKill(cells_scanned);
+      m_world->GetStats().AddNumOrgsKilled(orgs_killed);
+      m_world->GetStats().AddNumUnoccupiedCellAttemptedToKill(cells_empty);
       
-      assert(res_id != -1);
-      
-      for(int i=0; i < m_numkills; i++) {
-        target_cell = m_world->GetRandom().GetInt(0, pop.GetSize()-1);
-        level = pop.GetResourceCount().GetSpatialResource(res_id).GetAmount(target_cell);
-        
-        if(level > m_threshold) {
-          cPopulationCell& cell = pop.GetCell(target_cell);
-          if (cell.IsOccupied()) {
-            pop.KillOrganism(cell);
-            m_world->GetStats().IncNumOrgsKilled();
-          } else {
-            m_world->GetStats().IncNumUnoccupiedCellAttemptedToKill();
-          }
-        }
-      }
-      
     } //End Process()
   };
 
 
+
 /*
  Kill all organisms within a given radius of a randomly-chosen cell if the level
  of the given resource in the chosen cell is below the given threshold.  Currently
@@ -4061,6 +4016,10 @@
       
       assert(res_id != -1);
       
+      long cells_scanned = 0;
+      long orgs_killed = 0;
+      long cells_empty = 0;
+      
       for (int i = 0; i < m_numradii; i++) {
 
         int target_cell = m_world->GetRandom().GetInt(0, pop.GetSize()-1);
@@ -4077,6 +4036,7 @@
             for(int col = current_col - m_radius; col <= current_col + m_radius; col++) {
               if( ((col < 0) || (col >= world_x)) && (geometry == nGeometry::GRID) ) continue;
               
+              cells_scanned++;
               int row_adj = 0;
               int col_adj = 0;
 
@@ -4090,22 +4050,25 @@
               
               int current_cell = (world_x * row_adj) + col_adj;
 							cPopulationCell& cell = pop.GetCell(current_cell);
-              m_world->GetStats().IncNumCellsScannedAtKill();
 
 							if( (cell.IsOccupied()) && (ctx.GetRandom().P(m_kill_density)) ) {
 								pop.KillOrganism(cell);
-								m_world->GetStats().IncNumOrgsKilled();
+								orgs_killed++;
 							} else {
-								m_world->GetStats().IncNumUnoccupiedCellAttemptedToKill();
+								cells_empty++;
 							}
 
             }
           }
           
         }  // End if level at cell is below threshold
-        
+                
       } //End iterating through kill zones
       
+      m_world->GetStats().AddNumCellsScannedAtKill(cells_scanned);
+      m_world->GetStats().AddNumOrgsKilled(orgs_killed);
+      m_world->GetStats().AddNumUnoccupiedCellAttemptedToKill(cells_empty);
+      
     } //End Process()
   };
 
@@ -4166,6 +4129,10 @@
       
       assert(res_id != -1);
       
+      long cells_scanned = 0;
+      long orgs_killed = 0;
+      long cells_empty = 0;
+      
       for (int i = 0; i < m_numradii; i++) {
         
         int target_cell = m_world->GetRandom().GetInt(0, pop.GetSize()-1);
@@ -4218,13 +4185,13 @@
               
               int current_cell = (world_x * row_adj) + col_adj;
               cPopulationCell& cell = pop.GetCell(current_cell);
-              m_world->GetStats().IncNumCellsScannedAtKill();
+              cells_scanned++;
               
               if( (cell.IsOccupied())  && (ctx.GetRandom().P(m_kill_density)) ) {
                 pop.KillOrganism(cell);
-                m_world->GetStats().IncNumOrgsKilled();
+                orgs_killed++;
               } else {
-                m_world->GetStats().IncNumUnoccupiedCellAttemptedToKill();
+                cells_empty++;
               }
               
             }
@@ -4234,7 +4201,9 @@
         
       } //End iterating through kill zones
 
-        
+      m_world->GetStats().AddNumCellsScannedAtKill(cells_scanned);
+      m_world->GetStats().AddNumOrgsKilled(orgs_killed);
+      m_world->GetStats().AddNumUnoccupiedCellAttemptedToKill(cells_empty);
       
     } //End Process()
   };
@@ -4292,6 +4261,10 @@
 		int res_id = m_world->GetPopulation().GetResourceCount().GetResourceCountID(m_resname);
 		
 		assert(res_id != -1);
+    
+    long cells_scanned = 0;
+    long orgs_killed = 0;
+    long cells_empty = 0;
 		
 		for (int i = 0; i < m_numradii; i++) {
 			
@@ -4319,21 +4292,26 @@
 					
 					int current_cell = (world_x * row_adj) + col_adj;
 					cPopulationCell& cell = pop.GetCell(current_cell);
-					m_world->GetStats().IncNumCellsScannedAtKill();
+					cells_scanned++;
 					
 					double level = pop.GetResourceCount().GetSpatialResource(res_id).GetAmount(current_cell);
 					
 					if(level < m_threshold) {
 						if( (cell.IsOccupied()) && (ctx.GetRandom().P(m_kill_density)) ) {
 							pop.KillOrganism(cell);
-							m_world->GetStats().IncNumOrgsKilled();
+							orgs_killed++;
 						} else {
-							m_world->GetStats().IncNumUnoccupiedCellAttemptedToKill();
+							cells_empty++;
 						}
 					}
 				}
 			}
 		}
+    
+    m_world->GetStats().AddNumCellsScannedAtKill(cells_scanned);
+    m_world->GetStats().AddNumOrgsKilled(orgs_killed);
+    m_world->GetStats().AddNumUnoccupiedCellAttemptedToKill(cells_empty);
+    
 	}
 };
 
@@ -4365,19 +4343,28 @@
       int target_cell;
       cPopulation& pop = m_world->GetPopulation();
       
+      long cells_scanned = 0;
+      long orgs_killed = 0;
+      long cells_empty = 0;
+      
       for (int d = 0; d < pop.GetNumDemes(); d++) {
         
         cDeme &deme = pop.GetDeme(d);
                 
         if(deme.IsTreatableNow()) {
-        
           for (int c = 0; c < deme.GetWidth() * deme.GetHeight(); c++) {
+            cells_scanned++;
             target_cell = deme.GetCellID(c); 
+            cPopulationCell& cell = pop.GetCell(target_cell);
           
             if(ctx.GetRandom().P(m_pctkills)) {
-              pop.KillOrganism(pop.GetCell(target_cell));
-              m_world->GetStats().IncNumOrgsKilled();
-            }
+              if(cell.IsOccupied()) {
+                pop.KillOrganism(pop.GetCell(target_cell));
+                orgs_killed++;
+              } else {
+                cells_empty++; 
+              }
+            }      
           
           } //End iterating through all cells
            
@@ -4385,6 +4372,10 @@
         
       } //End iterating through all demes
       
+      m_world->GetStats().AddNumCellsScannedAtKill(cells_scanned);
+      m_world->GetStats().AddNumOrgsKilled(orgs_killed);
+      m_world->GetStats().AddNumUnoccupiedCellAttemptedToKill(cells_empty);
+      
     } //End Process()
 };
 
@@ -4648,7 +4639,6 @@
 	action_lib->Register<cActionPred_DemeResourceThresholdPredicate>("DemeResourceThresholdPredicate");
   
   action_lib->Register<cActionKillNBelowResourceThreshold>("KillNBelowResourceThreshold");
-  action_lib->Register<cActionKillNAboveResourceThreshold>("KillNAboveResourceThreshold");
   action_lib->Register<cActionKillWithinRadiusBelowResourceThreshold>("KillWithinRadiusBelowResourceThreshold");
   action_lib->Register<cActionKillWithinRadiusMeanBelowResourceThreshold>("KillWithinRadiusMeanBelowResourceThreshold");
 	action_lib->Register<cActionKillWithinRadiusBelowResourceThresholdTestAll>("KillWithinRadiusBelowResourceThresholdTestAll");

Modified: development/source/main/avida.cc
===================================================================
--- development/source/main/avida.cc	2009-12-21 20:41:18 UTC (rev 3572)
+++ development/source/main/avida.cc	2009-12-21 20:54:35 UTC (rev 3573)
@@ -110,8 +110,8 @@
   cout << "Lead Developers: David M. Bryson (Avida) and Kaben Nanlohy (Avida-ED)" << endl << endl;
 
   cout << "Active contributors include:  Christoph Adami, Brian Baer, Jeffrey Barrick," << endl
-       << "Benjamin Beckmann, Jeffrey Clune, Art Covert, Santiago Elena, Sherri Goings," << endl
-       << "Heather Goldsby, David Knoester, Richard Lenski, Philip McKinley," << endl
+       << "Benjamin Beckmann, Jeffrey Clune, Brian Connelly, Art Covert, Santiago Elena," << endl
+       << "Sherri Goings, Heather Goldsby, David Knoester, Richard Lenski, Philip McKinley," << endl
        << "Dusan Misevic, Elizabeth Ostrowski, Robert Pennock, Matthew Rupp, Eric Torng," << endl
        << "Michael Vo, Bess Walker, and Gabriel Yedid" << endl << endl;
 

Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc	2009-12-21 20:41:18 UTC (rev 3572)
+++ development/source/main/cStats.cc	2009-12-21 20:54:35 UTC (rev 3573)
@@ -134,9 +134,6 @@
   , m_spec_total(0)
   , m_spec_num(0)
   , m_spec_waste(0)
-  , num_orgs_killed(0)
-	, num_unoccupied_cell_kill_attempts(0)
-  , num_cells_scanned_at_kill(0)
   , num_migrations(0)
   , m_deme_num_repls(0)
 	, m_deme_num_repls_treatable(0)
@@ -580,9 +577,6 @@
   m_spec_num = 0;
   m_spec_waste = 0;
   
-  num_orgs_killed = 0;
-	num_unoccupied_cell_kill_attempts = 0;
-  num_cells_scanned_at_kill = 0;
   num_migrations = 0;
 }
 
@@ -2483,10 +2477,14 @@
   df.WriteComment("First column is the current update and the second column lists the number of organisms killed");
   
   df.Write(m_update,   "Update");
-  df.Write(num_orgs_killed, "Num Orgs Killed");
-  df.Write(num_unoccupied_cell_kill_attempts, "Num Unoccupied Cell Kill Attempts");
-  df.Write(num_cells_scanned_at_kill, "Num Cells Scanned By Kill Event");
+  df.Write(sum_orgs_killed.Average(), "Avg Num Orgs Killed");
+  df.Write(sum_unoccupied_cell_kill_attempts.Average(), "Avg Num Unoccupied Cell Kill Attempts");
+  df.Write(sum_cells_scanned_at_kill.Average(), "Avg Num Cells Scanned By Kill Event");
   df.Endl();
+    
+  sum_orgs_killed.Clear();
+  sum_unoccupied_cell_kill_attempts.Clear();
+  sum_cells_scanned_at_kill.Clear();
 } //End PrintNumOrgsKilledData()
 
 void cStats::PrintMigrationData(const cString& filename)

Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h	2009-12-21 20:41:18 UTC (rev 3572)
+++ development/source/main/cStats.h	2009-12-21 20:54:35 UTC (rev 3573)
@@ -341,9 +341,9 @@
   int m_spec_waste;
   
   // Number of organisms killed by kill actions
-  int num_orgs_killed;
-	int num_unoccupied_cell_kill_attempts;
-  int num_cells_scanned_at_kill;
+  cIntSum sum_orgs_killed;
+  cIntSum sum_unoccupied_cell_kill_attempts;
+  cIntSum sum_cells_scanned_at_kill;
   
   // Number of migrations that have been made
   int num_migrations;
@@ -576,9 +576,9 @@
 				
   void IncExecuted() { num_executed++; }
   
-  void IncNumOrgsKilled() { num_orgs_killed++; }
-	void IncNumUnoccupiedCellAttemptedToKill() { num_unoccupied_cell_kill_attempts++; }
-  void IncNumCellsScannedAtKill() { num_cells_scanned_at_kill++; }
+  void AddNumOrgsKilled(long num) { sum_orgs_killed.Add(num); }
+	void AddNumUnoccupiedCellAttemptedToKill(long num) { sum_unoccupied_cell_kill_attempts.Add(num); }
+  void AddNumCellsScannedAtKill(long num) { sum_cells_scanned_at_kill.Add(num); }
   void IncNumMigrations() { num_migrations++; }
 
   void AddCurTask(int task_num) { task_cur_count[task_num]++; }
@@ -754,8 +754,8 @@
   double GetAveSpeculative() const { return (m_spec_num) ? ((double)m_spec_total / (double)m_spec_num) : 0.0; }
   int GetSpeculativeWaste() const { return m_spec_waste; }
   
-  int GetNumOrgsKilled() const { return num_orgs_killed; }
-  int GetNumCellsScannedAtKill() const { return num_cells_scanned_at_kill; }
+  double GetAvgNumOrgsKilled() const { return sum_orgs_killed.Average(); }
+  double GetAvgNumCellsScannedAtKill() const { return sum_cells_scanned_at_kill.Average(); }
   int GetNumMigrations() const { return num_migrations; }
 
   // this value gets recorded when a creature with the particular




More information about the Avida-cvs mailing list