[Avida-cvs] [Avida2-svn] r149 - in trunk/source: main tools

kaben at myxo.css.msu.edu kaben at myxo.css.msu.edu
Fri Apr 15 03:58:36 PDT 2005


Author: kaben
Date: 2005-04-15 06:58:36 -0400 (Fri, 15 Apr 2005)
New Revision: 149

Modified:
   trunk/source/main/avida_driver_population.cc
   trunk/source/main/avida_driver_population.hh
   trunk/source/main/population.cc
   trunk/source/main/population.hh
   trunk/source/main/stats.cc
   trunk/source/tools/CMakeLists.txt
   trunk/source/tools/change_list.hh
   trunk/source/tools/const_schedule.cc
   trunk/source/tools/integrated_schedule.cc
   trunk/source/tools/prob_schedule.cc
Log:

* More fixes to tracking changed population cells.



Modified: trunk/source/main/avida_driver_population.cc
===================================================================
--- trunk/source/main/avida_driver_population.cc	2005-04-15 08:11:20 UTC (rev 148)
+++ trunk/source/main/avida_driver_population.cc	2005-04-15 10:58:36 UTC (rev 149)
@@ -34,7 +34,7 @@
 //  cAvidaDriver_Population
 /////////////////////////////
 
-cAvidaDriver_Population::cAvidaDriver_Population(cEnvironment & environment)
+cAvidaDriver_Population::cAvidaDriver_Population(cEnvironment & environment, cChangeList * change_list)
   : population(NULL)
   , event_manager(NULL)
   , event_list(NULL)
@@ -63,7 +63,7 @@
   default_interface.SetFun_InjectParasite(&cCallbackUtil::CB_InjectParasite);
   default_interface.SetFun_UpdateMerit(&cCallbackUtil::CB_UpdateMerit);
 
-  population = new cPopulation(default_interface, environment);
+  population = new cPopulation(default_interface, environment, change_list);
   cout << " ...done" << endl;
 
   //Setup Event List

Modified: trunk/source/main/avida_driver_population.hh
===================================================================
--- trunk/source/main/avida_driver_population.hh	2005-04-15 08:11:20 UTC (rev 148)
+++ trunk/source/main/avida_driver_population.hh	2005-04-15 10:58:36 UTC (rev 149)
@@ -19,6 +19,7 @@
 class cEventFactoryManager;
 class cEventList;
 class cString;
+class cChangeList;
 class cPopulation;
 
 class cAvidaDriver_Population : public cAvidaDriver_Base {
@@ -41,7 +42,7 @@
   void ReadEventListFile(const cString & filename="event_list");
   void SyncEventList();
 			
-  cAvidaDriver_Population(cEnvironment & environment);
+  cAvidaDriver_Population(cEnvironment & environment, cChangeList * change_list = 0);
   virtual ~cAvidaDriver_Population();
 
   virtual void Run();

Modified: trunk/source/main/population.cc
===================================================================
--- trunk/source/main/population.cc	2005-04-15 08:11:20 UTC (rev 148)
+++ trunk/source/main/population.cc	2005-04-15 10:58:36 UTC (rev 149)
@@ -45,7 +45,8 @@
 
 
 cPopulation::cPopulation(const cPopulationInterface & in_interface,
-			 cEnvironment & in_environment)
+			 cEnvironment & in_environment,
+			 cChangeList * change_list)
   : schedule(NULL)
   , resource_count(in_environment.GetResourceLib().GetSize())
   , environment(in_environment)
@@ -161,7 +162,7 @@
     }
   }
 
-  BuildTimeSlicer();
+  BuildTimeSlicer(change_list);
 
   if (SetupDemes() == false) {
     cerr << "Error -- failed to setup demes.  Exiting." << endl;
@@ -1794,7 +1795,7 @@
   resource_count.Set(id, new_level);
 }
 
-void cPopulation::BuildTimeSlicer()
+void cPopulation::BuildTimeSlicer(cChangeList * change_list)
 {
   switch (cConfig::GetSlicingMethod()) {
   case SLICE_CONSTANT:
@@ -1815,7 +1816,7 @@
     schedule = new cIntegratedSchedule(cell_array.GetSize());
     break;
   }
-
+  schedule->SetChangeList(change_list);
 }
 
 

