[Avida-SVN] r3528 - branches/biounit/source/classification
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Nov 12 13:15:32 PST 2009
Author: brysonda
Date: 2009-11-12 16:15:32 -0500 (Thu, 12 Nov 2009)
New Revision: 3528
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
Log:
Some more methods implemented in cBGGenotype.
Modified: branches/biounit/source/classification/cBGGenotype.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotype.cc 2009-11-11 21:56:42 UTC (rev 3527)
+++ branches/biounit/source/classification/cBGGenotype.cc 2009-11-12 21:15:32 UTC (rev 3528)
@@ -24,7 +24,9 @@
#include "cBGGenotype.h"
+#include "cBGGenotypeManager.h"
+
cBGGenotype::cBGGenotype(cBGGenotypeManager* mgr, int in_id, cBioUnit* founder, int update, tArray<cBioGroup*>* parents)
: m_mgr(mgr)
, m_src(founder->GetUnitSource())
@@ -38,9 +40,9 @@
, m_update_deactivated(-1)
, m_depth(0)
, m_active_offspring_genotypes(0)
- , m_num_organisms(0)
+ , m_num_organisms(1)
, m_last_num_organisms(0)
- , m_total_organisms(0)
+ , m_total_organisms(1)
{
if (parents) {
m_parents.Resize(parents->GetSize());
@@ -57,7 +59,91 @@
for (int i = 0; i < m_parents.GetSize(); i++) m_parents[i]->RemoveReference();
}
+cBioGroup* cBGGenotype::ClassifyNewBioUnit(cBioUnit* bu, tArray<cBioGroup*>* parents)
+{
+ m_births.Inc();
+
+ if (Matches(bu)) {
+ m_breed_true.Inc();
+ m_total_organisms++;
+ m_num_organisms++;
+ // @TODO - adjust genotype
+
+ return this;
+ }
+
+ m_breed_out.Inc();
+ return m_mgr->ClassifyNewBioUnit(bu, parents);
+}
+
+
+void cBGGenotype::RemoveBioUnit(cBioUnit* bu)
+{
+ m_deaths.Inc();
+ m_num_organisms--;
+ // @TODO - adjust genotype
+}
+
+
bool cBGGenotype::Matches(cBioUnit* bu)
{
- // @TODO
+ // Handle source branching
+ switch (m_src) {
+ case cBioUnit::SRC_ORGANISM_FILE_LOAD:
+ case cBioUnit::SRC_ORGANISM_DIVIDE:
+ switch (bu->GetUnitSource()) {
+ case cBioUnit::SRC_ORGANISM_FILE_LOAD:
+ case cBioUnit::SRC_ORGANISM_DIVIDE:
+ break;
+
+ case cBioUnit::SRC_PARASITE_FILE_LOAD:
+ case cBioUnit::SRC_PARASITE_INJECT:
+ return false;
+ break;
+
+ default:
+ assert(false);
+ break;
+ }
+ break;
+
+ case cBioUnit::SRC_PARASITE_FILE_LOAD:
+ case cBioUnit::SRC_PARASITE_INJECT:
+ switch (bu->GetUnitSource()) {
+ case cBioUnit::SRC_ORGANISM_FILE_LOAD:
+ case cBioUnit::SRC_ORGANISM_DIVIDE:
+ return false;
+ break;
+
+ case cBioUnit::SRC_PARASITE_FILE_LOAD:
+ case cBioUnit::SRC_PARASITE_INJECT:
+ // Verify that the parasite inject label matches
+ if (m_src_args != bu->GetUnitSourceArgs()) return false;
+ break;
+
+ default:
+ assert(false);
+ break;
+ }
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ // Compare the genomes
+ return (m_genome == bu->GetMetaGenome());
}
+
+void cBGGenotype::UpdateReset()
+{
+ m_last_num_organisms = m_num_organisms;
+ m_births.Next();
+ m_deaths.Next();
+ m_breed_out.Next();
+ m_breed_true.Next();
+ m_breed_in.Next();
+}
+
Modified: branches/biounit/source/classification/cBGGenotype.h
===================================================================
--- branches/biounit/source/classification/cBGGenotype.h 2009-11-11 21:56:42 UTC (rev 3527)
+++ branches/biounit/source/classification/cBGGenotype.h 2009-11-12 21:15:32 UTC (rev 3528)
@@ -99,8 +99,6 @@
// Genotype Specific Methods
- bool Matches(cBioUnit* bu);
-
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; }
@@ -118,6 +116,10 @@
void SetThreshold() { m_threshold = true; }
void ClearThreshold() { m_threshold = false; }
+
+ bool Matches(cBioUnit* bu);
+ inline void NotifyNewBioUnit(cBioUnit* bu) { m_total_organisms++; m_num_organisms++; m_breed_in.Inc(); }
+ void UpdateReset();
};
#endif
Modified: branches/biounit/source/classification/cBGGenotypeManager.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotypeManager.cc 2009-11-11 21:56:42 UTC (rev 3527)
+++ branches/biounit/source/classification/cBGGenotypeManager.cc 2009-11-12 21:15:32 UTC (rev 3528)
@@ -31,8 +31,12 @@
#include "cWorld.h"
-//const unsigned int cBGGenotypeManager::HASH_SIZE = 3203;
+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)
@@ -44,6 +48,7 @@
while (list_it.Next() != NULL) {
if (list_it.Get()->Matches(bu)) {
found = list_it.Get();
+ found->NotifyNewBioUnit(bu);
break;
}
}
@@ -51,6 +56,7 @@
if (!found) {
found = new cBGGenotype(this, m_next_id++, bu, m_world->GetStats().GetUpdate(), parents);
m_active_hash[list_num].Push(found);
+ resizeActiveList(found->GetNumOrganisms());
m_active_sz[found->GetNumOrganisms()].Push(found);
m_world->GetStats().AddGenotype();
}
Modified: branches/biounit/source/classification/cBGGenotypeManager.h
===================================================================
--- branches/biounit/source/classification/cBGGenotypeManager.h 2009-11-11 21:56:42 UTC (rev 3527)
+++ branches/biounit/source/classification/cBGGenotypeManager.h 2009-11-12 21:15:32 UTC (rev 3528)
@@ -75,6 +75,8 @@
private:
unsigned int hashGenome(const cGenome& genome) const;
cString nameGenotype(int size, int num) const;
+
+ inline void resizeActiveList(int size);
};
#endif
Modified: branches/biounit/source/classification/cBioUnit.h
===================================================================
--- branches/biounit/source/classification/cBioUnit.h 2009-11-11 21:56:42 UTC (rev 3527)
+++ branches/biounit/source/classification/cBioUnit.h 2009-11-12 21:15:32 UTC (rev 3528)
@@ -32,10 +32,10 @@
{
public:
enum eUnitSource {
- ORGANISM_FILE_LOAD,
- ORGANISM_DIVIDE,
- PARASITE_FILE_LOAD,
- PARASITE_INJECT
+ SRC_ORGANISM_FILE_LOAD,
+ SRC_ORGANISM_DIVIDE,
+ SRC_PARASITE_FILE_LOAD,
+ SRC_PARASITE_INJECT
};
More information about the Avida-cvs
mailing list