[Avida-SVN] r3097 - in development: Avida.xcodeproj source/analyze source/main
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Sat Jan 10 14:01:47 PST 2009
Author: brysonda
Date: 2009-01-10 17:01:46 -0500 (Sat, 10 Jan 2009)
New Revision: 3097
Added:
development/source/analyze/cGenotypeData.cc
development/source/analyze/cGenotypeData.h
Modified:
development/Avida.xcodeproj/project.pbxproj
development/source/analyze/cAnalyzeGenotype.cc
development/source/analyze/cAnalyzeGenotype.h
development/source/main/cTaskLib.cc
Log:
Beginning ground work for thread-safe, reference counted, general purpose datastore within cAnalyzeGenotype.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2009-01-10 16:17:26 UTC (rev 3096)
+++ development/Avida.xcodeproj/project.pbxproj 2009-01-10 22:01:46 UTC (rev 3097)
@@ -203,6 +203,7 @@
70AA941A09D486CA006A24C8 /* system-alloc.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF50209CFB0B400924128 /* system-alloc.cc */; };
70AA941B09D486CB006A24C8 /* tcmalloc-logging.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF57F09CFBD3D00924128 /* tcmalloc-logging.cc */; };
70AA941C09D486CD006A24C8 /* tcmalloc.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCF56309CFBB9500924128 /* tcmalloc.cc */; };
+ 70AD4FA00F194F4D00AA50AC /* cGenotypeData.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70AD4F9E0F194DD400AA50AC /* cGenotypeData.cc */; };
70B1A7430B7E3FFD00067486 /* instset-experimental.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 70B1A7420B7E3FFD00067486 /* instset-experimental.cfg */; };
70B1A75A0B7E431F00067486 /* experimental.org in CopyFiles */ = {isa = PBXBuildFile; fileRef = 70B1A7590B7E431F00067486 /* experimental.org */; };
70B6514F0BEA6FCC002472ED /* main.cc in Sources */ = {isa = PBXBuildFile; fileRef = 701EF27E0BEA5D2300DAE168 /* main.cc */; };
@@ -614,6 +615,8 @@
70A778370D69D5C200735F1E /* cDemeProbSchedule.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cDemeProbSchedule.cc; sourceTree = "<group>"; };
70A778380D69D5C200735F1E /* cDemeProbSchedule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cDemeProbSchedule.h; sourceTree = "<group>"; };
70AA941909D486AE006A24C8 /* libtcmalloc.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libtcmalloc.a; sourceTree = BUILT_PRODUCTS_DIR; };
+ 70AD4F990F194D2400AA50AC /* cGenotypeData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cGenotypeData.h; sourceTree = "<group>"; };
+ 70AD4F9E0F194DD400AA50AC /* cGenotypeData.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cGenotypeData.cc; sourceTree = "<group>"; };
70AE2D360E7DCAA100A520B5 /* cASNativeObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cASNativeObject.h; sourceTree = "<group>"; };
70AE2D3B0E7DF6C500A520B5 /* cASCPPParameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cASCPPParameter.h; sourceTree = "<group>"; };
70B0864808F4972600FC65FE /* cLandscape.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cLandscape.h; sourceTree = "<group>"; };
@@ -1043,6 +1046,8 @@
7054A1B409A810CB00038658 /* cAnalyzeJobWorker.cc */,
707AEF8C09EA8B2D001AEA89 /* cAnalyzeCommandAction.h */,
70E60C4A0EC0088300718740 /* cGenotypeBatch.cc */,
+ 70AD4F990F194D2400AA50AC /* cGenotypeData.h */,
+ 70AD4F9E0F194DD400AA50AC /* cGenotypeData.cc */,
);
path = analyze;
sourceTree = "<group>";
@@ -2081,6 +2086,7 @@
70E60C4B0EC0088300718740 /* cGenotypeBatch.cc in Sources */,
70211A5E0ECBD531004A293A /* cRCObject.cc in Sources */,
D7FB16D60ED62684002E939E /* cOrgMessage.cc in Sources */,
+ 70AD4FA00F194F4D00AA50AC /* cGenotypeData.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc 2009-01-10 16:17:26 UTC (rev 3096)
+++ development/source/analyze/cAnalyzeGenotype.cc 2009-01-10 22:01:46 UTC (rev 3097)
@@ -56,6 +56,7 @@
, genome(symbol_string)
, m_inst_set(in_inst_set)
, name("")
+ , m_data(new sGenotypeDatastore)
, aligned_sequence("")
, tag("")
, viable(false)
@@ -109,6 +110,7 @@
, genome(_genome)
, m_inst_set(in_inst_set)
, name("")
+ , m_data(new sGenotypeDatastore)
, aligned_sequence("")
, tag("")
, viable(false)
@@ -151,6 +153,7 @@
, genome(_gen.genome)
, m_inst_set(_gen.m_inst_set)
, name(_gen.name)
+ , m_data(_gen.m_data)
, aligned_sequence(_gen.aligned_sequence)
, tag(_gen.tag)
, viable(_gen.viable)
Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h 2009-01-10 16:17:26 UTC (rev 3096)
+++ development/source/analyze/cAnalyzeGenotype.h 2009-01-10 22:01:46 UTC (rev 3097)
@@ -59,6 +59,12 @@
#include "tArray.h"
#endif
+#include "cGenotypeData.h"
+#include "cRWLock.h"
+#include "tDictionary.h"
+#include "tRCPtr.h"
+
+
// cAnalyzeGenotype : Collection of information about loaded genotypes
class cAvidaContext;
@@ -67,51 +73,52 @@
class cWorld;
template<class T> class tDataCommandManager;
-
class cAnalyzeGenotype;
-class cAnalyzeGenotypeLink {
+
+
+class cAnalyzeGenotypeLink
+{
private:
cAnalyzeGenotype *m_parent;
tList<cAnalyzeGenotype> m_child_list;
+
public:
- cAnalyzeGenotypeLink(){
- SetParent(0);
- m_child_list.Clear();
- }
- void SetParent(cAnalyzeGenotype *parent){
- m_parent = parent;
- }
- cAnalyzeGenotype *GetParent(){
- return m_parent;
- }
- tList<cAnalyzeGenotype> &GetChildList(){
- return m_child_list;
- }
- cAnalyzeGenotype *FindChild(cAnalyzeGenotype *child){
- return GetChildList().FindPtr(child);
- }
- cAnalyzeGenotype *RemoveChild(cAnalyzeGenotype *child){
- return GetChildList().Remove(child);
- }
- void AddChild(cAnalyzeGenotype *child){
- if(!FindChild(child)){
- GetChildList().PushRear(child);
- }
- }
+ cAnalyzeGenotypeLink() : m_parent(NULL) { m_child_list.Clear(); }
+
+ void SetParent(cAnalyzeGenotype* parent) { m_parent = parent; }
+ cAnalyzeGenotype* GetParent() { return m_parent; }
+ tList<cAnalyzeGenotype>& GetChildList() { return m_child_list; }
+ cAnalyzeGenotype* FindChild(cAnalyzeGenotype* child) { return GetChildList().FindPtr(child); }
+ cAnalyzeGenotype* RemoveChild(cAnalyzeGenotype* child) { return GetChildList().Remove(child); }
+ void AddChild(cAnalyzeGenotype* child) { if(!FindChild(child)) GetChildList().PushRear(child); }
};
-class cAnalyzeGenotype {
+class cAnalyzeGenotype
+{
private:
- cAnalyzeGenotypeLink m_link;
-private:
cWorld* m_world;
cGenome genome; // Full Genome
- cInstSet& m_inst_set; // Instruction set used in this genome
+ cInstSet& m_inst_set; // Instruction set used in this genome
cString name; // Name, if one was provided in loading
+
+ struct sGenotypeDatastore : public cRCObject
+ {
+ cRWLock rwlock;
+ tDictionary<cGenotypeData*> dmap;
+
+ sGenotypeDatastore() { ; }
+ sGenotypeDatastore(const sGenotypeDatastore& ds) : cRCObject(ds) { ; } // Note that data objects are not copied right now
+
+ ~sGenotypeDatastore() { ; }
+ };
+ tRCPtr<sGenotypeDatastore> m_data;
+
cString aligned_sequence; // Sequence (in ASCII) after alignment
cString tag; // All genotypes in a batch can be tagged
+ cAnalyzeGenotypeLink m_link;
+
bool viable;
// Group 1 : Load-in Stats (Only obtained if available for input file)
@@ -190,7 +197,7 @@
cAnalyzeKnockouts() { Reset(); }
};
- mutable cAnalyzeKnockouts * knockout_stats;
+ mutable cAnalyzeKnockouts* knockout_stats;
mutable cLandscape* m_land;
@@ -236,7 +243,7 @@
public:
cAnalyzeGenotype(cWorld* world, cString symbol_string, cInstSet& in_inst_set);
cAnalyzeGenotype(cWorld* world, const cGenome& _genome, cInstSet& in_inst_set);
- cAnalyzeGenotype(const cAnalyzeGenotype & _gen);
+ cAnalyzeGenotype(const cAnalyzeGenotype& _gen);
~cAnalyzeGenotype();
static void Initialize();
@@ -251,10 +258,10 @@
// Set...
void SetSequence(cString _sequence);
- void SetName(const cString & _name) { name = _name; }
+ void SetName(const cString& _name) { name = _name; }
void SetInstructionSet(cInstSet& _inst_set) { m_inst_set = _inst_set; }
void SetAlignedSequence(const cString & _seq) { aligned_sequence = _seq; }
- void SetTag(const cString & _tag) { tag = _tag; }
+ void SetTag(const cString& _tag) { tag = _tag; }
void SetViable(bool _viable) { viable = _viable; }
@@ -282,11 +289,6 @@
void SetParentMuts(const cString & in_muts) { parent_muts = in_muts; }
void SetTaskOrder(const cString & in_order) { task_order = in_order; }
-// void SetFracDead(double in_frac);
-// void SetFracNeg(double in_frac);
-// void SetFracNeut(double in_frac);
-// void SetFracPos(double in_frac);
-
// A set of NULL accessors to simplyfy automated accesses.
void SetNULL(int idx, int dummy) { (void) dummy; }
void SetNULL(int dummy) { (void) dummy; }
@@ -324,8 +326,7 @@
double GetMerit() const { return merit; }
double GetCompMerit() const { return merit / (double) GetMinLength(); }
int GetGestTime() const { return gest_time; }
- double GetEfficiency() const
- { return ((double) GetMinLength()) / (double) gest_time; }
+ double GetEfficiency() const { return ((double) GetMinLength()) / (double) gest_time; }
double GetFitness() const { return fitness; }
double GetDivType() const { return div_type; }
int GetMateID() const { return mate_id; }
@@ -394,18 +395,14 @@
if (args.HasString("binary")) return (task_counts[task_id] > 0);
return task_counts[task_id];
}
- const tArray<int>& GetTaskCounts() const {
- return task_counts;
- }
+ const tArray<int>& GetTaskCounts() const { return task_counts; }
cString DescTask(int task_id) const;
double GetTaskQuality(int task_id) const {
if (task_id >= task_counts.GetSize()) return 0;
return task_qualities[task_id];
}
- const tArray<double> & GetTaskQualities() const {
- return task_qualities;
- }
+ const tArray<double>& GetTaskQualities() const { return task_qualities; }
// number of different tasks performed
int GetTotalTaskCount() const {
@@ -440,78 +437,71 @@
// 0 : Identical in phenotype
// +1 : Improvement in phenotype
// +2 : Toggle; phenotype now present that wasn't.
- int CompareNULL(cAnalyzeGenotype * prev) const { (void) prev; return 0; }
- int CompareArgNULL(cAnalyzeGenotype * prev, int i) const
- { (void) prev; (void) i; return 0; }
- int CompareLength(cAnalyzeGenotype * prev) const {
- if (GetLength() < MIN_CREATURE_SIZE &&
- prev->GetLength() > MIN_CREATURE_SIZE) return -2;
- if (GetLength() > MIN_CREATURE_SIZE &&
- prev->GetLength() < MIN_CREATURE_SIZE) return 2;
+ int CompareNULL(cAnalyzeGenotype* prev) const { (void) prev; return 0; }
+ int CompareArgNULL(cAnalyzeGenotype* prev, int i) const { (void) prev; (void) i; return 0; }
+ int CompareLength(cAnalyzeGenotype* prev) const
+ {
+ if (GetLength() < MIN_CREATURE_SIZE && prev->GetLength() > MIN_CREATURE_SIZE) return -2;
+ if (GetLength() > MIN_CREATURE_SIZE && prev->GetLength() < MIN_CREATURE_SIZE) return 2;
return 0;
}
- int CompareMerit(cAnalyzeGenotype * prev) const
- { return NumCompare(GetMerit(), prev->GetMerit()); }
- int CompareCompMerit(cAnalyzeGenotype * prev) const
- { return NumCompare(GetCompMerit(), prev->GetCompMerit()); }
- int CompareGestTime(cAnalyzeGenotype * prev) const {
+ int CompareMerit(cAnalyzeGenotype * prev) const { return NumCompare(GetMerit(), prev->GetMerit()); }
+ int CompareCompMerit(cAnalyzeGenotype * prev) const { return NumCompare(GetCompMerit(), prev->GetCompMerit()); }
+ int CompareGestTime(cAnalyzeGenotype * prev) const
+ {
const int max_time = CalcMaxGestation();
const int cur_time = max_time - GetGestTime();
const int prev_time = max_time - prev->GetGestTime();
return NumCompare(cur_time, prev_time);
}
- int CompareEfficiency(cAnalyzeGenotype * prev) const
- { return NumCompare(GetEfficiency(), prev->GetEfficiency()); }
- int CompareFitness(cAnalyzeGenotype * prev) const
- { return NumCompare(GetFitness(), prev->GetFitness()); }
+ int CompareEfficiency(cAnalyzeGenotype * prev) const { return NumCompare(GetEfficiency(), prev->GetEfficiency()); }
+ int CompareFitness(cAnalyzeGenotype * prev) const { return NumCompare(GetFitness(), prev->GetFitness()); }
int CompareTaskCount(cAnalyzeGenotype * prev, int task_id) const
- { return NumCompare(GetTaskCount(task_id), prev->GetTaskCount(task_id)); }
+ {
+ return NumCompare(GetTaskCount(task_id), prev->GetTaskCount(task_id));
+ }
/*
added to satisfy Boost.Python; the semantics are fairly useless --
equality of two references means that they refer to the same object.
*/
- bool operator==(const cAnalyzeGenotype &in) const { return &in == this; }
+ bool operator==(const cAnalyzeGenotype& in) const { return &in == this; }
- cAnalyzeGenotypeLink &GetLink(){
- return m_link;
- }
- cAnalyzeGenotype *GetParent(){
- return GetLink().GetParent();
- }
- void LinkParent(cAnalyzeGenotype *parent){
- if(GetParent() && GetParent() != parent){
- GetParent()->GetLink().RemoveChild(this);
- }
+
+ cAnalyzeGenotypeLink& GetLink() { return m_link; }
+ cAnalyzeGenotype* GetParent() { return GetLink().GetParent(); }
+
+ void LinkParent(cAnalyzeGenotype *parent) {
+ if (GetParent() && GetParent() != parent) GetParent()->GetLink().RemoveChild(this);
GetLink().SetParent(parent);
- if(parent){
- parent->GetLink().AddChild(this);
- }
+ if (parent) parent->GetLink().AddChild(this);
}
- void LinkChild(cAnalyzeGenotype &child){
- child.LinkParent(this);
- }
- void UnlinkParent(){
- LinkParent(0);
- }
- tList<cAnalyzeGenotype> &GetChildList(){
- return GetLink().GetChildList();
- }
- void UnlinkChildren(){
+
+ void LinkChild(cAnalyzeGenotype &child) { child.LinkParent(this); }
+
+ void UnlinkParent() { LinkParent(0); }
+
+ tList<cAnalyzeGenotype>& GetChildList() { return GetLink().GetChildList(); }
+
+ void UnlinkChildren()
+ {
tListIterator<cAnalyzeGenotype> it(GetChildList());
while (it.Next() != NULL) {
it.Get()->UnlinkParent();
}
}
- void Unlink(){
+
+ void Unlink()
+ {
UnlinkParent();
UnlinkChildren();
}
- bool HasChild(cAnalyzeGenotype &child){
- return GetLink().FindChild(&child);
- }
- bool UnlinkChild(cAnalyzeGenotype &child){
- if(HasChild(child)){
+
+ bool HasChild(cAnalyzeGenotype &child) { return GetLink().FindChild(&child); }
+
+ bool UnlinkChild(cAnalyzeGenotype &child)
+ {
+ if(HasChild(child)) {
child.UnlinkParent();
return true;
} else {
Added: development/source/analyze/cGenotypeData.cc
===================================================================
--- development/source/analyze/cGenotypeData.cc (rev 0)
+++ development/source/analyze/cGenotypeData.cc 2009-01-10 22:01:46 UTC (rev 3097)
@@ -0,0 +1,28 @@
+/*
+ * cGenotypeData.cc
+ * Avida
+ *
+ * Created by David Bryson on 1/10/09.
+ * Copyright 2009 Michigan State University. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "cGenotypeData.h"
+
+cGenotypeData::~cGenotypeData() { ; }
+
Added: development/source/analyze/cGenotypeData.h
===================================================================
--- development/source/analyze/cGenotypeData.h (rev 0)
+++ development/source/analyze/cGenotypeData.h 2009-01-10 22:01:46 UTC (rev 3097)
@@ -0,0 +1,35 @@
+/*
+ * cGenotypeData.h
+ * Avida
+ *
+ * Created by David Bryson on 1/10/09.
+ * Copyright 2009 Michigan State University. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef cGenotypeData_h
+#define cGenotypeData_h
+
+class cGenotypeData
+{
+public:
+ cGenotypeData() { ; }
+ virtual ~cGenotypeData() = 0;
+};
+
+#endif
Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc 2009-01-10 16:17:26 UTC (rev 3096)
+++ development/source/main/cTaskLib.cc 2009-01-10 22:01:46 UTC (rev 3097)
@@ -1926,7 +1926,7 @@
const cString& string_to_match = ctx.GetTaskEntry()->GetArguments().GetString(0);
int partial = ctx.GetTaskEntry()->GetArguments().GetInt(0);
int binary = ctx.GetTaskEntry()->GetArguments().GetInt(1);
- double mypow = ctx.GetTaskEntry()->GetArguments().GetDouble(0);
+// double mypow = ctx.GetTaskEntry()->GetArguments().GetDouble(0);
int string_index;
int num_matched = 0;
int test_output;
More information about the Avida-cvs
mailing list