[Avida-SVN] r3220 - in development: . Avida.xcodeproj documentation source source/analyze source/classification source/cpu source/main
ruppmatt at myxo.css.msu.edu
ruppmatt at myxo.css.msu.edu
Thu Apr 30 12:54:38 PDT 2009
Author: ruppmatt
Date: 2009-04-30 15:54:38 -0400 (Thu, 30 Apr 2009)
New Revision: 3220
Modified:
development/Avida.xcodeproj/project.pbxproj
development/CMakeLists.txt
development/documentation/environment.html
development/source/analyze/cAnalyzeGenotype.cc
development/source/analyze/cAnalyzeGenotype.h
development/source/classification/cGenotype.cc
development/source/classification/cGenotype.h
development/source/cpu/cTestCPU.cc
development/source/defs.h
development/source/main/cAvidaConfig.h
development/source/main/cAvidaContext.h
development/source/main/cEnvironment.cc
development/source/main/cEnvironment.h
development/source/main/cPhenPlastGenotype.cc
development/source/main/cPhenotype.cc
development/source/main/cPhenotype.h
development/source/main/cReactionProcess.h
development/source/main/cReactionResult.h
Log:
Adding phenotypic plasticity (task/function overlap) experiment-time features to the environment.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/Avida.xcodeproj/project.pbxproj 2009-04-30 19:54:38 UTC (rev 3220)
@@ -228,6 +228,7 @@
70DCAC9C097AF7C0002F8733 /* primitive.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCAC9B097AF7C0002F8733 /* primitive.cc */; };
70E60C4B0EC0088300718740 /* cGenotypeBatch.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70E60C4A0EC0088300718740 /* cGenotypeBatch.cc */; };
70EFD6600D975B6E00FAD32A /* cConstBurstSchedule.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70EFD65F0D975B5E00FAD32A /* cConstBurstSchedule.cc */; };
+ B462B5C10FA0F47D00F379D1 /* cPhenPlastSummary.h in Headers */ = {isa = PBXBuildFile; fileRef = B462B5C00FA0F47D00F379D1 /* cPhenPlastSummary.h */; };
B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */; };
B4FA25A90C5EB7880086D4B5 /* cPhenPlastGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */; };
B516AF840C91E2D400023D53 /* cDemeCellEvent.cc in Sources */ = {isa = PBXBuildFile; fileRef = B516AF790C91E24600023D53 /* cDemeCellEvent.cc */; };
@@ -912,6 +913,7 @@
70F7DE76092967A8009E311D /* cGenotypeBatch.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cGenotypeBatch.h; 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>"; };
+ B462B5C00FA0F47D00F379D1 /* cPhenPlastSummary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cPhenPlastSummary.h; 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>"; };
@@ -1059,6 +1061,7 @@
70422A1B091B141000A5E67F /* analyze */ = {
isa = PBXGroup;
children = (
+ B462B5C00FA0F47D00F379D1 /* cPhenPlastSummary.h */,
7076FEB40D347FEC00556CAF /* cAnalyzeTreeStats_CumulativeStemminess.h */,
7076FEB50D347FEC00556CAF /* cAnalyzeTreeStats_Gamma.h */,
7076FEAE0D347FD000556CAF /* cAnalyzeTreeStats_CumulativeStemminess.cc */,
@@ -1800,6 +1803,7 @@
70447CA30F83DB2900E1BF72 /* cBirthGenomeSizeHandler.h in Headers */,
70447CA70F83DB5600E1BF72 /* cBirthMateSelectHandler.h in Headers */,
70447CAB0F83DBC100E1BF72 /* cBirthDemeHandler.h in Headers */,
+ B462B5C10FA0F47D00F379D1 /* cPhenPlastSummary.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: development/CMakeLists.txt
===================================================================
--- development/CMakeLists.txt 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/CMakeLists.txt 2009-04-30 19:54:38 UTC (rev 3220)
@@ -136,6 +136,7 @@
${ANALYZE_DIR}/cGenotypeData.cc
${ANALYZE_DIR}/cModularityAnalysis.cc
${ANALYZE_DIR}/cMutationalNeighborhood.cc
+ ${ANALYZE_DIR}/cPhenPlastSummary.h
)
SOURCE_GROUP(analyze FILES ${ANALYZE_SOURCES})
LIST(APPEND AVIDA_CORE_SOURCES ${ANALYZE_SOURCES})
Modified: development/documentation/environment.html
===================================================================
--- development/documentation/environment.html 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/documentation/environment.html 2009-04-30 19:54:38 UTC (rev 3220)
@@ -557,13 +557,13 @@
Determines how to apply the bonus (i.e. the amount of the resource
absorbed times the value of this process) to change the merit of the
organism.
- <br /><em>add</em>: Directly add the bonus to the current merit.
- <br /><em>mult</em>: Multiply the current merit by the bonus (warning: if
+ <br /> <em>add</em>: Directly add the bonus to the current merit.
+ <br /> <em>mult</em>: Multiply the current merit by the bonus (warning: if
the bonus is ever less than one, this will be detrimental!)
- <br /><em>pow</em>: Multiply the current merit by 2<sup>bonus</sup>.
+ <br /> <em>pow</em>: Multiply the current merit by 2<sup>bonus</sup>.
this is effectively multiplicative, but positive bonuses are
always beneficial, and negative bonuses are harmful.
- <br /><em>enzyme</em>: Add bonus * resource / (resource + frac) to the current merit.
+ <br /> <em>enzyme</em>: Add bonus * resource / (resource + frac) to the current merit.
This is gives a Michaelis-Menten enzyme type reward where bonus is the K<sub>cat</sub>
and frac is the K<sub>m</sub>. Does not work with unlimited resources.
</td>
@@ -622,6 +622,24 @@
</td>
<td>true</td>
</tr>
+<tr>
+ <td class="resall">phenplastbonus</td>
+ <td>
+ Specify how to handle phenotypic plasticity at run-time.
+ This option may significantly slow an Avida experiment.
+ When requested in many of the settings below (*), task
+ bonuses will be adjusted by the plasticity
+ of each organism's genotype. Requisites will still be
+ honored, making true task completion information ambiguous.
+ <br /> <em>default</em>: Do not attempt to use the genotype's task plasticity.
+ <br /> *<em>nobonus</em>: Do not give a bonus to non-static tasks.
+ <br /> *<em>fracbonus</em>: Scale the bonus by how static the task is.
+ <br /> *<em>fullbonus</em>: Always reward a task when it is detected.
+ </td>
+ <td>
+ default
+ </td>
+</tr>
</table>
<p> </p>
</div>
Modified: development/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- development/source/analyze/cAnalyzeGenotype.cc 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/analyze/cAnalyzeGenotype.cc 2009-04-30 19:54:38 UTC (rev 3220)
@@ -193,10 +193,8 @@
knockout_stats = new cAnalyzeKnockouts;
*knockout_stats = *(_gen.knockout_stats);
}
- if (_gen.m_phenplast_stats != NULL){
- m_phenplast_stats = new cAnalyzePhenPlast;
- *m_phenplast_stats = *(_gen.m_phenplast_stats);
- }
+ if (_gen.m_phenplast_stats != NULL)
+ m_phenplast_stats = new cPhenPlastSummary(*_gen.m_phenplast_stats);
}
cAnalyzeGenotype::~cAnalyzeGenotype()
@@ -562,29 +560,11 @@
test_info.SetInstSet(&m_inst_set);
cPhenPlastGenotype pp(genome, 1000, test_info, m_world, m_world->GetDefaultContext());
- SummarizePhenotypicPlasticity(pp);
+ m_phenplast_stats = new cPhenPlastSummary(pp);
}
}
-void cAnalyzeGenotype::SummarizePhenotypicPlasticity(const cPhenPlastGenotype& pp) const
-{
- if (m_phenplast_stats == NULL){
- m_phenplast_stats = new cAnalyzePhenPlast;
- }
- m_phenplast_stats->m_recalculate_trials = pp.GetNumTrials();
- m_phenplast_stats->m_max_fitness = pp.GetMaximumFitness();
- m_phenplast_stats->m_avg_fitness = pp.GetAverageFitness();
- m_phenplast_stats->m_min_fitness = pp.GetMinimumFitness();
- m_phenplast_stats->m_phenotypic_entropy = pp.GetPhenotypicEntropy();
- m_phenplast_stats->m_likely_frequency = pp.GetMaximumFrequency();
- m_phenplast_stats->m_max_fit_frequency = pp.GetMaximumFitnessFrequency();
- m_phenplast_stats->m_min_fit_frequency = pp.GetMinimumFitnessFrequency();
- m_phenplast_stats->m_likely_fitness = pp.GetLikelyFitness();
- m_phenplast_stats->m_num_phenotypes = pp.GetNumPhenotypes();
- m_phenplast_stats->m_task_probabilities = pp.GetTaskProbabilities();
- m_phenplast_stats->m_viable_probability = pp.GetViableProbability();
-}
void cAnalyzeGenotype::CalcLandscape(cAvidaContext& ctx)
{
@@ -593,6 +573,7 @@
m_land->Process(ctx);
}
+
void cAnalyzeGenotype::Recalculate(cAvidaContext& ctx, cCPUTestInfo* test_info, cAnalyzeGenotype* parent_genotype, int num_trials)
{
// Allocate our own test info if it wasn't provided
@@ -642,7 +623,11 @@
}
// Summarize plasticity information if multiple recalculations performed
- if (num_trials > 1) SummarizePhenotypicPlasticity(recalc_data);
+ if (num_trials > 1){
+ if (m_phenplast_stats != NULL)
+ delete m_phenplast_stats;
+ m_phenplast_stats = new cPhenPlastSummary(recalc_data);
+ }
}
Modified: development/source/analyze/cAnalyzeGenotype.h
===================================================================
--- development/source/analyze/cAnalyzeGenotype.h 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/analyze/cAnalyzeGenotype.h 2009-04-30 19:54:38 UTC (rev 3220)
@@ -70,8 +70,10 @@
#ifndef tRCPtr_h
#include "tRCPtr.h"
#endif
+#ifndef cPhenPlastSummary_h
+#include "cPhenPlastSummary.h"
+#endif
-
// cAnalyzeGenotype : Collection of information about loaded genotypes
class cAvidaContext;
@@ -214,22 +216,7 @@
// Group 6: Phenotypic Plasticity
- class cAnalyzePhenPlast{
- public:
- int m_recalculate_trials;
- int m_num_phenotypes;
- double m_min_fitness;
- double m_max_fitness;
- double m_avg_fitness;
- double m_likely_fitness;
- double m_phenotypic_entropy;
- double m_likely_frequency;
- double m_min_fit_frequency;
- double m_max_fit_frequency;
- double m_viable_probability;
- tArray<double> m_task_probabilities;
- };
- mutable cAnalyzePhenPlast* m_phenplast_stats;
+ mutable cPhenPlastSummary* m_phenplast_stats;
int NumCompare(double new_val, double old_val) const {
if (new_val == old_val) return 0;
Modified: development/source/classification/cGenotype.cc
===================================================================
--- development/source/classification/cGenotype.cc 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/classification/cGenotype.cc 2009-04-30 19:54:38 UTC (rev 3220)
@@ -34,6 +34,9 @@
#include "cTestCPU.h"
#include "cTools.h"
#include "cWorld.h"
+#include "cPhenPlastGenotype.h"
+#include "cPhenPlastSummary.h"
+#include "cAvidaConfig.h"
using namespace std;
@@ -49,6 +52,7 @@
, symbol(0)
, map_color_id(-2)
, birth_data(in_update_born)
+ , m_phenplast(NULL)
, num_organisms(0)
, last_num_organisms(0)
, total_organisms(0)
@@ -71,6 +75,10 @@
next = NULL;
prev = NULL;
+
+ if (m_phenplast != NULL)
+ delete m_phenplast;
+
}
bool cGenotype::SaveClone(ofstream& fp)
@@ -218,6 +226,20 @@
}
+double cGenotype::GetTaskPlasticity(cAvidaContext& ctx, int task_id) const{
+ if (m_phenplast == NULL)
+ TestPlasticity(ctx);
+ assert(task_id >= 0 && task_id < m_phenplast->m_task_probabilities.GetSize());
+ return m_phenplast->m_task_probabilities[task_id];
+}
+
+void cGenotype::TestPlasticity(cAvidaContext& ctx) const{
+ cCPUTestInfo test_info;
+ cPhenPlastGenotype pp(genome, m_world->GetConfig().GENOTYPE_PHENPLAST_CALC.Get(), test_info, m_world, ctx);
+ m_phenplast = new cPhenPlastSummary(pp);
+}
+
+
int cGenotype::GetPhyloDistance(cGenotype * test_genotype)
{
if (GetID() == test_genotype->GetID()) {
Modified: development/source/classification/cGenotype.h
===================================================================
--- development/source/classification/cGenotype.h 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/classification/cGenotype.h 2009-04-30 19:54:38 UTC (rev 3220)
@@ -26,6 +26,7 @@
#ifndef cGenotype_h
#define cGenotype_h
+#include <cassert>
#include <fstream>
#ifndef cDoubleSum_h
#include "cDoubleSum.h"
@@ -43,10 +44,12 @@
#include "cString.h"
#endif
+
class cAvidaContext;
class cMerit;
class cSpecies;
class cWorld;
+class cPhenPlastSummary;
class cGenotype {
private:
@@ -69,7 +72,8 @@
mutable cGenotype_TestData test_data;
cGenotype_BirthData birth_data;
-
+ mutable cPhenPlastSummary* m_phenplast;
+
// Statistical info
int num_organisms;
@@ -136,6 +140,9 @@
inline int GetTestCopiedSize(cAvidaContext& ctx) const;
inline double GetTestColonyFitness(cAvidaContext& ctx) const;
inline int GetTestGenerations(cAvidaContext& ctx) const;
+ double GetTaskPlasticity(cAvidaContext& ctx, int task_id) const;
+
+ void TestPlasticity(cAvidaContext& ctx) const;
void SetParent(cGenotype* parent, cGenotype* parent2);
void SetName(cString in_name) { name = in_name; }
Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/cpu/cTestCPU.cc 2009-04-30 19:54:38 UTC (rev 3220)
@@ -212,16 +212,19 @@
bool cTestCPU::TestGenome(cAvidaContext& ctx, cCPUTestInfo& test_info, const cGenome& genome)
{
+ ctx.SetTestMode();
test_info.Clear();
cMetaGenome mg(m_world->GetConfig().HARDWARE_TYPE.Get(), 1, genome); // @TODO - fix test cpu metagenome handling
TestGenome_Body(ctx, test_info, mg, 0);
-
+ ctx.ClearTestMode();
+
return test_info.is_viable;
}
bool cTestCPU::TestGenome(cAvidaContext& ctx, cCPUTestInfo& test_info, const cGenome& genome,
ofstream& out_fp)
{
+ ctx.SetTestMode();
test_info.Clear();
cMetaGenome mg(m_world->GetConfig().HARDWARE_TYPE.Get(), 1, genome); // @TODO - fix test cpu metagenome handling
TestGenome_Body(ctx, test_info, mg, 0);
@@ -249,6 +252,7 @@
<< test_info.max_cycle << " "
<< repro_type << endl;
+ ctx.ClearTestMode();
return test_info.is_viable;
}
Modified: development/source/defs.h
===================================================================
--- development/source/defs.h 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/defs.h 2009-04-30 19:54:38 UTC (rev 3220)
@@ -172,6 +172,14 @@
INST_CODE_INSTNUM
};
+
+enum ePHENPLAST_BONUS_METHOD{
+ DEFAULT = 0,
+ NO_BONUS,
+ FRAC_BONUS,
+ FULL_BONUS
+};
+
enum eVerbosity {
VERBOSE_SILENT = 0, // No output at all
VERBOSE_NORMAL, // Notification at start of commands.
@@ -181,4 +189,6 @@
};
+
+
#endif
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/main/cAvidaConfig.h 2009-04-30 19:54:38 UTC (rev 3220)
@@ -458,6 +458,7 @@
CONFIG_ADD_VAR(PRECALC_PHENOTYPE, int, 0, "0 = Disabled\n 1 = Assign precalculated merit at birth (unlimited resources only)\n 2 = Assign precalculated gestation time\n 3 = Assign precalculated merit AND gestation time.\nFitness will be evaluated for organism based on these settings.");
CONFIG_ADD_VAR(FASTFORWARD_UPDATES, int, 0, "Fast-forward if the average generation has not changed in this many updates. (0 = off)");
CONFIG_ADD_VAR(FASTFORWARD_NUM_ORGS, int, 0, "Fast-forward if population is equal to this");
+ CONFIG_ADD_VAR(GENOTYPE_PHENPLAST_CALC, int, 100, "Number of times to calculate a genotype's\nplasticity during runtime.");
CONFIG_ADD_GROUP(GENEOLOGY_GROUP, "Geneology");
CONFIG_ADD_VAR(TRACK_MAIN_LINEAGE, int, 1, "Keep all ancestors of the active population?\n0=no, 1=yes, 2=yes,w/sexual population");
Modified: development/source/main/cAvidaContext.h
===================================================================
--- development/source/main/cAvidaContext.h 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/main/cAvidaContext.h 2009-04-30 19:54:38 UTC (rev 3220)
@@ -46,10 +46,11 @@
private:
cRandom* m_rng;
bool m_analyze;
+ bool m_testing;
public:
- cAvidaContext(cRandom& rng) : m_rng(&rng), m_analyze(false) { ; }
- cAvidaContext(cRandom* rng) : m_rng(rng), m_analyze(false) { ; }
+ cAvidaContext(cRandom& rng) : m_rng(&rng), m_analyze(false), m_testing(false) { ; }
+ cAvidaContext(cRandom* rng) : m_rng(rng), m_analyze(false), m_testing(false) { ; }
~cAvidaContext() { ; }
void SetRandom(cRandom& rng) { m_rng = &rng; }
@@ -59,6 +60,10 @@
void SetAnalyzeMode() { m_analyze = true; }
void ClearAnalyzeMode() { m_analyze = false; }
bool GetAnalyzeMode() { return m_analyze; }
+
+ void SetTestMode() { m_testing = true; } //@MRR Some modifications I've made need to distinguish
+ void ClearTestMode() { m_testing = false; } // when we're running a genotype through a test-cpu
+ bool GetTestMode() { return m_testing; } // versus when we're not when dealing with reactions rewards.
};
#endif
Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/main/cEnvironment.cc 2009-04-30 19:54:38 UTC (rev 3220)
@@ -50,6 +50,8 @@
#include "cWorld.h"
#include "tAutoRelease.h"
+#include "cOrganism.h"
+#include "cGenotype.h"
#include <iostream>
#include <algorithm>
@@ -253,7 +255,19 @@
return false;
new_process->SetDepletable(var_value.AsInt());
}
-
+ else if (var_name == "phenplastbonus") {
+ if (var_value == "nobonus")
+ new_process->SetPhenPlastBonusMethod(NO_BONUS);
+ else if (var_value == "fracbonus")
+ new_process->SetPhenPlastBonusMethod(FRAC_BONUS);
+ else if (var_value == "fullbonus")
+ new_process->SetPhenPlastBonusMethod(FULL_BONUS);
+ else if (var_value == "default")
+ new_process->SetPhenPlastBonusMethod(DEFAULT);
+ else
+ cerr << "Error: invalid setting for phenplastbonus "
+ << "in reaction '" << reaction->GetName() << "'" << endl;
+ }
else {
cerr << "Error: Unknown process variable '" << var_name
<< "' in reaction '" << reaction->GetName() << "'" << endl;
@@ -1045,19 +1059,27 @@
continue;
}
+
const double task_quality = m_tasklib.TestOutput(taskctx);
assert(task_quality >= 0.0);
+
+ // If this task wasn't performed, move on to the next one.
+ // @MRR task_probability will be either the probability [0,1] for the task or it will
+ // be -1.0 if the value is not needed for this reaction.
+ bool force_mark_task = false; //@MRR Some phenplastbonus settings will force a task to be counted even if it isn't demonstrated.
+ double task_probability = GetTaskProbability(ctx, taskctx, cur_reaction->GetProcesses(), force_mark_task);
- // If this task wasn't performed, move on to the next one.
- if (task_quality == 0.0) continue;
+ if (task_quality == 0.0 && !force_mark_task) continue;
// Mark this task as performed...
result.MarkTask(task_id, task_quality, taskctx.GetTaskValue());
// And let's process it!
- DoProcesses(ctx, cur_reaction->GetProcesses(), resource_count, rbins_count, task_quality, task_cnt, i, result);
+ DoProcesses(ctx, cur_reaction->GetProcesses(), resource_count, rbins_count,
+ task_quality, task_probability, task_cnt, i, result);
+
// Note: the reaction is actually marked as being performed inside DoProcesses.
}
@@ -1066,6 +1088,8 @@
+
+
bool cEnvironment::TestRequisites(const tList<cReactionRequisite>& req_list,
int task_count, const tArray<int>& reaction_count, const bool on_divide) const
{
@@ -1124,9 +1148,40 @@
}
+
+
+double cEnvironment::GetTaskProbability(cAvidaContext& ctx, cTaskContext& taskctx,
+ const tList<cReactionProcess>& req_proc, bool& force_mark_task) const
+{
+ force_mark_task = false;
+ if (ctx.GetTestMode()) //If we're in test-cpu mode, do not do this.
+ return -1.0;
+
+ double task_prob = -1.0;
+ tLWConstListIterator<cReactionProcess> proc_it(req_proc);
+ cReactionProcess* cur_proc;
+ bool test_plasticity = false;
+ while ( (cur_proc = proc_it.Next()) != NULL){ //Determine whether or not we need to test for plastcity
+ ePHENPLAST_BONUS_METHOD pp_meth = cur_proc->GetPhenPlastBonusMethod();
+ if (pp_meth != DEFAULT){ //DEFAULT doesn't modify bonuses
+ test_plasticity = true;
+ if (pp_meth == FULL_BONUS || pp_meth == FRAC_BONUS) //These will require us to force a task to be marked
+ force_mark_task = true;
+ }
+ }
+ if (test_plasticity){ //We have to test for plasticity, so try to get it
+ int task_id = taskctx.GetTaskEntry()->GetID();
+ task_prob = taskctx.GetOrganism()->GetGenotype()->GetTaskPlasticity(ctx,task_id);
+ }
+ force_mark_task = force_mark_task && (task_prob > 0.0); //If the task isn't demonstrated, we don't need to worry about marking it.
+ return task_prob;
+}
+
+
+
void cEnvironment::DoProcesses(cAvidaContext& ctx, const tList<cReactionProcess>& process_list,
const tArray<double>& resource_count, const tArray<double>& rbins_count,
- const double task_quality, const int task_count,
+ const double task_quality, const double task_probability, const int task_count,
const int reaction_id, cReactionResult& result) const
{
const int num_process = process_list.GetSize();
@@ -1138,13 +1193,22 @@
const double max_consumed = cur_process->GetMaxNumber();
const double min_consumed = cur_process->GetMinNumber();
+ ePHENPLAST_BONUS_METHOD pp_meth = cur_process->GetPhenPlastBonusMethod();
+ const double task_plasticity_modifier =
+ (pp_meth == NO_BONUS) ? 0.0 :
+ (pp_meth == FRAC_BONUS) ? task_probability : 1.0;
+
+ //Phenplast full bonus will use a 1.0 task quality
+ const double local_task_quality =
+ (pp_meth == FULL_BONUS || pp_meth == FRAC_BONUS) ? 1.0 : task_quality;
+
// Determine resource consumption
double consumed = 0.0;
cResource* in_resource = cur_process->GetResource();
if (in_resource == NULL) {
// Test if infinite resource
- consumed = max_consumed * task_quality;
+ consumed = max_consumed * local_task_quality * task_plasticity_modifier;
} else {
// Otherwise we're using a finite resource
const int res_id = in_resource->GetID();
@@ -1183,8 +1247,8 @@
if (consumed > max_consumed) consumed = max_consumed;
// Multiply by task_quality
- assert((task_quality >= 0.0) && (task_quality <= 1.0));
- consumed *= task_quality; // modify consumed based on task quality
+ assert((local_task_quality >= 0.0) && (local_task_quality <= 1.0));
+ consumed = consumed * local_task_quality * task_plasticity_modifier; // modify consumed based on task quality and plasticity
// Test if we are below the minimum consumption.
if (consumed < min_consumed) consumed = 0.0;
Modified: development/source/main/cEnvironment.h
===================================================================
--- development/source/main/cEnvironment.h 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/main/cEnvironment.h 2009-04-30 19:54:38 UTC (rev 3220)
@@ -115,11 +115,15 @@
bool LoadSetActive(cString desc);
+ double GetTaskProbability(cAvidaContext& ctx, cTaskContext& taskctx,
+ const tList<cReactionProcess>& req_proc, bool& force_mark_task) const;
+
bool TestRequisites(const tList<cReactionRequisite>& req_list, int task_count,
const tArray<int>& reaction_count, const bool on_divide = false) const;
void DoProcesses(cAvidaContext& ctx, const tList<cReactionProcess>& process_list,
const tArray<double>& resource_count, const tArray<double>& rbin_count,
- const double task_quality, const int task_count, const int reaction_id,
+ const double task_quality, const double task_probability,
+ const int task_count, const int reaction_id,
cReactionResult& result) const;
cEnvironment(); // @not_implemented
Modified: development/source/main/cPhenPlastGenotype.cc
===================================================================
--- development/source/main/cPhenPlastGenotype.cc 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/main/cPhenPlastGenotype.cc 2009-04-30 19:54:38 UTC (rev 3220)
@@ -25,6 +25,7 @@
#include "cPhenPlastGenotype.h"
#include <iostream>
#include <cmath>
+#include <cfloat>
cPhenPlastGenotype::cPhenPlastGenotype(const cGenome& in_genome, int num_trials, cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx)
: m_genome(in_genome), m_num_trials(num_trials), m_world(world)
@@ -78,7 +79,7 @@
m_min_fit_freq = 0.0;
m_phenotypic_entropy = 0.0;
m_viable_probability = 0.0;
- m_min_fitness = (*uit)->GetFitness();
+ m_min_fitness = DBL_MAX;
while(uit != m_unique.end()){
cPlasticPhenotype* this_phen = static_cast<cPlasticPhenotype*>(*uit);
double fit = this_phen->GetFitness();
Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/main/cPhenotype.cc 2009-04-30 19:54:38 UTC (rev 3220)
@@ -1127,6 +1127,7 @@
{
cur_task_count[i]++;
eff_task_count[i]++;
+ //cerr << "eff: " << eff_task_count[i] << endl;
if(result.UsedEnvResource() == false) { cur_internal_task_count[i]++; }
}
Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/main/cPhenotype.h 2009-04-30 19:54:38 UTC (rev 3220)
@@ -83,6 +83,7 @@
template <class T> class tList;
class cTaskContext;
class cTaskState;
+class cPhenPlastSummary;
class cPhenotype
{
Modified: development/source/main/cReactionProcess.h
===================================================================
--- development/source/main/cReactionProcess.h 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/main/cReactionProcess.h 2009-04-30 19:54:38 UTC (rev 3220)
@@ -42,6 +42,8 @@
class cResource;
+
+
class cReactionProcess {
private:
cResource* resource; // Resource consumed.
@@ -61,6 +63,7 @@
bool depletable; // Does completing consume resource?
// (This is not quite redundant with an infinite resource
// because it allows the resource level to be sensed @JEB)
+ ePHENPLAST_BONUS_METHOD m_ppmethod; //@MRR How does one handle phenotypically plastic tasks?
// Resource detection
cResource * detect; // Resource Measured
@@ -87,6 +90,7 @@
, is_germline(false)
, inst_id(-1)
, depletable(true)
+ , m_ppmethod(DEFAULT)
, detect(NULL)
, detection_threshold(0.0)
, detection_error(0.0)
@@ -107,6 +111,7 @@
bool GetLethal() const { return lethal; }
bool GetSterilize() const { return sterilize; }
double GetDemeFraction() const { return deme_fraction; }
+ ePHENPLAST_BONUS_METHOD GetPhenPlastBonusMethod() const { return m_ppmethod; }
bool GetIsGermline() const { return is_germline; }
cResource* GetDetect() const { return detect; }
double GetDetectionThreshold() const { return detection_threshold; }
@@ -127,6 +132,7 @@
void SetSterile(int _in) { sterilize = _in; }
void SetDemeFraction(double _in) { assert(_in>=0.0); assert(_in<=1.0); deme_fraction = _in; }
void SetIsGermline(bool _in) { is_germline = _in; }
+ void SetPhenPlastBonusMethod(ePHENPLAST_BONUS_METHOD _in) { m_ppmethod = _in; }
void SetDetect(cResource* _in) { detect = _in; }
void SetDetectionThreshold(double _in) { detection_threshold = _in; }
void SetDetectionError(double _in) { detection_error = _in; }
Modified: development/source/main/cReactionResult.h
===================================================================
--- development/source/main/cReactionResult.h 2009-04-24 18:33:51 UTC (rev 3219)
+++ development/source/main/cReactionResult.h 2009-04-30 19:54:38 UTC (rev 3220)
@@ -41,6 +41,7 @@
tArray<double> tasks_value;
tArray<bool> reactions_triggered;
tArray<double> reaction_add_bonus;
+ tArray<double> task_plasticity;
double energy_add;
double bonus_add;
double bonus_mult;
More information about the Avida-cvs
mailing list