[Avida-SVN] r3550 - branches/biounit/source/classification

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Wed Dec 9 10:49:46 PST 2009


Author: brysonda
Date: 2009-12-09 13:49:46 -0500 (Wed, 09 Dec 2009)
New Revision: 3550

Modified:
   branches/biounit/source/classification/cBGGenotype.cc
   branches/biounit/source/classification/cBGGenotypeManager.cc
   branches/biounit/source/classification/cBGGenotypeManager.h
Log:
cBGGenotypeManager coalescent and best handling.

Modified: branches/biounit/source/classification/cBGGenotype.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotype.cc	2009-12-08 20:50:09 UTC (rev 3549)
+++ branches/biounit/source/classification/cBGGenotype.cc	2009-12-09 18:49:46 UTC (rev 3550)
@@ -47,7 +47,6 @@
   if (parents) {
     m_parents.Resize(parents->GetSize());
     for (int i = 0; i < m_parents.GetSize(); i++) {
-      // @TODO - is there a better way to handle biogroup -> genotype transformation or a good way to eliminate the need?
       m_parents[i] = static_cast<cBGGenotype*>((*parents)[i]);
       m_parents[i]->AddPassiveReference();
     }

Modified: branches/biounit/source/classification/cBGGenotypeManager.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotypeManager.cc	2009-12-08 20:50:09 UTC (rev 3549)
+++ branches/biounit/source/classification/cBGGenotypeManager.cc	2009-12-09 18:49:46 UTC (rev 3550)
@@ -33,6 +33,8 @@
 
 cBGGenotypeManager::cBGGenotypeManager(cWorld* world)
   : m_world(world)
+  , m_coalescent(NULL)
+  , m_best(0)
   , m_next_id(1)
   , m_dom_prev(-1)
   , m_dom_time(0)
@@ -96,6 +98,10 @@
   // Remove from old size list
   m_active_sz[old_size].Remove(genotype);
 
+  if (old_size == m_best && m_active_sz[old_size].GetSize() == 0) {
+    for (m_best--; m_best > 0; m_best--) if (m_active_sz[m_best].GetSize()) break;
+  }
+  
   // Handle defunct genotypes
   if (new_size == 0 && genotype->GetActiveReferenceCount() == 0) {
     removeGenotype(genotype);
@@ -105,6 +111,7 @@
   // Add to new size list
   resizeActiveList(new_size);
   m_active_sz[new_size].Push(genotype);
+  if (new_size > m_best) m_best = new_size;
 }
 
 
@@ -154,7 +161,37 @@
   const tArray<cBGGenotype*>& parents = genotype->GetParents();
   for (int i = 0; i < parents.GetSize(); i++) {
     parents[i]->RemovePassiveReference();
-    // @TODO - update coalescent?
+    updateCoalescent();
     removeGenotype(parents[i]);
   }
+  
+  m_historic.Remove(genotype);
+  delete genotype;
 }
+
+void cBGGenotypeManager::updateCoalescent()
+{
+  if (m_coalescent && (m_coalescent->GetActiveReferenceCount() > 0 || m_coalescent->GetPassiveReferenceCount() > 1)) return;
+  
+  if (m_best == 0) {
+    m_coalescent = NULL;
+    // m_world->GetStats().SetCoalescentGenotypeDepth(-1);
+    return;
+  }
+  
+  // @TODO - assumes asexual population
+  cBGGenotype* test_gen = getBest();
+  cBGGenotype* found_gen = test_gen;
+  cBGGenotype* parent_gen = (found_gen->GetParents().GetSize()) ? found_gen->GetParents()[0] : NULL;
+
+  while (parent_gen != NULL) {
+    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;
+  }
+  
+  m_coalescent = found_gen;
+  // m_world->GetStats().SetCoalescentGenotypeDepth(m_coalescent->GetDepth());
+}
+

Modified: branches/biounit/source/classification/cBGGenotypeManager.h
===================================================================
--- branches/biounit/source/classification/cBGGenotypeManager.h	2009-12-08 20:50:09 UTC (rev 3549)
+++ branches/biounit/source/classification/cBGGenotypeManager.h	2009-12-09 18:49:46 UTC (rev 3550)
@@ -55,6 +55,8 @@
   tList<cBGGenotype> m_active_hash[nBGGenotypeManager::HASH_SIZE];
   tManagedPointerArray<tList<cBGGenotype> > m_active_sz;
   tList<cBGGenotype> m_historic;
+  cBGGenotype* m_coalescent;
+  int m_best;
   int m_next_id;
   int m_dom_prev;
   int m_dom_time;
@@ -78,8 +80,10 @@
   cString nameGenotype(int size, int num) const;
   
   void removeGenotype(cBGGenotype* genotype);
+  void updateCoalescent();  
   
   inline void resizeActiveList(int size);
+  inline cBGGenotype* getBest();
 };
 
 
@@ -88,4 +92,10 @@
   if (m_active_sz.GetSize() <= size) m_active_sz.Resize(size + 1);
 }
 
+inline cBGGenotype* cBGGenotypeManager::getBest()
+{
+  return (m_best) ? m_active_sz[m_best].GetLast() : NULL;
+}
+
+
 #endif




More information about the Avida-cvs mailing list