[Avida-SVN] r2928 - in development/source: analyze script tools
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Sun Nov 9 14:46:10 PST 2008
Author: brysonda
Date: 2008-11-09 17:46:09 -0500 (Sun, 09 Nov 2008)
New Revision: 2928
Modified:
development/source/analyze/cAnalyzeGenotype.h
development/source/analyze/cGenotypeBatch.cc
development/source/analyze/cGenotypeBatch.h
development/source/script/ASAvidaLib.cc
development/source/tools/tList.h
Log:
Implement cGenotypeBatch::RemoveClade
AS: Expose currently implemented methods of cGenotypeBatch
Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h 2008-11-07 20:04:59 UTC (rev 2927)
+++ development/source/analyze/cAnalyzeGenotype.h 2008-11-09 22:46:09 UTC (rev 2928)
@@ -297,9 +297,9 @@
// Accessors...
const cGenome & GetGenome() const { return genome; }
- const cString & GetName() const { return name; }
- const cInstSet & GetInstructionSet() const { return m_inst_set; }
- const cString & GetAlignedSequence() const { return aligned_sequence; }
+ const cString& GetName() const { return name; }
+ const cInstSet& GetInstructionSet() const { return m_inst_set; }
+ const cString& GetAlignedSequence() const { return aligned_sequence; }
cString GetExecutedFlags() const { return executed_flags; }
cString GetAlignmentExecutedFlags() const;
const tArray<int>& GetInstExecutedCounts() const { return inst_executed_counts; }
Modified: development/source/analyze/cGenotypeBatch.cc
===================================================================
--- development/source/analyze/cGenotypeBatch.cc 2008-11-07 20:04:59 UTC (rev 2927)
+++ development/source/analyze/cGenotypeBatch.cc 2008-11-09 22:46:09 UTC (rev 2928)
@@ -31,11 +31,19 @@
#include "tSmartArray.h"
-cAnalyzeGenotype* cGenotypeBatch::FindGenotypeNumCPUs()
+cGenotypeBatch::~cGenotypeBatch()
{
- return m_list.FindMax(&cAnalyzeGenotype::GetNumCPUs);
+ tListIterator<cAnalyzeGenotype> it(m_list);
+ cAnalyzeGenotype* genotype = NULL;
+ while ((genotype = it.Next())) delete genotype;
}
+
+cAnalyzeGenotype* cGenotypeBatch::FindGenotypeNumCPUs() const
+{
+ return new cAnalyzeGenotype(*(m_list.FindMax(&cAnalyzeGenotype::GetNumCPUs)));
+}
+
cAnalyzeGenotype* cGenotypeBatch::PopGenotypeNumCPUs()
{
clearFlags();
@@ -43,9 +51,9 @@
}
-cAnalyzeGenotype* cGenotypeBatch::FindGenotypeTotalCPUs()
+cAnalyzeGenotype* cGenotypeBatch::FindGenotypeTotalCPUs() const
{
- return m_list.FindMax(&cAnalyzeGenotype::GetTotalCPUs);
+ return new cAnalyzeGenotype(*(m_list.FindMax(&cAnalyzeGenotype::GetTotalCPUs)));
}
cAnalyzeGenotype* cGenotypeBatch::PopGenotypeTotalCPUs()
@@ -55,9 +63,9 @@
}
-cAnalyzeGenotype* cGenotypeBatch::FindGenotypeMetabolicRate()
+cAnalyzeGenotype* cGenotypeBatch::FindGenotypeMetabolicRate() const
{
- return m_list.FindMax(&cAnalyzeGenotype::GetMerit);
+ return new cAnalyzeGenotype(*(m_list.FindMax(&cAnalyzeGenotype::GetMerit)));
}
cAnalyzeGenotype* cGenotypeBatch::PopGenotypeMetabolicRate()
@@ -67,9 +75,9 @@
}
-cAnalyzeGenotype* cGenotypeBatch::FindGenotypeFitness()
+cAnalyzeGenotype* cGenotypeBatch::FindGenotypeFitness() const
{
- return m_list.FindMax(&cAnalyzeGenotype::GetFitness);
+ return new cAnalyzeGenotype(*(m_list.FindMax(&cAnalyzeGenotype::GetFitness)));
}
cAnalyzeGenotype* cGenotypeBatch::PopGenotypeFitness()
@@ -79,9 +87,9 @@
}
-cAnalyzeGenotype* cGenotypeBatch::FindGenotypeID(int gid)
+cAnalyzeGenotype* cGenotypeBatch::FindGenotypeID(int gid) const
{
- return m_list.FindValue(&cAnalyzeGenotype::GetID, gid);
+ return new cAnalyzeGenotype(*(m_list.FindValue(&cAnalyzeGenotype::GetID, gid)));
}
cAnalyzeGenotype* cGenotypeBatch::PopGenotypeID(int gid)
@@ -91,11 +99,11 @@
}
-cAnalyzeGenotype* cGenotypeBatch::FindGenotypeRandom(cRandom& rng)
+cAnalyzeGenotype* cGenotypeBatch::FindGenotypeRandom(cRandom& rng) const
{
if (m_list.GetSize() == 0) return NULL;
- return m_list.GetPos(rng.GetUInt(m_list.GetSize()));
+ return new cAnalyzeGenotype(*(m_list.GetPos(rng.GetUInt(m_list.GetSize()))));
}
cAnalyzeGenotype* cGenotypeBatch::PopGenotypeRandom(cRandom& rng)
@@ -107,20 +115,21 @@
}
-cGenotypeBatch* cGenotypeBatch::FindLineage(cAnalyzeGenotype* end_genotype)
+cGenotypeBatch* cGenotypeBatch::FindLineage(cAnalyzeGenotype* end_genotype) const
{
if ((end_genotype)) return FindLineage(end_genotype->GetID());
return new cGenotypeBatch;
}
-cGenotypeBatch* cGenotypeBatch::FindLineage(int end_genotype_id)
+cGenotypeBatch* cGenotypeBatch::FindLineage(int end_genotype_id) const
{
cGenotypeBatch* batch = new cGenotypeBatch;
cAnalyzeGenotype* found_gen = FindGenotypeID(end_genotype_id);
while ((found_gen)) {
batch->m_list.Push(found_gen);
+ batch->m_lineage_head = found_gen;
found_gen = FindGenotypeID(found_gen->GetParentID());
}
@@ -130,14 +139,14 @@
}
-cGenotypeBatch* cGenotypeBatch::FindClade(cAnalyzeGenotype* start_genotype)
+cGenotypeBatch* cGenotypeBatch::FindClade(cAnalyzeGenotype* start_genotype) const
{
if ((start_genotype)) return FindClade(start_genotype->GetID());
return new cGenotypeBatch;
}
-cGenotypeBatch* cGenotypeBatch::FindClade(int start_genotype_id)
+cGenotypeBatch* cGenotypeBatch::FindClade(int start_genotype_id) const
{
cGenotypeBatch* batch = new cGenotypeBatch;
tList<cAnalyzeGenotype> list(m_list);
@@ -146,6 +155,7 @@
if ((found_gen)) {
batch->m_list.Push(found_gen);
+ batch->m_clade_head = found_gen;
scan_list.Push(found_gen->GetID());
}
@@ -158,7 +168,7 @@
if (found_gen->GetParentID() == parent_id) {
it.Remove();
scan_list.Push(found_gen->GetID());
- batch->m_list.Push(found_gen);
+ batch->m_list.Push(new cAnalyzeGenotype(*found_gen));
}
}
}
@@ -174,6 +184,37 @@
void cGenotypeBatch::RemoveClade(int start_genotype_id)
{
- // @TODO - implement remove clade
+ if (m_is_lineage) {
+ tListIterator<cAnalyzeGenotype> it(m_list);
+ cAnalyzeGenotype* genotype = NULL;
+
+ while ((genotype = it.Next())) {
+ if (genotype->GetID() == start_genotype_id) {
+ it.Remove();
+ delete genotype;
+ break;
+ }
+ }
+ while ((genotype = it.Next())) { it.Remove(); delete genotype; }
+ } else {
+ tSmartArray<int> scan_list;
+ cAnalyzeGenotype* found_gen = PopGenotypeID(start_genotype_id);
+
+ if ((found_gen)) scan_list.Push(found_gen->GetID());
+
+ while (scan_list.GetSize()) {
+ int parent_id = scan_list.Pop();
+
+ // Seach for all of the offspring of this genotype...
+ tListIterator<cAnalyzeGenotype> it(m_list);
+ while ((found_gen = it.Next()) != NULL) {
+ if (found_gen->GetParentID() == parent_id) {
+ it.Remove();
+ scan_list.Push(found_gen->GetID());
+ delete found_gen;
+ }
+ }
+ }
+ }
}
Modified: development/source/analyze/cGenotypeBatch.h
===================================================================
--- development/source/analyze/cGenotypeBatch.h 2008-11-07 20:04:59 UTC (rev 2927)
+++ development/source/analyze/cGenotypeBatch.h 2008-11-09 22:46:09 UTC (rev 2928)
@@ -52,11 +52,11 @@
public:
cGenotypeBatch() : m_name(""), m_lineage_head(NULL), m_clade_head(NULL), m_is_lineage(false), m_is_aligned(false) { ; }
- ~cGenotypeBatch() { ; }
+ ~cGenotypeBatch();
tListPlus<cAnalyzeGenotype>& List() { return m_list; }
cString& Name() { return m_name; }
- const cString& GetName() { return m_name; }
+ const cString& GetName() const { return m_name; }
int GetSize() { return m_list.GetSize(); }
@@ -69,26 +69,26 @@
void MergeWith(cGenotypeBatch* batch) { m_list.Append(batch->m_list); }
- cAnalyzeGenotype* FindGenotypeNumCPUs();
+ cAnalyzeGenotype* FindGenotypeNumCPUs() const;
cAnalyzeGenotype* PopGenotypeNumCPUs();
- cAnalyzeGenotype* FindGenotypeTotalCPUs();
+ cAnalyzeGenotype* FindGenotypeTotalCPUs() const;
cAnalyzeGenotype* PopGenotypeTotalCPUs();
- cAnalyzeGenotype* FindGenotypeMetabolicRate();
+ cAnalyzeGenotype* FindGenotypeMetabolicRate() const;
cAnalyzeGenotype* PopGenotypeMetabolicRate();
- cAnalyzeGenotype* FindGenotypeFitness();
+ cAnalyzeGenotype* FindGenotypeFitness() const;
cAnalyzeGenotype* PopGenotypeFitness();
- cAnalyzeGenotype* FindGenotypeID(int gid);
+ cAnalyzeGenotype* FindGenotypeID(int gid) const;
cAnalyzeGenotype* PopGenotypeID(int gid);
- cAnalyzeGenotype* FindGenotypeRandom(cRandom& rng);
+ cAnalyzeGenotype* FindGenotypeRandom(cRandom& rng) const;
cAnalyzeGenotype* PopGenotypeRandom(cRandom& rng);
- inline cAnalyzeGenotype* FindGenotypeRandom(cRandom* rng) { return FindGenotypeRandom(*rng); }
+ inline cAnalyzeGenotype* FindGenotypeRandom(cRandom* rng) const { return FindGenotypeRandom(*rng); }
inline cAnalyzeGenotype* PopGenotypeRandom(cRandom* rng) { return PopGenotypeRandom(*rng); }
- cGenotypeBatch* FindLineage(cAnalyzeGenotype* end_genotype);
- cGenotypeBatch* FindLineage(int end_genotype_id);
+ cGenotypeBatch* FindLineage(cAnalyzeGenotype* end_genotype) const;
+ cGenotypeBatch* FindLineage(int end_genotype_id) const;
- cGenotypeBatch* FindClade(cAnalyzeGenotype* start_genotype);
- cGenotypeBatch* FindClade(int start_genotype_id);
+ cGenotypeBatch* FindClade(cAnalyzeGenotype* start_genotype) const;
+ cGenotypeBatch* FindClade(int start_genotype_id) const;
void RemoveClade(cAnalyzeGenotype* start_genotype);
void RemoveClade(int start_genotype_id);
Modified: development/source/script/ASAvidaLib.cc
===================================================================
--- development/source/script/ASAvidaLib.cc 2008-11-07 20:04:59 UTC (rev 2927)
+++ development/source/script/ASAvidaLib.cc 2008-11-09 22:46:09 UTC (rev 2928)
@@ -29,6 +29,7 @@
#include "cASCPPParameter_NativeObjectSupport.h"
#include "cASLibrary.h"
+#include "cAnalyzeGenotype.h"
#include "cAvidaConfig.h"
#include "cDefaultRunDriver.h"
#include "cGenotypeBatch.h"
@@ -45,6 +46,10 @@
tASNativeObject<CLASS>::RegisterMethod(new tASNativeObjectMethodConst<CLASS, SIGNATURE>(&CLASS::METHOD), NAME);
+ tASNativeObject<cAnalyzeGenotype>::InitializeMethodRegistrar();
+ REGISTER_C_METHOD(cAnalyzeGenotype, "Name", GetName, const cString& ());
+
+
tASNativeObject<cAvidaConfig>::InitializeMethodRegistrar();
REGISTER_C_METHOD(cAvidaConfig, "Get", GetAsString, cString (const cString&));
REGISTER_C_METHOD(cAvidaConfig, "HasEntry", HasEntry, bool (const cString&));
@@ -57,9 +62,27 @@
tASNativeObject<cGenotypeBatch>::InitializeMethodRegistrar();
- REGISTER_S_METHOD(cGenotypeBatch, "Name", GetName, const cString& ());
+ REGISTER_C_METHOD(cGenotypeBatch, "Name", GetName, const cString& ());
+ REGISTER_S_METHOD(cGenotypeBatch, "GetSize", GetSize, int ());
REGISTER_S_METHOD(cGenotypeBatch, "IsAligned", IsAligned, bool ());
REGISTER_S_METHOD(cGenotypeBatch, "IsLineage", IsLineage, bool ());
+ REGISTER_S_METHOD(cGenotypeBatch, "MergeWith", MergeWith, void (cGenotypeBatch*));
+ REGISTER_C_METHOD(cGenotypeBatch, "FindGenotypeNumCPUs", FindGenotypeNumCPUs, cAnalyzeGenotype* ());
+ REGISTER_S_METHOD(cGenotypeBatch, "PopGenotypeNumCPUs", PopGenotypeNumCPUs, cAnalyzeGenotype* ());
+ REGISTER_C_METHOD(cGenotypeBatch, "FindGenotypeTotalCPUs", FindGenotypeTotalCPUs, cAnalyzeGenotype* ());
+ REGISTER_S_METHOD(cGenotypeBatch, "PopGenotypeTotalCPUs", PopGenotypeTotalCPUs, cAnalyzeGenotype* ());
+ REGISTER_C_METHOD(cGenotypeBatch, "FindGenotypeMetabolicRate", FindGenotypeMetabolicRate, cAnalyzeGenotype* ());
+ REGISTER_S_METHOD(cGenotypeBatch, "PopGenotypeMetabolicRate", PopGenotypeMetabolicRate, cAnalyzeGenotype* ());
+ REGISTER_C_METHOD(cGenotypeBatch, "FindGenotypeFitness", FindGenotypeFitness, cAnalyzeGenotype* ());
+ REGISTER_S_METHOD(cGenotypeBatch, "PopGenotypeFitness", PopGenotypeFitness, cAnalyzeGenotype* ());
+ REGISTER_C_METHOD(cGenotypeBatch, "FindGenotypeID", FindGenotypeID, cAnalyzeGenotype* (int));
+ 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, "FindLineage", FindLineage, cGenotypeBatch* (cAnalyzeGenotype*));
+ REGISTER_C_METHOD(cGenotypeBatch, "FindClade", FindClade, cGenotypeBatch* (cAnalyzeGenotype*));
+ REGISTER_S_METHOD(cGenotypeBatch, "RemoveClade", RemoveClade, void (cAnalyzeGenotype*));
+
tASNativeObject<cResourceHistory>::InitializeMethodRegistrar();
Modified: development/source/tools/tList.h
===================================================================
--- development/source/tools/tList.h 2008-11-07 20:04:59 UTC (rev 2927)
+++ development/source/tools/tList.h 2008-11-09 22:46:09 UTC (rev 2928)
@@ -362,7 +362,7 @@
- template<typename V> T* FindValue(V (T::*fun)() const, V value)
+ template<typename V> T* FindValue(V (T::*fun)() const, V value) const
{
tListNode<T>* node;
if (FindNode(fun, value, node)) return node->data;
@@ -376,7 +376,7 @@
return NULL;
}
- template<typename V> T* FindMax(V (T::*fun)() const)
+ template<typename V> T* FindMax(V (T::*fun)() const) const
{
tListNode<T>* node;
if (FindMax(fun, node)) return node->data;
@@ -392,7 +392,7 @@
// Find by summing values until a specified total is reached.
- T* FindSummedValue(int sum, int (T::*fun)() const)
+ T* FindSummedValue(int sum, int (T::*fun)() const) const
{
if (this->size == 0) return NULL;
@@ -406,7 +406,7 @@
}
- int Count(int (T::*fun)() const)
+ int Count(int (T::*fun)() const) const
{
int total = 0;
tListNode<T> * test = this->root.next;
@@ -419,7 +419,7 @@
private:
- template<typename V> bool FindNode(V (T::*fun)() const, V value, tListNode<T>*& node)
+ template<typename V> bool FindNode(V (T::*fun)() const, V value, tListNode<T>*& node) const
{
node = this->root.next;
while (node != &(this->root)) {
@@ -431,7 +431,7 @@
}
- template<typename V> bool FindMax(V (T::*fun)() const, tListNode<T>*& best)
+ template<typename V> bool FindMax(V (T::*fun)() const, tListNode<T>*& best) const
{
if (this->size == 0) return false;
More information about the Avida-cvs
mailing list