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

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Fri Nov 13 13:42:51 PST 2009


Author: brysonda
Date: 2009-11-13 16:42:51 -0500 (Fri, 13 Nov 2009)
New Revision: 3529

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/cBioUnit.h
   branches/biounit/source/main/cOrganism.cc
   branches/biounit/source/main/cOrganism.h
Log:
More work on biounit.  Implemented adjust in cBGGenotypeManager.  Start adding cBioUnit interface to cOrganism;

Modified: branches/biounit/source/classification/cBGGenotype.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotype.cc	2009-11-12 21:15:32 UTC (rev 3528)
+++ branches/biounit/source/classification/cBGGenotype.cc	2009-11-13 21:42:51 UTC (rev 3529)
@@ -66,8 +66,7 @@
   if (Matches(bu)) {
     m_breed_true.Inc();
     m_total_organisms++;
-    m_num_organisms++;
-    // @TODO - adjust genotype
+    m_mgr->AdjustGenotype(this, m_num_organisms++, m_num_organisms);
     
     return this;
   }  
@@ -80,8 +79,7 @@
 void cBGGenotype::RemoveBioUnit(cBioUnit* bu)
 {
   m_deaths.Inc();
-  m_num_organisms--;
-  // @TODO - adjust genotype
+  m_mgr->AdjustGenotype(this, m_num_organisms--, m_num_organisms);
 }
 
 

Modified: branches/biounit/source/classification/cBGGenotype.h
===================================================================
--- branches/biounit/source/classification/cBGGenotype.h	2009-11-12 21:15:32 UTC (rev 3528)
+++ branches/biounit/source/classification/cBGGenotype.h	2009-11-13 21:42:51 UTC (rev 3529)
@@ -101,7 +101,7 @@
   // Genotype Specific Methods
   inline const cBioUnit::eUnitSource GetSource() const { return m_src; }
   inline const cString& GetSourceArgs() const { return m_src_args; }
-  inline const cMetaGenome& GetGenome() const { return m_genome; }
+  inline const cMetaGenome& GetMetaGenome() const { return m_genome; }
   
   inline const cString& GetName() const { return m_name; }
   

Modified: branches/biounit/source/classification/cBGGenotypeManager.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotypeManager.cc	2009-11-12 21:15:32 UTC (rev 3528)
+++ branches/biounit/source/classification/cBGGenotypeManager.cc	2009-11-13 21:42:51 UTC (rev 3529)
@@ -31,12 +31,6 @@
 #include "cWorld.h"
 
 
-inline void cBGGenotypeManager::resizeActiveList(int size)
-{
-  if (m_active_sz.GetSize() <= size) m_active_sz.Resize(size + 1);
-}
-
-
 cBioGroup* cBGGenotypeManager::ClassifyNewBioUnit(cBioUnit* bu) { return ClassifyNewBioUnit(bu, NULL); }
 
 cBGGenotype* cBGGenotypeManager::ClassifyNewBioUnit(cBioUnit* bu, tArray<cBioGroup*>* parents)
@@ -65,6 +59,7 @@
 }
 
 
+
 unsigned int cBGGenotypeManager::hashGenome(const cGenome& genome) const
 {
   unsigned int total = 0;

Modified: branches/biounit/source/classification/cBGGenotypeManager.h
===================================================================
--- branches/biounit/source/classification/cBGGenotypeManager.h	2009-11-12 21:15:32 UTC (rev 3528)
+++ branches/biounit/source/classification/cBGGenotypeManager.h	2009-11-13 21:42:51 UTC (rev 3529)
@@ -70,8 +70,8 @@
   
   // Genotype Manager Methods
   cBGGenotype* ClassifyNewBioUnit(cBioUnit* bu, tArray<cBioGroup*>* parents);
+  inline void AdjustGenotype(cBGGenotype* genotype, int old_size, int new_size);
   
-  
 private:
   unsigned int hashGenome(const cGenome& genome) const;
   cString nameGenotype(int size, int num) const;
@@ -79,4 +79,18 @@
   inline void resizeActiveList(int size);
 };
 
+
+
+void cBGGenotypeManager::AdjustGenotype(cBGGenotype* genotype, int old_size, int new_size)
+{
+  m_active_sz[old_size].Remove(genotype);
+  resizeActiveList(new_size);
+  m_active_sz[new_size].Push(genotype);
+}
+
+inline void cBGGenotypeManager::resizeActiveList(int size)
+{
+  if (m_active_sz.GetSize() <= size) m_active_sz.Resize(size + 1);
+}
+
 #endif

