[Avida-SVN] r3552 - in branches/biounit/source: classification main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Fri Dec 11 11:55:59 PST 2009


Author: brysonda
Date: 2009-12-11 14:55:58 -0500 (Fri, 11 Dec 2009)
New Revision: 3552

Modified:
   branches/biounit/source/classification/cBGGenotype.cc
   branches/biounit/source/classification/cBGGenotype.h
   branches/biounit/source/classification/cBGGenotypeManager.cc
   branches/biounit/source/classification/cBGGenotypeManager.h
   branches/biounit/source/classification/cBioGroup.h
   branches/biounit/source/classification/cBioUnit.cc
   branches/biounit/source/classification/cBioUnit.h
   branches/biounit/source/main/cPopulation.cc
Log:
Active and passive reference counting fixes.  Size parameter passing to adjustGenotype fixes.

Modified: branches/biounit/source/classification/cBGGenotype.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotype.cc	2009-12-09 20:00:41 UTC (rev 3551)
+++ branches/biounit/source/classification/cBGGenotype.cc	2009-12-11 19:55:58 UTC (rev 3552)
@@ -26,6 +26,7 @@
 
 #include "cBGGenotypeManager.h"
 #include "cDataFile.h"
+#include "cPhenotype.h"
 #include "cStringUtil.h"
 
 
@@ -46,6 +47,7 @@
   , m_last_num_organisms(0)
   , m_total_organisms(1)
 {
+  AddActiveReference();
   if (parents) {
     m_parents.Resize(parents->GetSize());
     for (int i = 0; i < m_parents.GetSize(); i++) {
@@ -58,7 +60,6 @@
 
 cBGGenotype::~cBGGenotype()
 {
-  for (int i = 0; i < m_parents.GetSize(); i++) m_parents[i]->RemovePassiveReference();
 }
 
 int cBGGenotype::GetRoleID() const
@@ -80,7 +81,8 @@
   if (Matches(bu)) {
     m_breed_true.Inc();
     m_total_organisms++;
-    m_mgr->AdjustGenotype(this, m_num_organisms++, m_num_organisms);
+    m_num_organisms++;
+    m_mgr->AdjustGenotype(this, m_num_organisms - 1, m_num_organisms);
     AddActiveReference();
     return this;
   }  
@@ -89,12 +91,24 @@
   return m_mgr->ClassifyNewBioUnit(bu, parents);
 }
 
+void cBGGenotype::HandleBioUnitGestation(cBioUnit* bu)
+{
+  const cPhenotype& phenotype = bu->GetPhenotype();
+  
+  m_copied_size.Add(phenotype.GetCopiedSize());
+  m_exe_size.Add(phenotype.GetExecutedSize());
+  m_gestation_time.Add(phenotype.GetGestationTime());
+  m_merit.Add(phenotype.GetMerit().GetDouble());
+  m_fitness.Add(phenotype.GetFitness());
+}
 
+
 void cBGGenotype::RemoveBioUnit(cBioUnit* bu)
 {
   m_deaths.Inc();
   RemoveActiveReference();
-  m_mgr->AdjustGenotype(this, m_num_organisms--, m_num_organisms);  
+  m_num_organisms--;
+  m_mgr->AdjustGenotype(this, m_num_organisms + 1, m_num_organisms);
 }
 
 

Modified: branches/biounit/source/classification/cBGGenotype.h
===================================================================
--- branches/biounit/source/classification/cBGGenotype.h	2009-12-09 20:00:41 UTC (rev 3551)
+++ branches/biounit/source/classification/cBGGenotype.h	2009-12-11 19:55:58 UTC (rev 3552)
@@ -81,7 +81,6 @@
   cDoubleSum m_copied_size;
   cDoubleSum m_exe_size;
   cDoubleSum m_gestation_time;
-  cDoubleSum m_repro_rate;
   cDoubleSum m_merit;
   cDoubleSum m_fitness;
     
@@ -97,6 +96,7 @@
   int GetID() const { return m_id; }
   
   cBioGroup* ClassifyNewBioUnit(cBioUnit* bu, tArray<cBioGroup*>* parents = NULL);
+  void HandleBioUnitGestation(cBioUnit* bu);
   void RemoveBioUnit(cBioUnit* bu);
   
   int GetDepth() const { return m_depth; }
@@ -122,12 +122,12 @@
   void SetThreshold() { m_threshold = true; }
   void ClearThreshold() { m_threshold = false; }
   
-  void Deactivate() { m_active = false; }
+  void Deactivate(int update) { m_active = false; m_update_deactivated = update; }
   
   inline const tArray<cBGGenotype*> GetParents() const { return m_parents; }
 
   bool Matches(cBioUnit* bu);
-  inline void NotifyNewBioUnit(cBioUnit* bu) { m_total_organisms++; m_num_organisms++; m_breed_in.Inc(); }
+  inline void NotifyNewBioUnit(cBioUnit* bu) { m_total_organisms++; m_num_organisms++; m_breed_in.Inc(); AddActiveReference(); }
   void UpdateReset();
 };
 

Modified: branches/biounit/source/classification/cBGGenotypeManager.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotypeManager.cc	2009-12-09 20:00:41 UTC (rev 3551)
+++ branches/biounit/source/classification/cBGGenotypeManager.cc	2009-12-11 19:55:58 UTC (rev 3552)
@@ -40,7 +40,6 @@
   , m_dom_prev(-1)
   , m_dom_time(0)
 {
-  for (int i = 0; i < MAX_CREATURE_SIZE; i++) m_sz_count[i] = 0;
 }
 
 cBGGenotypeManager::~cBGGenotypeManager()
@@ -78,7 +77,10 @@
   //         cPopulation do the work.
   
   tListIterator<cBGGenotype> list_it(m_historic);
-  while (list_it.Next() != NULL) list_it.Get()->Save(df);
+  while (list_it.Next() != NULL) {
+    list_it.Get()->Save(df);
+    df.Endl();
+  }
 }
 
 