Modified: trunk/source/main/population.hh
===================================================================
--- trunk/source/main/population.hh	2005-04-15 08:11:20 UTC (rev 148)
+++ trunk/source/main/population.hh	2005-04-15 10:58:36 UTC (rev 149)
@@ -85,7 +85,7 @@
   bool sync_events;   // Do we need to sync up the event list with population?
 
   ///////////////// Private Methods ////////////////////
-  void BuildTimeSlicer(); // Build the schedule object
+  void BuildTimeSlicer(cChangeList * change_list); // Build the schedule object
 
   // Methods to place offspring in the population.
   cPopulationCell & PositionChild(cPopulationCell & parent_cell,
@@ -120,7 +120,8 @@
 
 public:
   cPopulation(const cPopulationInterface & in_interface,
-	      cEnvironment & in_environment);
+	      cEnvironment & in_environment,
+	      cChangeList * change_list = 0);
   ~cPopulation();
 
   // Extra Setup...

Modified: trunk/source/main/stats.cc
===================================================================
--- trunk/source/main/stats.cc	2005-04-15 08:11:20 UTC (rev 148)
+++ trunk/source/main/stats.cc	2005-04-15 10:58:36 UTC (rev 149)
@@ -5,26 +5,15 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#ifndef STATS_HH
 #include "stats.hh"
-#endif
 
-#ifndef CONFIG_HH
 #include "config.hh"
-#endif
-#ifndef DATA_FILE_HH
 #include "data_file.hh"
-#endif
-#ifndef FUNCTIONS_HH
 #include "functions.hh"
-#endif
-#ifndef STRING_UTIL_HH
 #include "string_util.hh"
-#endif
-#ifndef TDATAENTRY_HH
 #include "tDataEntry.hh"
-#endif
 
+
 using namespace std;
 
 ////////////

Modified: trunk/source/tools/CMakeLists.txt
===================================================================
--- trunk/source/tools/CMakeLists.txt	2005-04-15 08:11:20 UTC (rev 148)
+++ trunk/source/tools/CMakeLists.txt	2005-04-15 10:58:36 UTC (rev 149)
@@ -1,5 +1,6 @@
 SET(libtools_a_SOURCES
   block_struct.cc
+  change_list.cc
   const_schedule.cc
   count_tracker.cc
   data_entry.cc

Modified: trunk/source/tools/change_list.hh
===================================================================
--- trunk/source/tools/change_list.hh	2005-04-15 08:11:20 UTC (rev 148)
+++ trunk/source/tools/change_list.hh	2005-04-15 10:58:36 UTC (rev 149)
@@ -25,32 +25,21 @@
   0 <= m_change_count <= size of m_change_tracking.
   */
   // Number of changes.
-  unsigned int m_change_count;
+  int m_change_count;
   /*
   List of changed indices. When n changes are listed, the first n
   entries of m_change_list store the indices, and the remaining entries
   are invalid.
   */
-  tArray<unsigned int> m_change_list;
+  tArray<int> m_change_list;
   // m_change_tracking[i] is true iff i is in m_change_list.
   tArray<bool> m_change_tracking;
 
 public:
-  void ResizeClear(unsigned int capacity){
-    m_change_list.ResizeClear(capacity);
-    m_change_tracking.ResizeClear(capacity);
-    m_change_list.SetAll(0);
-    m_change_tracking.SetAll(false);
-    m_change_count = 0;
-  }
+  void ResizeClear(int capacity);
 
-public:
   // Constructor.
-  explicit cChangeList(unsigned int capacity = 0)
-  : m_change_list(0)
-  , m_change_tracking(0)
-  , m_change_count(0)
-  { ResizeClear(capacity); }
+  explicit cChangeList(int capacity = 0);
 
   //// Assignment operator.
   //cChangeList & operator= (const cChangeList & rhs) {
@@ -69,53 +58,27 @@
 
   // Interface Methods ///////////////////////////////////////////////////////
 
-  unsigned int GetSize() const { return m_change_list.GetSize(); }
+  int GetSize() const;
 
-  unsigned int GetChangeCount() const { return m_change_count; }
+  int GetChangeCount() const;
 
   // Note that decreasing size invalidates stored changes.
-  void Resize(unsigned int capacity) {
-    if (capacity < m_change_list.GetSize()){
-      ResizeClear(capacity);
-    } else {
-      m_change_list.Resize(capacity);
-      m_change_tracking.Resize(capacity, false);
-    }
-  }
+  void Resize(int capacity);
   
   // Unsafe version : assumes index is within change count.
-  unsigned int GetChangeAt(unsigned int index) const {
-    return m_change_list[index];
-  }
+  int GetChangeAt(int index) const;
 
   // Safe version : returns -1 if index is outside change count.
-  int CheckChangeAt(unsigned int index) const {
-    return (index < m_change_count) ? ((int) GetChangeAt(index)) : (-1);
-  }
+  int CheckChangeAt(int index) const;
 
   // Unsafe version : assumes changed_index is within capacity.
-  void MarkChange(unsigned int changed_index) {
-    if (!m_change_tracking[changed_index]) {
-      m_change_tracking[changed_index] = true;
-      m_change_list[m_change_count++] = changed_index;
-    }
-  }
+  void MarkChange(int changed_index);
 
   // Safe version : will resize to accommodate changed_index greater
   // than capacity.
-  void PushChange(unsigned int changed_index) {
-    if (m_change_list.GetSize() <= changed_index) {
-      Resize(changed_index + 1);
-    }
-    MarkChange(changed_index);
-  }
+  void PushChange(int changed_index);
 
-  void Reset() {
-    for (unsigned int i = 0; i < m_change_count; i++) {
-      m_change_tracking[m_change_list[i]] = false;
-    }
-    m_change_count = 0;
-  }
+  void Reset();
 };
 
 #endif

