[Avida-SVN] r1871 - in development: . Avida.xcodeproj source/analyze source/main
matt at myxo.css.msu.edu
matt at myxo.css.msu.edu
Mon Jul 30 17:17:09 PDT 2007
Author: matt
Date: 2007-07-30 20:17:09 -0400 (Mon, 30 Jul 2007)
New Revision: 1871
Added:
development/source/main/cPhenPlastGenotype.cc
development/source/main/cPhenPlastGenotype.h
development/source/main/cPlasticPhenotype.cc
development/source/main/cPlasticPhenotype.h
Modified:
development/Avida.xcodeproj/project.pbxproj
development/CMakeLists.txt
development/source/analyze/cAnalyze.cc
development/source/analyze/cAnalyze.h
development/source/main/cPhenotype.cc
development/source/main/cPhenotype.h
Log:
Added basic support for plastic phenotype analysis.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2007-07-30 19:23:18 UTC (rev 1870)
+++ development/Avida.xcodeproj/project.pbxproj 2007-07-31 00:17:09 UTC (rev 1871)
@@ -194,6 +194,8 @@
70D046610C32EA90000614E7 /* cBirthChamber.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 702D4F3908DA61E2007BA469 /* cBirthChamber.h */; };
70DCAC9C097AF7C0002F8733 /* primitive.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCAC9B097AF7C0002F8733 /* primitive.cc */; };
70F9FC100C469DD70083B788 /* cASTDumpVisitor.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70F9FC0F0C469DC10083B788 /* cASTDumpVisitor.cc */; };
+ B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */; };
+ B4FA25A90C5EB7880086D4B5 /* cPhenPlastGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
@@ -813,6 +815,10 @@
70F9FC0F0C469DC10083B788 /* cASTDumpVisitor.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cASTDumpVisitor.cc; sourceTree = "<group>"; };
70F9FD990C4E89C40083B788 /* tAutoRelease.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tAutoRelease.h; sourceTree = "<group>"; };
70FB86A908BFAFEC00BDF589 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
+ B4FA25800C5EB6510086D4B5 /* cPhenPlastGenotype.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cPhenPlastGenotype.h; sourceTree = "<group>"; };
+ B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPlasticPhenotype.cc; sourceTree = "<group>"; };
+ B4FA25820C5EB6510086D4B5 /* cPlasticPhenotype.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cPlasticPhenotype.h; sourceTree = "<group>"; };
+ B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPhenPlastGenotype.cc; sourceTree = "<group>"; };
DCC30FCF0762539D008F7A48 /* Doxyfile */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = Doxyfile; sourceTree = "<group>"; };
DCC3109C0762539E008F7A48 /* avida.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = avida.cc; sourceTree = "<group>"; };
DCC31547076253A4008F7A48 /* cCycleCheck.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cCycleCheck.cc; sourceTree = "<group>"; };
@@ -1358,6 +1364,10 @@
DCC310040762539D008F7A48 /* main */ = {
isa = PBXGroup;
children = (
+ B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */,
+ B4FA25800C5EB6510086D4B5 /* cPhenPlastGenotype.h */,
+ B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */,
+ B4FA25820C5EB6510086D4B5 /* cPlasticPhenotype.h */,
42490EFE0BE2472800318058 /* cGermline.h */,
706C6F480B83E69D003174C1 /* cSaleItem.h */,
708BF3010AB65DD300A923BF /* cEventList.h */,
@@ -1941,6 +1951,8 @@
7023ECA10C0A431B00362B9C /* SaveLoadActions.cc in Sources */,
70436B280C36C64400A05ABA /* cThread.cc in Sources */,
70436B6C0C36C98900A05ABA /* PlatformExpert.cc in Sources */,
+ B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */,
+ B4FA25A90C5EB7880086D4B5 /* cPhenPlastGenotype.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: development/CMakeLists.txt
===================================================================
--- development/CMakeLists.txt 2007-07-30 19:23:18 UTC (rev 1870)
+++ development/CMakeLists.txt 2007-07-31 00:17:09 UTC (rev 1871)
@@ -219,6 +219,8 @@
${MAIN_DIR}/cMxCodeArray.cc
${MAIN_DIR}/cOrganism.cc
${MAIN_DIR}/cPhenotype.cc
+ ${MAIN_DIR}/cPhenPlastGenotype.cc
+ ${MAIN_DIR}/cPlasticPhenotype.cc
${MAIN_DIR}/cPopulation.cc
${MAIN_DIR}/cPopulationCell.cc
${MAIN_DIR}/cPopulationInterface.cc
Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc 2007-07-30 19:23:18 UTC (rev 1870)
+++ development/source/analyze/cAnalyze.cc 2007-07-31 00:17:09 UTC (rev 1871)
@@ -54,6 +54,8 @@
#include "cInstSet.h"
#include "cLandscape.h"
#include "cPhenotype.h"
+#include "cPhenPlastGenotype.h"
+#include "cPlasticPhenotype.h"
#include "cProbSchedule.h"
#include "cSchedule.h"
#include "cSpecies.h"
@@ -7031,6 +7033,24 @@
}
+void cAnalyze::CommandAnalyzePlasticity(cString cur_string)
+{
+ tListIterator<cAnalyzeGenotype> batch_it(batch[cur_batch].List());
+ cAnalyzeGenotype* genotype;
+ while ( (genotype = batch_it.Next()) != NULL ){
+ cerr << "Using Genome: " << genotype->GetGenome().AsString() << endl;
+ cPhenPlastGenotype PPG(genotype->GetGenome(), 1000, m_world, m_ctx);
+ cerr << "There are " << PPG.GetNumPhenotypes() << " phenotype(s) for this genome.\n";
+ for (int k = 0; k < PPG.GetNumPhenotypes(); k++)
+ cerr << "\t Phenotype " << k << " has fitness " << PPG.GetPlasticPhenotype(k).GetFitness()
+ << " with frequency " << PPG.GetPlasticPhenotype(k).GetFrequency() << endl;
+ cerr << endl;
+ }
+ cerr << "here" << endl;
+
+}
+
+
//////////////// Control...
void cAnalyze::VarSet(cString cur_string)
@@ -8173,6 +8193,9 @@
}
+
+
+
void cAnalyze::AddLibraryDef(const cString & name,
void (cAnalyze::*_fun)(cString))
{
@@ -8239,7 +8262,8 @@
AddLibraryDef("ANALYZE_KNOCKOUTS", &cAnalyze::AnalyzeKnockouts);
AddLibraryDef("ANALYZE_POP_COMPLEXITY", &cAnalyze::AnalyzePopComplexity);
AddLibraryDef("MAP_DEPTH", &cAnalyze::CommandMapDepth);
- AddLibraryDef("PAIRWISE_ENTROPY", &cAnalyze::CommandPairwiseEntropy); //@MRR
+ // (Untested) AddLibraryDef("PAIRWISE_ENTROPY", &cAnalyze::CommandPairwiseEntropy);
+ AddLibraryDef("ANALYZE_PLASTICITY", &cAnalyze::CommandAnalyzePlasticity);
// Population comparison commands...
AddLibraryDef("HAMMING", &cAnalyze::CommandHamming);
Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h 2007-07-30 19:23:18 UTC (rev 1870)
+++ development/source/analyze/cAnalyze.h 2007-07-31 00:17:09 UTC (rev 1871)
@@ -250,6 +250,7 @@
void CommandMapMutations(cString cur_string);
void CommandMapDepth(cString cur_string);
void CommandPairwiseEntropy(cString cur_string);
+ void CommandAnalyzePlasticity(cString cur_string);
// Population Comparison Commands...
void CommandHamming(cString cur_string);
Added: development/source/main/cPhenPlastGenotype.cc
===================================================================
--- development/source/main/cPhenPlastGenotype.cc (rev 0)
+++ development/source/main/cPhenPlastGenotype.cc 2007-07-31 00:17:09 UTC (rev 1871)
@@ -0,0 +1,66 @@
+/*
+ * cPhenPlastGenotype.cpp
+ * Avida
+ *
+ * Created by Matthew Rupp on 7/29/07.
+ * Copyright 1999-2007 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 "cPhenPlastGenotype.h"
+#include <iostream>
+
+cPhenPlastGenotype::cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cWorld* world, cAvidaContext& ctx)
+: m_genome(in_genome), m_num_trials(num_trials), m_world(world)
+{
+ cTestCPU* test_cpu = m_world->GetHardwareManager().CreateTestCPU();
+ for (int k = 0; k < m_num_trials; k++){
+ cCPUTestInfo test_info;
+ test_info.UseRandomInputs(true);
+ test_cpu->TestGenome(ctx, test_info, m_genome);
+
+ //Is this a new phenotype?
+ UniquePhenotypes::iterator uit = m_unique.find(&test_info.GetTestPhenotype());
+ if (uit == m_unique.end()){ // Yes, make a new entry for it
+ cPlasticPhenotype* new_phen = new cPlasticPhenotype(test_info, m_num_trials);
+ m_unique.insert( static_cast<cPhenotype*>(new_phen) );
+ } else{ // No, add an observation to existing entry, make sure it is equivalent
+ assert( static_cast<cPlasticPhenotype*>((*uit))->AddObservation(test_info) );
+ }
+ }
+ delete test_cpu;
+}
+
+cPhenPlastGenotype::~cPhenPlastGenotype()
+{
+ UniquePhenotypes::iterator it = m_unique.begin();
+ while (it != m_unique.end()){
+ delete *it;
+ ++it;
+ }
+}
+
+
+cPlasticPhenotype cPhenPlastGenotype::GetPlasticPhenotype(int num) const
+{
+ assert(num >= 0 && num < (int) m_unique.size());
+ UniquePhenotypes::iterator it = m_unique.begin();
+ for (int k = 0; k < num; k++, it++);
+ return *static_cast<cPlasticPhenotype*>(*it);
+}
+
Added: development/source/main/cPhenPlastGenotype.h
===================================================================
--- development/source/main/cPhenPlastGenotype.h (rev 0)
+++ development/source/main/cPhenPlastGenotype.h 2007-07-31 00:17:09 UTC (rev 1871)
@@ -0,0 +1,75 @@
+/*
+* cPhenPlastGenotype.h
+* Avida
+*
+* Created by Matthew Rupp on 7/27/07.
+*/
+
+
+#ifndef cPhenPlastGenotype_h
+#define cPhenPlastGenotype_h
+
+#include <set>
+#include <utility>
+
+#ifndef functions_h
+#include "functions.h"
+#endif
+#ifndef cCPUMemory_h
+#include "cCPUMemory.h"
+#endif
+#ifndef cGenome_h
+#include "cGenome.h"
+#endif
+#ifndef cString_h
+#include "cString.h"
+#endif
+#ifndef cStringList_h
+#include "cStringList.h"
+#endif
+#ifndef cStringUtil_h
+#include "cStringUtil.h"
+#endif
+#ifndef tArray_h
+#include "tArray.h"
+#endif
+#ifndef cPlasticPhenotype_h
+#include "cPlasticPhenotype.h"
+#endif
+#ifndef cPhenotype_h
+#include "cPhenotype.h"
+#endif
+#ifndef cHardwareManager_h
+#include "cHardwareManager.h"
+#endif
+
+class cAvidaContext;
+class cTestCPU;
+class cWorld;
+
+/**
+ * This class examines a genotype for evidence of phenotypic plasticity.
+**/
+
+
+class cPhenPlastGenotype
+{
+ private:
+
+ typedef set<cPhenotype*, cPhenotype::lt_phenotype > UniquePhenotypes; //Actually, these are cPlasticPhenotype*
+ cGenome m_genome;
+ int m_num_trials;
+ UniquePhenotypes m_unique;
+ cWorld* m_world;
+
+ public:
+ cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cWorld* world, cAvidaContext& ctx);
+ ~cPhenPlastGenotype();
+
+ int GetNumPhenotypes() const { return m_unique.size(); }
+ cPlasticPhenotype GetPlasticPhenotype(int num) const;
+
+};
+
+#endif
+
Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc 2007-07-30 19:23:18 UTC (rev 1870)
+++ development/source/main/cPhenotype.cc 2007-07-31 00:17:09 UTC (rev 1871)
@@ -32,6 +32,7 @@
#include "cTaskState.h"
#include "cTools.h"
#include "cWorld.h"
+#include "tList.h"
#include <fstream>
@@ -70,6 +71,155 @@
for (int i = 0; i < task_states.GetSize(); i++) delete task_states[i];
}
+
+cPhenotype::cPhenotype(const cPhenotype& in_phen)
+{
+ *this = in_phen;
+}
+
+
+cPhenotype& cPhenotype::operator=(const cPhenotype& in_phen)
+{
+
+ m_world = in_phen.m_world;
+ initialized = in_phen.initialized;
+
+
+ // 1. These are values calculated at the last divide (of self or offspring)
+ merit = in_phen.merit;
+ energy_store = in_phen.energy_store;
+ energy_tobe_applied = in_phen.energy_tobe_applied;
+ genome_length = in_phen.genome_length;
+ bonus_instruction_count = in_phen.bonus_instruction_count;
+ copied_size = in_phen.copied_size;
+ executed_size = in_phen.executed_size;
+ gestation_time = in_phen.gestation_time;
+
+ gestation_start = in_phen.gestation_start;
+ fitness = in_phen.fitness;
+ div_type = in_phen.div_type;
+
+ // 2. These are "in progress" variables, updated as the organism operates
+ cur_bonus = in_phen.cur_bonus;
+ cur_energy_bonus = in_phen.cur_energy_bonus;
+ cur_num_errors = in_phen.cur_num_errors;
+ cur_num_donates = in_phen.cur_num_donates;
+ cur_task_count = in_phen.cur_task_count;
+ eff_task_count = in_phen.eff_task_count;
+ cur_task_quality = in_phen.cur_task_quality;
+ cur_task_value = in_phen.cur_task_value;
+ cur_reaction_count = in_phen.cur_reaction_count;
+ cur_reaction_add_reward = in_phen.cur_reaction_add_reward;
+ cur_inst_count = in_phen.cur_inst_count;
+ cur_sense_count = in_phen.cur_sense_count;
+ sensed_resources = in_phen.sensed_resources;
+ cur_task_time = in_phen.cur_task_time;
+ active_transposons = in_phen.active_transposons;
+ base_promoter_weights = in_phen.base_promoter_weights;
+ cur_promoter_weights = in_phen.cur_promoter_weights;
+ promoter_activation = in_phen.promoter_activation;
+ promoter_repression = in_phen.promoter_repression;
+ promoter_last_inst_terminated = in_phen.promoter_last_inst_terminated;
+
+ // Dynamically allocated m_task_states requires special handling
+ tList<cTaskState*> hash_values;
+ tList<void*> hash_keys;
+ in_phen.m_task_states.AsLists(hash_keys, hash_values);
+ tListIterator<cTaskState*> vit(hash_values);
+ tListIterator<void*> kit(hash_keys);
+ while(vit.Next() && kit.Next())
+ {
+ cTaskState* new_ts = new cTaskState(**(vit.Get()));
+ m_task_states.Add(*(kit.Get()), new_ts);
+ }
+
+ // 3. These mark the status of "in progess" variables at the last divide.
+ last_merit_base = in_phen.last_merit_base;
+ last_bonus = in_phen.last_bonus;
+ last_energy_bonus = in_phen.last_energy_bonus;
+ last_num_errors = in_phen.last_num_errors;
+ last_num_donates = in_phen.last_num_donates;
+ last_task_count = in_phen.last_task_count;
+ last_task_quality = in_phen.last_task_quality;
+ last_task_value = in_phen.last_task_value;
+ last_reaction_count = in_phen.last_reaction_count;
+ last_reaction_add_reward = in_phen.last_reaction_add_reward;
+ last_inst_count = in_phen.last_inst_count;
+ last_sense_count = in_phen.last_sense_count;
+ last_fitness = in_phen.last_fitness;
+
+ // 4. Records from this organisms life...
+ num_divides = in_phen.num_divides;
+ generation = in_phen.generation;
+ cpu_cycles_used = in_phen.cpu_cycles_used;
+ time_used = in_phen.time_used;
+ age = in_phen.age;
+ fault_desc = in_phen.fault_desc;
+ neutral_metric = in_phen.neutral_metric;
+ life_fitness = in_phen.life_fitness;
+
+
+ // 5. Status Flags... (updated at each divide)
+ to_die = in_phen.to_die;
+ to_delete = in_phen.to_delete;
+ is_injected = in_phen.is_injected;
+ is_donor_cur = in_phen.is_donor_cur;
+ is_donor_last = in_phen.is_donor_last;
+ is_donor_rand = in_phen.is_donor_rand;
+ is_donor_rand_last = in_phen.is_donor_rand_last;
+ is_donor_null = in_phen.is_donor_null;
+ is_donor_null_last = in_phen.is_donor_null_last;
+ is_donor_kin = in_phen.is_donor_kin;
+ is_donor_kin_last = in_phen.is_donor_kin_last;
+ is_donor_edit = in_phen.is_donor_edit;
+ is_donor_edit_last = in_phen.is_donor_edit_last;
+ is_donor_gbg = in_phen.is_donor_gbg;
+ is_donor_gbg_last = in_phen.is_donor_gbg_last;
+ is_donor_truegb = in_phen.is_donor_truegb;
+ is_donor_truegb_last = in_phen.is_donor_truegb_last;
+ is_donor_threshgb = in_phen.is_donor_threshgb;
+ is_donor_threshgb_last = in_phen.is_donor_threshgb_last;
+ is_donor_quanta_threshgb = in_phen.is_donor_quanta_threshgb;
+ is_donor_quanta_threshgb_last = in_phen.is_donor_quanta_threshgb_last;
+ num_thresh_gb_donations = in_phen.num_thresh_gb_donations;
+ num_thresh_gb_donations_last = in_phen.num_thresh_gb_donations_last;
+ num_quanta_thresh_gb_donations = in_phen.num_quanta_thresh_gb_donations;
+ num_quanta_thresh_gb_donations_last = in_phen.num_quanta_thresh_gb_donations_last;
+ is_receiver = in_phen.is_receiver;
+ is_receiver_last = in_phen.is_receiver_last;
+ is_receiver_rand = in_phen.is_receiver_rand;
+ is_receiver_kin = in_phen.is_receiver_kin;
+ is_receiver_kin_last = in_phen.is_receiver_kin_last;
+ is_receiver_edit = in_phen.is_receiver_edit;
+ is_receiver_edit_last = in_phen.is_receiver_edit_last;
+ is_receiver_gbg = in_phen.is_receiver_gbg;
+ is_receiver_truegb = in_phen.is_receiver_truegb;
+ is_receiver_truegb_last = in_phen.is_receiver_truegb_last;
+ is_receiver_threshgb = in_phen.is_receiver_threshgb;
+ is_receiver_threshgb_last = in_phen.is_receiver_threshgb_last;
+ is_receiver_quanta_threshgb = in_phen.is_receiver_quanta_threshgb;
+ is_receiver_quanta_threshgb_last = in_phen.is_receiver_quanta_threshgb_last;
+ is_modifier = in_phen.is_modifier;
+ is_modified = in_phen.is_modified;
+ is_fertile = in_phen.is_fertile;
+ is_mutated = in_phen.is_mutated;
+ is_multi_thread = in_phen.is_multi_thread;
+ parent_true = in_phen.parent_true;
+ parent_sex = in_phen.parent_sex;
+ parent_cross_num = in_phen.parent_cross_num;
+
+ // 6. Child information...
+ copy_true = in_phen.copy_true;
+ divide_sex = in_phen.divide_sex;
+ mate_select_id = in_phen.mate_select_id;
+ cross_num = in_phen.cross_num;
+ child_fertile = in_phen.child_fertile;
+ last_child_fertile = in_phen.last_child_fertile;
+ child_copied_size = in_phen.child_copied_size;
+
+ return *this;
+}
+
bool cPhenotype::OK()
{
assert(genome_length >= 0);
@@ -1275,3 +1425,62 @@
cur_promoter_weights[i] = base_promoter_weights[i] * exp((1+promoter_activation[i])*log(2.0)) / exp((1+promoter_repression[i])*log(2.0));
}
+
+
+// C O M P A R I S O N O P E R A T O R S
+
+bool cPhenotype::operator<(const cPhenotype& rhs) const
+{
+ if (this->GetMerit() < rhs.GetMerit())
+ return true;
+
+ if ( this->GetGestationTime() < rhs.GetGestationTime() )
+ return true;
+
+ tArray<int> lhsTasks = this->GetCurTaskCount();
+ tArray<int> rhsTasks = rhs.GetCurTaskCount();
+ for (int k = 0; k < lhsTasks.GetSize(); k++)
+ if (lhsTasks[k] < rhsTasks[k])
+ return true;
+
+ return false;
+}
+
+bool cPhenotype::operator==(const cPhenotype& rhs) const
+{
+ if (this->GetMerit() != rhs.GetMerit())
+ return false;
+
+ if ( this->GetGestationTime() != rhs.GetGestationTime() )
+ return false;
+
+ tArray<int> lhsTasks = this->GetCurTaskCount();
+ tArray<int> rhsTasks = rhs.GetCurTaskCount();
+ for (int k = 0; k < lhsTasks.GetSize(); k++)
+ if (lhsTasks[k] != rhsTasks[k])
+ return false;
+
+ return true;
+}
+
+bool cPhenotype::operator!=(const cPhenotype& rhs) const
+{
+ return !(*this == rhs);
+}
+
+bool cPhenotype::operator>(const cPhenotype& rhs) const
+{
+ if (this->GetMerit() > rhs.GetMerit())
+ return true;
+
+ if ( this->GetGestationTime() > rhs.GetGestationTime() )
+ return true;
+
+ tArray<int> lhsTasks = this->GetCurTaskCount();
+ tArray<int> rhsTasks = rhs.GetCurTaskCount();
+ for (int k = 0; k < lhsTasks.GetSize(); k++)
+ if (lhsTasks[k] > rhsTasks[k])
+ return true;
+
+ return false;
+}
Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h 2007-07-30 19:23:18 UTC (rev 1870)
+++ development/source/main/cPhenotype.h 2007-07-31 00:17:09 UTC (rev 1871)
@@ -217,9 +217,11 @@
cPhenotype(); // @not_implemented
- cPhenotype(const cPhenotype&); // @not_implemented
- cPhenotype& operator=(const cPhenotype&); // @not_implemented
+protected:
+ cPhenotype(const cPhenotype&);
+ cPhenotype& operator=(const cPhenotype&);
+
public:
cPhenotype(cWorld* world);
~cPhenotype();
@@ -453,6 +455,17 @@
void RefreshEnergy();
void ApplyToEnergyStore();
double ExtractParentEnergy();
+
+ bool operator<(const cPhenotype& rhs) const;
+ bool operator>(const cPhenotype& rhs) const;
+ bool operator==(const cPhenotype& rhs) const;
+ bool operator!=(const cPhenotype& rhs) const;
+
+ struct lt_phenotype{
+ bool operator()(const cPhenotype* lhs, const cPhenotype* rhs)
+ {return *lhs < *rhs;} // operator< in cPhenotype
+ };
+
};
Added: development/source/main/cPlasticPhenotype.cc
===================================================================
--- development/source/main/cPlasticPhenotype.cc (rev 0)
+++ development/source/main/cPlasticPhenotype.cc 2007-07-31 00:17:09 UTC (rev 1871)
@@ -0,0 +1,56 @@
+/*
+ * cPlasticCPUTestInfo.cpp
+ * Avida
+ *
+ * Created by Matthew Rupp on 7/27/07
+ * Copyright 1999-2007 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 "cPlasticPhenotype.h"
+
+
+bool cPlasticPhenotype::AddObservation( const cPhenotype& in_phen, const tArray<int>& env_inputs )
+{
+ if (in_phen == *this){
+ if (m_num_observations == 0)
+ m_env_inputs.Resize(1, env_inputs.GetSize());
+ else
+ m_env_inputs.Resize(m_env_inputs.GetNumRows()+1, env_inputs.GetSize());
+ m_env_inputs[m_env_inputs.GetNumRows()-1] = env_inputs;
+ m_num_observations++;
+ return true;
+ }
+ return false; //Wrong phenotype
+}
+
+bool cPlasticPhenotype::AddObservation( cCPUTestInfo& test_info )
+{
+ tArray<int> env_inputs = test_info.GetTestCPUInputs();
+ cPhenotype& test_phenotype = test_info.GetTestPhenotype();
+ if (test_phenotype == *this ){
+ if (m_num_observations == 0)
+ m_env_inputs.Resize(1, env_inputs.GetSize());
+ else
+ m_env_inputs.Resize(m_env_inputs.GetNumRows()+1, env_inputs.GetSize());
+ m_env_inputs[m_env_inputs.GetNumRows()-1] = env_inputs;
+ m_num_observations++;
+ return true;
+ }
+ return false; //Wrong phenotype
+}
Added: development/source/main/cPlasticPhenotype.h
===================================================================
--- development/source/main/cPlasticPhenotype.h (rev 0)
+++ development/source/main/cPlasticPhenotype.h 2007-07-31 00:17:09 UTC (rev 1871)
@@ -0,0 +1,74 @@
+/*
+ * cPlasticCPUTestInfo.h
+ * Avida
+ *
+ * Created by Matthew Rupp on 7/27/07.
+ * Copyright 1999-2007 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 cPlasticCPUTestInfo
+#define cPlasticCPUTestInfo
+
+
+#include <cassert>
+
+#ifndef cCPUTestInfo_h
+#include "cCPUTestInfo.h"
+#endif
+
+#ifndef cPhenotype_h
+#include "cPhenotype.h"
+#endif
+
+#ifndef tMatrix_h
+#include "tMatrix.h"
+#endif
+
+
+#include <iostream>
+
+class cPlasticPhenotype : public cPhenotype{
+
+ private:
+ int m_num_observations;
+ int m_num_trials;
+ tMatrix<int> m_env_inputs;
+
+ public:
+ cPlasticPhenotype(cCPUTestInfo& test_info, int num_trials) :
+ cPhenotype(test_info.GetTestPhenotype()), m_num_observations(1), m_num_trials(num_trials) { assert(m_num_trials > 0); }
+
+ ~cPlasticPhenotype() { ; }
+
+ //Modifiers
+ bool AddObservation( const cPhenotype& in_phen, const tArray<int>& env_inputs );
+ bool AddObservation( cCPUTestInfo& test_info );
+
+ //Accessors
+ int GetNumObservations() const { return m_num_observations; }
+ int GetNumTrials() const { return m_num_trials; }
+ double GetFrequency() const { return static_cast<double>(m_num_observations) / m_num_trials; }
+ tMatrix<int> GetEnvInputs() const { return m_env_inputs; }
+
+
+
+};
+
+#endif
+
More information about the Avida-cvs
mailing list