Modified: branches/biounit/source/classification/cBioUnit.h
===================================================================
--- branches/biounit/source/classification/cBioUnit.h	2009-11-12 21:15:32 UTC (rev 3528)
+++ branches/biounit/source/classification/cBioUnit.h	2009-11-13 21:42:51 UTC (rev 3529)
@@ -35,7 +35,8 @@
     SRC_ORGANISM_FILE_LOAD,
     SRC_ORGANISM_DIVIDE,
     SRC_PARASITE_FILE_LOAD,
-    SRC_PARASITE_INJECT
+    SRC_PARASITE_INJECT,
+    SRC_TEST_CPU
   };
   
 
@@ -43,9 +44,9 @@
   cBioUnit() { ; }
   virtual ~cBioUnit() = 0;
   
-  virtual eUnitSource GetUnitSource() = 0;
-  virtual const cString& GetUnitSourceArgs() = 0;
-  virtual cMetaGenome& GetMetaGenome() = 0;
+  virtual eUnitSource GetUnitSource() const = 0;
+  virtual const cString& GetUnitSourceArgs() const = 0;
+  virtual const cMetaGenome& GetMetaGenome() const = 0;
 };
 
 #endif

Modified: branches/biounit/source/main/cOrganism.cc
===================================================================
--- branches/biounit/source/main/cOrganism.cc	2009-11-12 21:15:32 UTC (rev 3528)
+++ branches/biounit/source/main/cOrganism.cc	2009-11-13 21:42:51 UTC (rev 3529)
@@ -26,6 +26,7 @@
 #include "cOrganism.h"
 
 #include "cAvidaContext.h"
+#include "cBioGroup.h"
 #include "nHardware.h"
 #include "cEnvironment.h"
 #include "functions.h"
@@ -207,6 +208,9 @@
   if(m_net) delete m_net;
   if(m_msg) delete m_msg;
   if(m_opinion) delete m_opinion;
+  
+  // Notify all groups that this bio unit has been terminated
+  for (int i = 0; i < m_bio_groups.GetSize(); i++) m_bio_groups[i]->RemoveBioUnit(this);
 }
 
 cOrganism::cNetSupport::~cNetSupport()

Modified: branches/biounit/source/main/cOrganism.h
===================================================================
--- branches/biounit/source/main/cOrganism.h	2009-11-12 21:15:32 UTC (rev 3528)
+++ branches/biounit/source/main/cOrganism.h	2009-11-13 21:42:51 UTC (rev 3529)
@@ -34,6 +34,9 @@
 #include <utility>
 #include <map>
 
+#ifndef cBioUnit_h
+#include "cBioUnit.h"
+#endif
 #ifndef cCPUMemory_h
 #include "cCPUMemory.h"
 #endif
@@ -76,6 +79,7 @@
 
 
 class cAvidaContext;
+class cBioGroup;
 class cCodeLabel;
 class cEnvironment;
 class cGenotype;
@@ -89,13 +93,16 @@
 
 
 
-class cOrganism
+class cOrganism : public cBioUnit
 {
 private:
   cWorld* m_world;
   cHardwareBase* m_hardware;              // The actual machinery running this organism.
+  tArray<cBioGroup*> m_bio_groups;
   cGenotype* m_genotype;                  // Information about organisms with this genome.
   cPhenotype m_phenotype;                 // Descriptive attributes of organism.
+  cBioUnit::eUnitSource m_src;
+  cString m_src_args;
   const cMetaGenome m_initial_genome;         // Initial genome; can never be changed!
   tArray<cInjectGenotype*> m_parasites;   // List of all parasites associated with this organism.
   cMutationRates m_mut_rates;             // Rate of all possible mutations.
@@ -160,6 +167,12 @@
   cOrganism(cWorld* world, cAvidaContext& ctx, int hw_type, int inst_set_id, const cGenome& genome);
   cOrganism(cWorld* world, cAvidaContext& ctx, const cMetaGenome& genome, cInstSet* inst_set);
   ~cOrganism();
+  
+  // --------  cBioUnit Methods  --------
+  cBioUnit::eUnitSource GetUnitSource() const { return m_src; }
+  const cString& GetUnitSourceArgs() const { return m_src_args; }
+  const cMetaGenome& GetMetaGenome() const { return m_initial_genome; }
+  
 
   // --------  Support Methods  --------
   double GetTestFitness(cAvidaContext& ctx);
@@ -182,7 +195,6 @@
   void SetPhenotype(cPhenotype& _in_phenotype) { m_phenotype = _in_phenotype; }
 
   const cGenome& GetGenome() const { return m_initial_genome.GetGenome(); }
-  const cMetaGenome& GetMetaGenome() const { return m_initial_genome; }
   
   const cMutationRates& MutationRates() const { return m_mut_rates; }
   cMutationRates& MutationRates() { return m_mut_rates; }




More information about the Avida-cvs mailing list