[Avida-SVN] r2930 - in development/source: analyze script

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Mon Nov 10 20:17:19 PST 2008


Author: brysonda
Date: 2008-11-10 23:17:18 -0500 (Mon, 10 Nov 2008)
New Revision: 2930

Modified:
   development/source/analyze/cGenotypeBatch.cc
   development/source/analyze/cGenotypeBatch.h
   development/source/script/ASAvidaLib.cc
Log:
Implement cGenotypeBatch Find/Pop Organism methods and a couple of pruning methods.

Modified: development/source/analyze/cGenotypeBatch.cc
===================================================================
--- development/source/analyze/cGenotypeBatch.cc	2008-11-10 15:24:05 UTC (rev 2929)
+++ development/source/analyze/cGenotypeBatch.cc	2008-11-11 04:17:18 UTC (rev 2930)
@@ -115,6 +115,36 @@
 }
 
 
+cAnalyzeGenotype* cGenotypeBatch::FindOrganismRandom(cRandom& rng) const
+{
+  if (m_list.GetSize() == 0) return NULL;
+  
+  int num_orgs = m_list.Count(&cAnalyzeGenotype::GetNumCPUs);
+  while (true) {
+    cAnalyzeGenotype* genotype = m_list.FindSummedValue(rng.GetUInt(num_orgs), &cAnalyzeGenotype::GetNumCPUs);
+    if (genotype->GetNumCPUs()) return new cAnalyzeGenotype(*genotype);
+  }
+  
+  return NULL;
+}
+
+cAnalyzeGenotype* cGenotypeBatch::PopOrganismRandom(cRandom& rng)
+{
+  if (m_list.GetSize() == 0) return NULL;
+
+  int num_orgs = m_list.Count(&cAnalyzeGenotype::GetNumCPUs);
+  while (true) {
+    cAnalyzeGenotype* genotype = m_list.FindSummedValue(rng.GetUInt(num_orgs), &cAnalyzeGenotype::GetNumCPUs);
+    if (genotype->GetNumCPUs()) {
+      genotype->SetNumCPUs(genotype->GetNumCPUs() - 1);
+      return new cAnalyzeGenotype(*genotype);
+    }
+  }
+  
+  return m_list.PopPos(rng.GetUInt(m_list.GetSize()));
+}
+
+
 cGenotypeBatch* cGenotypeBatch::FindLineage(cAnalyzeGenotype* end_genotype) const
 {
   if ((end_genotype)) return FindLineage(end_genotype->GetID());
@@ -218,3 +248,34 @@
   }
 }
 
+
+void cGenotypeBatch::PruneExtinctGenotypes()
+{
+  cAnalyzeGenotype* genotype = NULL;
+  tListIterator<cAnalyzeGenotype> it(m_list);
+  
+  while ((genotype = it.Next())) {
+    if (genotype->GetNumCPUs() == 0) {
+      it.Remove();
+      delete genotype;
+    }
+  }
+  
+  clearFlags();
+}
+
+void cGenotypeBatch::PruneNonViableGenotypes()
+{
+  cAnalyzeGenotype* genotype = NULL;
+  tListIterator<cAnalyzeGenotype> it(m_list);
+  
+  while ((genotype = it.Next())) {
+    if (!genotype->GetViable()) {
+      it.Remove();
+      delete genotype;
+    }
+  }
+  
+  clearFlags();
+}
+

Modified: development/source/analyze/cGenotypeBatch.h
===================================================================
--- development/source/analyze/cGenotypeBatch.h	2008-11-10 15:24:05 UTC (rev 2929)
+++ development/source/analyze/cGenotypeBatch.h	2008-11-11 04:17:18 UTC (rev 2930)
@@ -84,6 +84,11 @@
   inline cAnalyzeGenotype* FindGenotypeRandom(cRandom* rng) const { return FindGenotypeRandom(*rng); }
   inline cAnalyzeGenotype* PopGenotypeRandom(cRandom* rng) { return PopGenotypeRandom(*rng); }
   
+  cAnalyzeGenotype* FindOrganismRandom(cRandom& rng) const;
+  cAnalyzeGenotype* PopOrganismRandom(cRandom& rng);
+  inline cAnalyzeGenotype* FindOrganismRandom(cRandom* rng) const { return FindOrganismRandom(*rng); }
+  inline cAnalyzeGenotype* PopOrganismRandom(cRandom* rng) { return PopOrganismRandom(*rng); }
+  
   cGenotypeBatch* FindLineage(cAnalyzeGenotype* end_genotype) const;
   cGenotypeBatch* FindLineage(int end_genotype_id) const;
 
@@ -92,10 +97,13 @@
   
   void RemoveClade(cAnalyzeGenotype* start_genotype);
   void RemoveClade(int start_genotype_id);
+  
+  void PruneExtinctGenotypes();
+  void PruneNonViableGenotypes();
 
   
 private:
-  inline void clearFlags() { m_is_lineage = false; m_is_aligned = false; }
+  inline void clearFlags() { m_lineage_head = NULL; m_is_lineage = false; m_clade_head = NULL; m_is_aligned = false; }
 };
 
 

Modified: development/source/script/ASAvidaLib.cc
===================================================================
--- development/source/script/ASAvidaLib.cc	2008-11-10 15:24:05 UTC (rev 2929)
+++ development/source/script/ASAvidaLib.cc	2008-11-11 04:17:18 UTC (rev 2930)
@@ -79,9 +79,13 @@
   REGISTER_S_METHOD(cGenotypeBatch, "PopGenotypeID", PopGenotypeID, cAnalyzeGenotype* (int));
 //  REGISTER_C_METHOD(cGenotypeBatch, "FindGenotypeRandom", FindGenotypeRandom, cAnalyzeGenotype* (cRandom*));
 //  REGISTER_S_METHOD(cGenotypeBatch, "PopGenotypeRandom", PopGenotypeRandom, cAnalyzeGenotype* (cRandom*));
+//  REGISTER_C_METHOD(cGenotypeBatch, "FindOrganismRandom", FindOrganismRandom, cAnalyzeGenotype* (cRandom*));
+//  REGISTER_S_METHOD(cGenotypeBatch, "PopOrganismRandom", PopOrganismRandom, cAnalyzeGenotype* (cRandom*));
   REGISTER_C_METHOD(cGenotypeBatch, "FindLineage", FindLineage, cGenotypeBatch* (cAnalyzeGenotype*));
   REGISTER_C_METHOD(cGenotypeBatch, "FindClade", FindClade, cGenotypeBatch* (cAnalyzeGenotype*));
   REGISTER_S_METHOD(cGenotypeBatch, "RemoveClade", RemoveClade, void (cAnalyzeGenotype*));
+  REGISTER_S_METHOD(cGenotypeBatch, "PruneExtinctGenotypes", PruneExtinctGenotypes, void ());
+  REGISTER_S_METHOD(cGenotypeBatch, "PruneNonViableGenotypes", PruneNonViableGenotypes, void ());
   
 
   tASNativeObject<cResourceHistory>::InitializeMethodRegistrar();




More information about the Avida-cvs mailing list