Modified: trunk/source/tools/const_schedule.cc
===================================================================
--- trunk/source/tools/const_schedule.cc	2005-04-15 08:11:20 UTC (rev 148)
+++ trunk/source/tools/const_schedule.cc	2005-04-15 10:58:36 UTC (rev 149)
@@ -34,11 +34,11 @@
 
 void cConstSchedule::Adjust(int item_id, const cMerit & merit)
 {
-  if (merit == 0.0) is_active[item_id] = false;
-  else is_active[item_id] = true;
   if (cChangeList *change_list = GetChangeList()) {
     change_list->MarkChange(item_id);
   }
+  if (merit == 0.0) is_active[item_id] = false;
+  else is_active[item_id] = true;
 }
 
 

Modified: trunk/source/tools/integrated_schedule.cc
===================================================================
--- trunk/source/tools/integrated_schedule.cc	2005-04-15 08:11:20 UTC (rev 148)
+++ trunk/source/tools/integrated_schedule.cc	2005-04-15 10:58:36 UTC (rev 149)
@@ -12,7 +12,10 @@
 #include "integrated_schedule_node.hh"
 #include "merit.hh"
 
+#include <iostream>
+using namespace std;
 
+
 /////////////////////////
 //  cIntegratedSchedule
 /////////////////////////
@@ -60,6 +63,9 @@
 
 void cIntegratedSchedule::Adjust(int item_id, const cMerit & new_merit)
 {
+  if (cChangeList *change_list = GetChangeList()) {
+    change_list->MarkChange(item_id);
+  }
   // Grab the old_merit, the new merit, and compare them.
   const cMerit old_merit = merit_chart[item_id];
 
@@ -87,9 +93,6 @@
       node_array[i]->Insert(item_id);
     }
   }
-  if (cChangeList *change_list = GetChangeList()) {
-    change_list->MarkChange(item_id);
-  }
 }
 
 

Modified: trunk/source/tools/prob_schedule.cc
===================================================================
--- trunk/source/tools/prob_schedule.cc	2005-04-15 08:11:20 UTC (rev 148)
+++ trunk/source/tools/prob_schedule.cc	2005-04-15 10:58:36 UTC (rev 149)
@@ -38,8 +38,8 @@
 
 void cProbSchedule::Adjust(int item_id, const cMerit & item_merit)
 {
-  chart.SetWeight(item_id, item_merit.GetDouble());
   if (cChangeList *change_list = GetChangeList()) {
     change_list->MarkChange(item_id);
   }
+  chart.SetWeight(item_id, item_merit.GetDouble());
 }




More information about the Avida-cvs mailing list