[Avida-SVN] r3527 - branches/biounit/source/classification
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Wed Nov 11 13:56:42 PST 2009
Author: brysonda
Date: 2009-11-11 16:56:42 -0500 (Wed, 11 Nov 2009)
New Revision: 3527
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
Log:
More work on biounit. Fleshing out cBGGenotypeManager.
Modified: branches/biounit/source/classification/cBGGenotype.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotype.cc 2009-11-11 19:40:41 UTC (rev 3526)
+++ branches/biounit/source/classification/cBGGenotype.cc 2009-11-11 21:56:42 UTC (rev 3527)
@@ -28,6 +28,7 @@
cBGGenotype::cBGGenotype(cBGGenotypeManager* mgr, int in_id, cBioUnit* founder, int update, tArray<cBioGroup*>* parents)
: m_mgr(mgr)
, m_src(founder->GetUnitSource())
+ , m_src_args(founder->GetUnitSourceArgs())
, m_genome(founder->GetMetaGenome())
, m_name("001-no_name")
, m_threshold(false)
@@ -37,6 +38,9 @@
, m_update_deactivated(-1)
, m_depth(0)
, m_active_offspring_genotypes(0)
+ , m_num_organisms(0)
+ , m_last_num_organisms(0)
+ , m_total_organisms(0)
{
if (parents) {
m_parents.Resize(parents->GetSize());
@@ -52,3 +56,8 @@
{
for (int i = 0; i < m_parents.GetSize(); i++) m_parents[i]->RemoveReference();
}
+
+bool cBGGenotype::Matches(cBioUnit* bu)
+{
+ // @TODO
+}
Modified: branches/biounit/source/classification/cBGGenotype.h
===================================================================
--- branches/biounit/source/classification/cBGGenotype.h 2009-11-11 19:40:41 UTC (rev 3526)
+++ branches/biounit/source/classification/cBGGenotype.h 2009-11-11 21:56:42 UTC (rev 3527)
@@ -47,10 +47,12 @@
class cBGGenotype : public cBioGroup
{
+ friend class cBGGenotypeManager;
private:
cBGGenotypeManager* m_mgr;
cBioUnit::eUnitSource m_src;
+ cString m_src_args;
cMetaGenome m_genome;
cString m_name;
@@ -64,6 +66,9 @@
int m_update_deactivated;
int m_depth;
int m_active_offspring_genotypes;
+ int m_num_organisms;
+ int m_last_num_organisms;
+ int m_total_organisms;
tArray<cBioGroup*> m_parents;
@@ -72,7 +77,6 @@
cCountTracker m_breed_in;
cCountTracker m_breed_true;
cCountTracker m_breed_out;
- cCountTracker m_orgs;
cDoubleSum m_copied_size;
cDoubleSum m_exe_size;
@@ -95,6 +99,12 @@
// 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; }
+
inline const cString& GetName() const { return m_name; }
inline bool IsThreshold() const { return m_threshold; }
@@ -104,6 +114,8 @@
inline int GetUpdateBorn() const { return m_update_born; }
inline int GetUpdateDeactivated() const { return m_update_deactivated; }
+ inline int GetNumOrganisms() const { return m_num_organisms; }
+
void SetThreshold() { m_threshold = true; }
void ClearThreshold() { m_threshold = false; }
};
Modified: branches/biounit/source/classification/cBGGenotypeManager.cc
===================================================================
--- branches/biounit/source/classification/cBGGenotypeManager.cc 2009-11-11 19:40:41 UTC (rev 3526)
+++ branches/biounit/source/classification/cBGGenotypeManager.cc 2009-11-11 21:56:42 UTC (rev 3527)
@@ -24,3 +24,61 @@
#include "cBGGenotypeManager.h"
+#include "cBGGenotype.h"
+#include "cGenome.h"
+#include "cStats.h"
+#include "cStringUtil.h"
+#include "cWorld.h"
+
+
+//const unsigned int cBGGenotypeManager::HASH_SIZE = 3203;
+
+cBioGroup* cBGGenotypeManager::ClassifyNewBioUnit(cBioUnit* bu) { return ClassifyNewBioUnit(bu, NULL); }
+
+cBGGenotype* cBGGenotypeManager::ClassifyNewBioUnit(cBioUnit* bu, tArray<cBioGroup*>* parents)
+{
+ int list_num = hashGenome(bu->GetMetaGenome().GetGenome());
+
+ cBGGenotype* found = NULL;
+ tListIterator<cBGGenotype> list_it(m_active_hash[list_num]);
+ while (list_it.Next() != NULL) {
+ if (list_it.Get()->Matches(bu)) {
+ found = list_it.Get();
+ break;
+ }
+ }
+
+ if (!found) {
+ found = new cBGGenotype(this, m_next_id++, bu, m_world->GetStats().GetUpdate(), parents);
+ m_active_hash[list_num].Push(found);
+ m_active_sz[found->GetNumOrganisms()].Push(found);
+ m_world->GetStats().AddGenotype();
+ }
+
+ return found;
+}
+
+
+unsigned int cBGGenotypeManager::hashGenome(const cGenome& genome) const
+{
+ unsigned int total = 0;
+
+ for (int i = 0; i < genome.GetSize(); i++) {
+ total += (genome[i].GetOp() + 3) * i;
+ }
+
+ return total % nBGGenotypeManager::HASH_SIZE;
+}
+
+cString cBGGenotypeManager::nameGenotype(int size, int num) const
+{
+ char alpha[6];
+
+ for (int i = 4; i >= 0; i--) {
+ alpha[i] = (num % 26) + 'a';
+ num /= 26;
+ }
+ alpha[5] = '\0';
+
+ return cStringUtil::Stringf("%03d-%s", size, alpha);
+}
Modified: branches/biounit/source/classification/cBGGenotypeManager.h
===================================================================
--- branches/biounit/source/classification/cBGGenotypeManager.h 2009-11-11 19:40:41 UTC (rev 3526)
+++ branches/biounit/source/classification/cBGGenotypeManager.h 2009-11-11 21:56:42 UTC (rev 3527)
@@ -25,17 +25,39 @@
#ifndef cBGGenotypeManager_h
#define cBGGenotypeManager_h
+#ifndef defs_h
+#include "defs.h"
+#endif
#ifndef cBioGroupManager_h
#include "cBioGroupManager.h"
#endif
+#ifndef tList_h
+#include "tList.h"
+#endif
+#ifndef tManagedPointerArray_h
+#include "tManagedPointerArray.h"
+#endif
+class cBGGenotype;
+class cGenome;
class cWorld;
+namespace nBGGenotypeManager {
+ const unsigned int HASH_SIZE = 3203;
+}
class cBGGenotypeManager : public cBioGroupManager
{
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;
+ int m_next_id;
+ int m_dom_prev;
+ int m_dom_time;
public:
@@ -47,6 +69,12 @@
// Genotype Manager Methods
+ cBGGenotype* ClassifyNewBioUnit(cBioUnit* bu, tArray<cBioGroup*>* parents);
+
+
+private:
+ unsigned int hashGenome(const cGenome& genome) const;
+ cString nameGenotype(int size, int num) const;
};
#endif
More information about the Avida-cvs
mailing list