@@ -161,7 +163,7 @@
   if (genotype->IsActive()) {
     int list_num = hashGenome(genotype->GetMetaGenome().GetGenome());
     m_active_hash[list_num].Remove(genotype);
-    genotype->Deactivate();
+    genotype->Deactivate(m_world->GetStats().GetUpdate());
     m_historic.Push(genotype);
   }
   
@@ -203,7 +205,7 @@
     if (test_gen->GetActiveReferenceCount() > 0 || test_gen->GetPassiveReferenceCount() > 1) found_gen = test_gen;
     
     test_gen = parent_gen;
-    parent_gen = (found_gen->GetParents().GetSize()) ? found_gen->GetParents()[0] : NULL;
+    parent_gen = (test_gen->GetParents().GetSize()) ? test_gen->GetParents()[0] : NULL;
   }
   
   m_coalescent = found_gen;

Modified: branches/biounit/source/classification/cBGGenotypeManager.h
===================================================================
--- branches/biounit/source/classification/cBGGenotypeManager.h	2009-12-09 20:00:41 UTC (rev 3551)
+++ branches/biounit/source/classification/cBGGenotypeManager.h	2009-12-11 19:55:58 UTC (rev 3552)
@@ -51,7 +51,6 @@
 private:
   cWorld* m_world;
 
-  unsigned int m_sz_count[MAX_CREATURE_SIZE];
   tList<cBGGenotype> m_active_hash[nBGGenotypeManager::HASH_SIZE];
   tManagedPointerArray<tList<cBGGenotype> > m_active_sz;
   tList<cBGGenotype> m_historic;

Modified: branches/biounit/source/classification/cBioGroup.h
===================================================================
--- branches/biounit/source/classification/cBioGroup.h	2009-12-09 20:00:41 UTC (rev 3551)
+++ branches/biounit/source/classification/cBioGroup.h	2009-12-11 19:55:58 UTC (rev 3552)
@@ -51,6 +51,7 @@
   virtual int GetID() const = 0;
   
   virtual cBioGroup* ClassifyNewBioUnit(cBioUnit* bu, tArray<cBioGroup*>* parents = NULL) = 0;
+  virtual void HandleBioUnitGestation(cBioUnit* bu) = 0;
   virtual void RemoveBioUnit(cBioUnit* bu) = 0;
   
   virtual int GetDepth() const = 0;
@@ -60,11 +61,11 @@
   
   int GetReferenceCount() const { return m_a_refs + m_p_refs; }
   int GetActiveReferenceCount() const { return m_a_refs; }
-  void AddActiveReference() { m_a_refs++; }
-  void RemoveActiveReference() { m_a_refs--; }
+  void AddActiveReference() { m_a_refs++; assert(m_a_refs >= 0); }
+  void RemoveActiveReference() { m_a_refs--; assert(m_a_refs >= 0); }
   int GetPassiveReferenceCount() const { return m_p_refs; }
-  void AddPassiveReference() { m_p_refs++; }
-  void RemovePassiveReference() { m_p_refs--; }
+  void AddPassiveReference() { m_p_refs++; assert(m_p_refs >= 0); }
+  void RemovePassiveReference() { m_p_refs--; assert(m_p_refs >= 0); }
 };
 
 #endif

Modified: branches/biounit/source/classification/cBioUnit.cc
===================================================================
--- branches/biounit/source/classification/cBioUnit.cc	2009-12-09 20:00:41 UTC (rev 3551)
+++ branches/biounit/source/classification/cBioUnit.cc	2009-12-11 19:55:58 UTC (rev 3552)
@@ -80,3 +80,8 @@
     }
   }
 }
+
+void cBioUnit::HandleGestation()
+{
+  for (int i = 0; i < m_bio_groups.GetSize(); i++) m_bio_groups[i]->HandleBioUnitGestation(this);
+}

Modified: branches/biounit/source/classification/cBioUnit.h
===================================================================
--- branches/biounit/source/classification/cBioUnit.h	2009-12-09 20:00:41 UTC (rev 3551)
+++ branches/biounit/source/classification/cBioUnit.h	2009-12-11 19:55:58 UTC (rev 3552)
@@ -34,6 +34,7 @@
 
 class cBioGroup;
 class cMetaGenome;
+class cPhenotype;
 class cString;
 
 
@@ -50,12 +51,15 @@
   virtual eBioUnitSource GetUnitSource() const = 0;
   virtual const cString& GetUnitSourceArgs() const = 0;
   virtual const cMetaGenome& GetMetaGenome() const = 0;
+  virtual const cPhenotype& GetPhenotype() const = 0;
   
   const tArray<cBioGroup*>& GetBioGroups() const { return m_bio_groups; }
   cBioGroup* GetBioGroup(const cString& role) const;
   
   void AddClassification(cBioGroup* bg) { m_bio_groups.Push(bg); }
   void SelfClassify(const tArray<const tArray<cBioGroup*>*>& parents);
+  
+  void HandleGestation();
 };
 
 #endif

Modified: branches/biounit/source/main/cPopulation.cc
===================================================================
--- branches/biounit/source/main/cPopulation.cc	2009-12-09 20:00:41 UTC (rev 3551)
+++ branches/biounit/source/main/cPopulation.cc	2009-12-11 19:55:58 UTC (rev 3552)
@@ -498,6 +498,7 @@
 	}
   
   // Do any statistics on the parent that just gave birth...
+  parent_organism->HandleGestation();
   parent_genotype->AddGestationTime( parent_phenotype.GetGestationTime() );
   parent_genotype->AddFitness(       parent_phenotype.GetFitness()       );
   parent_genotype->AddMerit(         parent_phenotype.GetMerit()         );




More information about the Avida-cvs mailing list