[Avida-SVN] r2584 - in branches/matt/FuncOverlap: Avida.xcodeproj source/actions source/classification source/main
matt at myxo.css.msu.edu
matt at myxo.css.msu.edu
Mon May 12 07:55:19 PDT 2008
Author: matt
Date: 2008-05-12 10:55:19 -0400 (Mon, 12 May 2008)
New Revision: 2584
Modified:
branches/matt/FuncOverlap/Avida.xcodeproj/project.pbxproj
branches/matt/FuncOverlap/source/actions/PrintActions.cc
branches/matt/FuncOverlap/source/classification/cGenotype.cc
branches/matt/FuncOverlap/source/classification/cGenotype.h
branches/matt/FuncOverlap/source/main/cAvidaConfig.h
branches/matt/FuncOverlap/source/main/cEnvironment.cc
branches/matt/FuncOverlap/source/main/cPhenPlastGenotype.cc
branches/matt/FuncOverlap/source/main/cPhenPlastGenotype.h
branches/matt/FuncOverlap/source/main/cPhenotype.cc
branches/matt/FuncOverlap/source/main/cPhenotype.h
branches/matt/FuncOverlap/source/main/cPopulation.cc
branches/matt/FuncOverlap/source/main/cReactionResult.cc
branches/matt/FuncOverlap/source/main/cReactionResult.h
branches/matt/FuncOverlap/source/main/cStats.cc
branches/matt/FuncOverlap/source/main/cStats.h
Log:
Switching URL
Modified: branches/matt/FuncOverlap/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/matt/FuncOverlap/Avida.xcodeproj/project.pbxproj 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/Avida.xcodeproj/project.pbxproj 2008-05-12 14:55:19 UTC (rev 2584)
@@ -1409,9 +1409,9 @@
70B0864F08F4972600FC65FE /* cMxCodeArray.h */,
70B0868708F49EA800FC65FE /* cOrganism.cc */,
70B0868308F49E9700FC65FE /* cOrganism.h */,
+ 70B0869C08F49F4800FC65FE /* cPhenotype.cc */,
42777E5B0C7F123600AFA4ED /* cOrgMessage.h */,
422B64520C8305C40012C545 /* cOrgMessagePredicate.h */,
- 70B0869C08F49F4800FC65FE /* cPhenotype.cc */,
70B0869B08F49F3900FC65FE /* cPhenotype.h */,
70B0868908F49EA800FC65FE /* cPopulation.cc */,
70B0868508F49E9700FC65FE /* cPopulation.h */,
Modified: branches/matt/FuncOverlap/source/actions/PrintActions.cc
===================================================================
--- branches/matt/FuncOverlap/source/actions/PrintActions.cc 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/actions/PrintActions.cc 2008-05-12 14:55:19 UTC (rev 2584)
@@ -2598,6 +2598,48 @@
};
+class cActionPrintFuncOverlapData : public cAction
+{
+private:
+ cString m_file_prefix;
+ bool m_obs_level_gen; //True = genome
+
+public:
+ cActionPrintFuncOverlapData(cWorld* world, const cString& args) : cAction(world, args)
+ {
+ cString largs(args);
+ m_file_prefix = (largs.GetSize()) ? largs.PopWord() : "func_overlap";
+ m_obs_level_gen = (largs.GetSize() && largs.PopWord().ToUpper() == "GEN") ? true : false;
+ }
+
+ static const cString GetDescription() { return "Arguments: file-prefix[=func_overlap], gen/org=[gen]";}
+
+ void Process(cAvidaContext& ctx)
+ {
+ if (ctx.GetAnalyzeMode()){ // We're in analyze mode
+ m_world->GetDriver().NotifyComment("cActionPrintFuncOverlapData: Not available in analyze mode.");
+ return;
+ }
+ else{ // We're in run mode
+ cString this_path = m_file_prefix + cString(m_world->GetStats().GetUpdate()) + cString(".dat");
+ ofstream& fot = m_world->GetDataFileOFStream(this_path);
+ tMatrix<int>& mtx = (m_obs_level_gen) ? m_world->GetStats().GetGenFuncOverlap() : m_world->GetStats().GetOrgFuncOverlap();
+ fot << "# Functional Overlap w/ Environmental Tasks (Cumulative, ObsLevel=";
+ if (m_obs_level_gen = true)
+ fot << "GENOTYPE";
+ else
+ fot << "ORGANISM";
+ fot << ")\n"
+ << "# Task.N (0..10%), [10..20%), [20,30%) ... [90,100%), [100%]" << endl;
+ for (int r = 0; r < mtx.GetNumRows(); r++){
+ fot << r << " ";
+ for (int c = 0; c < mtx.GetNumCols(); c++)
+ fot << mtx.ElementAt(r,c) << " ";
+ fot << endl;
+ }
+ }
+ }
+};
void RegisterPrintActions(cActionLibrary* action_lib)
@@ -2625,7 +2667,8 @@
action_lib->Register<cActionPrintSenseData>("PrintSenseData");
action_lib->Register<cActionPrintSenseExeData>("PrintSenseExeData");
action_lib->Register<cActionPrintSleepData>("PrintSleepData");
-
+ action_lib->Register<cActionPrintFuncOverlapData>("PrintFuncOverlapData");
+
// Population Out Files
action_lib->Register<cActionPrintPhenotypeData>("PrintPhenotypeData");
action_lib->Register<cActionPrintPhenotypeStatus>("PrintPhenotypeStatus");
Modified: branches/matt/FuncOverlap/source/classification/cGenotype.cc
===================================================================
--- branches/matt/FuncOverlap/source/classification/cGenotype.cc 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/classification/cGenotype.cc 2008-05-12 14:55:19 UTC (rev 2584)
@@ -55,6 +55,7 @@
, species(NULL)
, next(NULL)
, prev(NULL)
+ , m_func_overlap(NULL)
{
}
@@ -68,6 +69,9 @@
num_organisms = -1;
total_organisms = -1;
+ if (!m_func_overlap)
+ delete m_func_overlap;
+
next = NULL;
prev = NULL;
}
Modified: branches/matt/FuncOverlap/source/classification/cGenotype.h
===================================================================
--- branches/matt/FuncOverlap/source/classification/cGenotype.h 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/classification/cGenotype.h 2008-05-12 14:55:19 UTC (rev 2584)
@@ -103,6 +103,8 @@
cDoubleSum tmp_sum_merit;
cDoubleSum tmp_sum_fitness;
+ // @MRR Functional Overlap Tracking
+ tArray<double>* m_func_overlap; // Task functional overlap
void CalcTestStats(cAvidaContext& ctx) const;
@@ -233,6 +235,8 @@
int GetNumOrganisms() { return num_organisms; }
int GetTotalOrganisms() { return total_organisms; }
int GetTotalParasites() { return total_parasites; }
+
+ tArray<double>*& GetFuncOverlap() { return m_func_overlap; } // @MRR
};
Modified: branches/matt/FuncOverlap/source/main/cAvidaConfig.h
===================================================================
--- branches/matt/FuncOverlap/source/main/cAvidaConfig.h 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/main/cAvidaConfig.h 2008-05-12 14:55:19 UTC (rev 2584)
@@ -398,7 +398,10 @@
CONFIG_ADD_VAR(DONATE_THRESH_QUANTA, int, 10, "The size of steps between quanta donate thresholds");
CONFIG_ADD_VAR(MAX_DONATES, int, 1000000, "Limit on number of donates organisms are allowed.");
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(FUNC_OVERLAP_MODE, int, 0, "0 = Disabled\n 1=Do not reward functional overlap.");
+ CONFIG_ADD_VAR(FUNC_OVERLAP_TRIALS, int, 0, "0 = Disabled\nNumber of trials to test a genotype performing a new task for functional overlap.");
+
+
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");
CONFIG_ADD_VAR(THRESHOLD, int, 3, "Number of organisms in a genotype needed for it\n to be considered viable.");
Modified: branches/matt/FuncOverlap/source/main/cEnvironment.cc
===================================================================
--- branches/matt/FuncOverlap/source/main/cEnvironment.cc 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/main/cEnvironment.cc 2008-05-12 14:55:19 UTC (rev 2584)
@@ -885,9 +885,13 @@
// Mark this task as performed...
result.MarkTask(task_id, task_quality, taskctx.GetTaskValue());
+ double old_bonus = result.GetAddBonus() + result.GetMultBonus();
+
// And lets process it!
DoProcesses(ctx, cur_reaction->GetProcesses(), resource_count, task_quality, task_cnt, i, result);
+ result.AddTaskBonus(task_id, result.GetAddBonus() + result.GetMultBonus() - old_bonus);
+
// Mark this reaction as occuring...
result.MarkReaction(cur_reaction->GetID());
}
Modified: branches/matt/FuncOverlap/source/main/cPhenPlastGenotype.cc
===================================================================
--- branches/matt/FuncOverlap/source/main/cPhenPlastGenotype.cc 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/main/cPhenPlastGenotype.cc 2008-05-12 14:55:19 UTC (rev 2584)
@@ -23,19 +23,29 @@
*/
#include "cPhenPlastGenotype.h"
+#include "cEnvironment.h"
+
#include <iostream>
#include <cmath>
-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)
+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),
+m_phen_task(m_world->GetEnvironment().GetNumTasks()),
+m_task_prob(world->GetEnvironment().GetNumTasks())
{
cCPUTestInfo test_info;
test_info.UseRandomInputs(true);
Process(test_info, world, ctx);
}
-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)
+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),
+m_phen_task(m_world->GetEnvironment().GetNumTasks()),
+m_task_prob(world->GetEnvironment().GetNumTasks())
{
// Override input mode if more than one recalculation requested
if (num_trials > 1)
@@ -84,6 +94,9 @@
m_min_fit_freq = 0.0;
m_phenotypic_entropy = 0.0;
m_min_fitness = (*uit)->GetFitness();
+ m_phen_task.SetAll(0);
+ m_task_prob.SetAll(0.0);
+
while(uit != m_unique.end()){
cPlasticPhenotype* this_phen = static_cast<cPlasticPhenotype*>(*uit);
double fit = this_phen->GetFitness();
@@ -102,6 +115,13 @@
}
m_avg_fitness += freq * fit;
m_phenotypic_entropy -= freq * log(freq) / log(2.0);
+
+ for (int k = 0; k < m_world->GetEnvironment().GetNumTasks(); k++){
+ if (this_phen->GetLastTaskCount()[k] > 0){
+ m_phen_task[k]++;
+ m_task_prob[k] += freq;
+ }
+ }
++uit;
}
Modified: branches/matt/FuncOverlap/source/main/cPhenPlastGenotype.h
===================================================================
--- branches/matt/FuncOverlap/source/main/cPhenPlastGenotype.h 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/main/cPhenPlastGenotype.h 2008-05-12 14:55:19 UTC (rev 2584)
@@ -78,6 +78,8 @@
double m_max_fit_freq;
double m_min_fit_freq;
double m_min_fitness;
+ tArray<int> m_phen_task; // How many phenotypes are performing a task?
+ tArray<double> m_task_prob; // What is the probability of a phenotype performing a task?
void Process(cCPUTestInfo& test_info, cWorld* world, cAvidaContext& ctx);
@@ -97,6 +99,7 @@
double GetMaximumFrequency() const { return m_max_freq; }
double GetMaximumFitnessFrequency() const {return m_max_fit_freq;}
double GetMinimumFitnessFrequency() const {return m_min_fit_freq;}
+ tArray<double> GetTaskProbs() const {return m_task_prob;}
const cPlasticPhenotype* GetPlasticPhenotype(int num) const;
const cPlasticPhenotype* GetMostLikelyPhenotype() const;
const cPlasticPhenotype* GetHighestFitnessPhenotype() const;
Modified: branches/matt/FuncOverlap/source/main/cPhenotype.cc
===================================================================
--- branches/matt/FuncOverlap/source/main/cPhenotype.cc 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/main/cPhenotype.cc 2008-05-12 14:55:19 UTC (rev 2584)
@@ -43,6 +43,7 @@
: m_world(world)
, initialized(false)
, cur_task_count(m_world->GetEnvironment().GetNumTasks())
+ , cur_task_bonus(m_world->GetEnvironment().GetNumTasks())
, eff_task_count(m_world->GetEnvironment().GetNumTasks())
, cur_task_quality(m_world->GetEnvironment().GetNumTasks())
, cur_task_value(m_world->GetEnvironment().GetNumTasks())
@@ -59,6 +60,7 @@
, last_reaction_add_reward(m_world->GetEnvironment().GetReactionLib().GetSize())
, last_inst_count(world->GetHardwareManager().GetInstSet().GetSize())
, last_sense_count(m_world->GetStats().GetSenseSize())
+ , parent_task_count(m_world->GetEnvironment().GetNumTasks())
{
}
@@ -100,7 +102,8 @@
div_type = in_phen.div_type;
// 2. These are "in progress" variables, updated as the organism operates
- cur_bonus = in_phen.cur_bonus;
+ cur_bonus = in_phen.cur_bonus;
+ cur_task_bonus = in_phen.cur_task_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;
@@ -201,6 +204,7 @@
parent_true = in_phen.parent_true;
parent_sex = in_phen.parent_sex;
parent_cross_num = in_phen.parent_cross_num;
+ parent_task_count = in_phen.parent_task_count;
// 6. Child information...
copy_true = in_phen.copy_true;
@@ -278,6 +282,7 @@
// Initialize current values, as neeeded.
cur_bonus = m_world->GetConfig().DEFAULT_BONUS.Get();
+ cur_task_bonus.SetAll(0.0);
cur_energy_bonus = 0.0;
cur_num_errors = 0;
cur_num_donates = 0;
@@ -307,7 +312,7 @@
last_num_donates = parent_phenotype.last_num_donates;
last_task_count = parent_phenotype.last_task_count;
last_task_quality = parent_phenotype.last_task_quality;
- last_task_value = parent_phenotype.last_task_value;
+ last_task_value = parent_phenotype.last_task_value;
last_reaction_count = parent_phenotype.last_reaction_count;
last_reaction_add_reward = parent_phenotype.last_reaction_add_reward;
last_inst_count = parent_phenotype.last_inst_count;
@@ -372,6 +377,8 @@
parent_true = parent_phenotype.copy_true;
parent_sex = parent_phenotype.divide_sex;
parent_cross_num = parent_phenotype.cross_num;
+ parent_task_count = parent_phenotype.last_task_count;
+
to_die = false;
to_delete = false;
@@ -414,6 +421,7 @@
// Initialize current values, as neeeded.
cur_bonus = m_world->GetConfig().DEFAULT_BONUS.Get();
+ cur_task_bonus.SetAll(0.0);
cur_energy_bonus = 0.0;
cur_num_errors = 0;
cur_num_donates = 0;
@@ -505,6 +513,7 @@
parent_true = true;
parent_sex = false;
parent_cross_num = 0;
+ parent_task_count.SetAll(0);
to_die = false;
to_delete = false;
@@ -568,6 +577,7 @@
// Reset cur values.
cur_bonus = m_world->GetConfig().DEFAULT_BONUS.Get();
+ cur_task_bonus.SetAll(0.0);
cpu_cycles_used = 0;
cur_energy_bonus = 0.0;
cur_num_errors = 0;
@@ -710,6 +720,7 @@
// Reset cur values.
cur_bonus = m_world->GetConfig().DEFAULT_BONUS.Get();
+ cur_task_bonus.SetAll(0.0);
cpu_cycles_used = 0;
cur_num_errors = 0;
cur_num_donates = 0;
@@ -834,6 +845,7 @@
// Initialize current values, as neeeded.
cur_bonus = m_world->GetConfig().DEFAULT_BONUS.Get();
+ cur_task_bonus.SetAll(0.0);
cpu_cycles_used = 0;
cur_num_errors = 0;
cur_num_donates = 0;
@@ -925,6 +937,7 @@
parent_true = clone_phenotype.copy_true;
parent_sex = clone_phenotype.divide_sex;
parent_cross_num = clone_phenotype.cross_num;
+ parent_task_count = clone_phenotype.parent_task_count;
to_die = false;
to_delete = false;
@@ -978,6 +991,7 @@
return false; // Nothing happened.
}
+
// Update the phenotype with the results...
// Start with updating task and reaction counters
for (int i = 0; i < num_tasks; i++) {
@@ -998,6 +1012,7 @@
if (result.TaskQuality(i) > 0) cur_task_quality[i]+= result.TaskQuality(i) * refract_factor;
cur_task_value[i] = result.TaskValue(i);
cur_task_time[i] = cur_update_time; // Find out time from context
+ cur_task_bonus[i] += result.GetTaskBonus(i); // @MRR, the merit bonus received from performing this task
}
for (int i = 0; i < num_reactions; i++) {
@@ -1008,6 +1023,7 @@
// Update the merit bonus
cur_bonus *= result.GetMultBonus();
cur_bonus += result.GetAddBonus();
+
// Update the energy bonus
cur_energy_bonus += result.GetAddEnergy();
@@ -1129,6 +1145,9 @@
fp << parent_true << " ";
fp << parent_sex << " ";
fp << parent_cross_num << " ";
+ for (int i = 0; i < parent_task_count.GetSize(); i++) {
+ fp << parent_task_count[i] << " ";
+ }
fp << copy_true << " ";
fp << divide_sex << " ";
@@ -1237,7 +1256,10 @@
fp >> parent_true;
fp >> parent_sex;
fp >> parent_cross_num;
-
+ for (int i = 0; i < parent_task_count.GetSize(); i++) {
+ fp >> parent_task_count[i];
+ }
+
fp >> copy_true;
fp >> divide_sex;
fp >> mate_select_id;
@@ -1600,6 +1622,19 @@
if (m_world->GetConfig().GENERATION_INC_METHOD.Get() == GENERATION_INC_BOTH) generation++;
}
+
+void cPhenotype::SetCurTaskCount(int ndx, int value)
+{
+ assert(ndx < m_world->GetEnvironment().GetNumTasks());
+ cur_task_count[ndx] = value;
+}
+void cPhenotype::SetCurTaskBonus(int ndx, double value)
+{
+ assert(ndx < m_world->GetEnvironment().GetNumTasks());
+ cur_task_bonus[ndx] = value;
+};
+
+
// 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
Modified: branches/matt/FuncOverlap/source/main/cPhenotype.h
===================================================================
--- branches/matt/FuncOverlap/source/main/cPhenotype.h 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/main/cPhenotype.h 2008-05-12 14:55:19 UTC (rev 2584)
@@ -112,6 +112,7 @@
int cur_num_errors; // Total instructions executed illeagally.
int cur_num_donates; // Number of donations so far
tArray<int> cur_task_count; // Total times each task was performed
+ tArray<double> cur_task_bonus; // Bonuses received from each task
tArray<int> eff_task_count; // Total times each task was performed (resetable during the life of the organism)
tArray<double> cur_task_quality; // Average (total?) quality with which each task was performed
tArray<double> cur_task_value; // Value with which this phenotype performs task
@@ -203,7 +204,8 @@
bool parent_true; // Is this genome an exact copy of its parent's?
bool parent_sex; // Did the parent divide with sex?
int parent_cross_num; // How many corssovers did the parent do?
-
+ tArray<int> parent_task_count; //What tasks did the parent do?
+
// 6. Child information...
bool copy_true; // Can this genome produce an exact copy of itself?
bool divide_sex; // Was this child created with a sexual divide?
@@ -293,6 +295,7 @@
int GetCurNumErrors() const { assert(initialized == true); return cur_num_errors; }
int GetCurNumDonates() const { assert(initialized == true); return cur_num_donates; }
const tArray<int>& GetCurTaskCount() const { assert(initialized == true); return cur_task_count; }
+ const tArray<double>& GetCurTaskBonus() const { assert(initialized == true); return cur_task_bonus; }
void ClearEffTaskCount() { assert(initialized == true); eff_task_count.SetAll(0); }
const tArray<double> & GetCurTaskQuality() const { assert(initialized == true); return cur_task_quality; }
const tArray<double> & GetCurTaskValue() const { assert(initialized == true); return cur_task_value; }
@@ -402,7 +405,9 @@
void SetCrossNum(int _cross_num) { cross_num = _cross_num; }
void SetToDie() { to_die = true; }
void SetToDelete() { to_delete = true; }
-
+ void SetCurTaskCount(int ndx, int value);
+ void SetCurTaskBonus(int ndx, double value);
+
void SetIsDonorCur() { is_donor_cur = true; }
void SetIsDonorRand() { SetIsDonorCur(); is_donor_rand = true; }
void SetIsDonorKin() { SetIsDonorCur(); is_donor_kin = true; }
Modified: branches/matt/FuncOverlap/source/main/cPopulation.cc
===================================================================
--- branches/matt/FuncOverlap/source/main/cPopulation.cc 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/main/cPopulation.cc 2008-05-12 14:55:19 UTC (rev 2584)
@@ -45,6 +45,7 @@
#include "cLineage.h"
#include "cOrganism.h"
#include "cPhenotype.h"
+#include "cPhenPlastGenotype.h"
#include "cPopulationCell.h"
#include "cProbSchedule.h"
#include "cResource.h"
@@ -277,6 +278,62 @@
// This needs to be done before the parent goes into the birth chamber
// or the merit doesn't get passed onto the child correctly
cPhenotype& parent_phenotype = parent_organism.GetPhenotype();
+
+ //@MRR To remove functional overlap benefits, we're going to need
+ //to test new phenotypes a number of times through the test CPU
+ //to make sure they are not dependent on environmental inputs
+ //Execute only if this option is enabled.
+ //func_overlap_mode 0=Disabled, 1=Detect Only, 2=Remove Bonuses
+ int func_overlap_mode = m_world->GetConfig().FUNC_OVERLAP_MODE.Get();
+ int func_overlap_trials = m_world->GetConfig().FUNC_OVERLAP_TRIALS.Get();
+ if ( func_overlap_mode > 0 && func_overlap_trials > 0){
+ tArray<int> parent_tasks = parent_phenotype.GetCurTaskCount();
+ tArray<int> grandparent_tasks = parent_phenotype.GetLastTaskCount();
+ tArray<int> task_delta(m_world->GetEnvironment().GetNumTasks());
+ task_delta.SetAll(0);
+ bool new_tasks; //Do we have new tasks being performed?
+ for (int k = 0; k < parent_tasks.GetSize(); k++){
+ if (parent_tasks[k] && !grandparent_tasks[k]){
+ task_delta[k] = 1;
+ new_tasks = true;
+ }
+ }
+ if (new_tasks){
+ tArray<int> task_undos(m_world->GetEnvironment().GetNumTasks());
+ task_undos.SetAll(0);
+ bool undo_tasks = false; //Do we need to remove task bonuses?
+ cPhenPlastGenotype ppg(parent_organism.GetGenome(), m_world->GetConfig().FUNC_OVERLAP_TRIALS.Get(), m_world, ctx);
+ tArray<double> task_probs = ppg.GetTaskProbs();
+ for (int k = 0; k < task_delta.GetSize(); k++){
+ if (task_delta[k] && task_probs[k] < 1.0){
+ task_undos[k] = 1;
+ undo_tasks = true;
+ }
+ }
+
+ //If this organism is the first of its genotype to demonstrate new tasks, record it
+ if (parent_organism.GetGenotype()->GetFuncOverlap() == NULL){
+ parent_organism.GetGenotype()->GetFuncOverlap() = new tArray<double>(task_probs); //cGenotype responsible for deleting
+ m_world->GetStats().IncGenFuncOverlap(task_probs);
+ }
+ m_world->GetStats().IncOrgFuncOverlap(task_probs);
+
+ if (undo_tasks && func_overlap_mode > 1){ //If we are actually going to undo merit bonuses
+ double remove_bonus = 0.0;
+ tArray<double> task_bonuses = parent_phenotype.GetCurTaskBonus();
+ for (int k = 0; k < task_undos.GetSize(); k++)
+ if (task_undos[k]){
+ remove_bonus += task_bonuses[k];
+ parent_phenotype.SetCurTaskCount(k,0);
+ parent_phenotype.SetCurTaskBonus(k,0);
+ }
+ parent_phenotype.SetCurBonus( parent_phenotype.GetCurBonus() - remove_bonus);
+
+ assert(parent_phenotype.GetCurBonus() >= 0.0);
+ }
+ }
+ }
+
parent_phenotype.DivideReset(parent_organism.GetGenome());
birth_chamber.SubmitOffspring(ctx, child_genome, parent_organism, child_array, merit_array);
Modified: branches/matt/FuncOverlap/source/main/cReactionResult.cc
===================================================================
--- branches/matt/FuncOverlap/source/main/cReactionResult.cc 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/main/cReactionResult.cc 2008-05-12 14:55:19 UTC (rev 2584)
@@ -35,6 +35,7 @@
, tasks_done(num_tasks)
, tasks_quality(num_tasks)
, tasks_value(num_tasks)
+ , task_reward_bonus(num_tasks)
, reactions_triggered(num_reactions)
, reaction_add_bonus(num_reactions)
, energy_add(0.0)
@@ -58,6 +59,7 @@
tasks_done.SetAll(false);
tasks_quality.SetAll(0.0);
tasks_value.SetAll(0.0);
+ task_reward_bonus.SetAll(0.0);
reactions_triggered.SetAll(false);
reaction_add_bonus.SetAll(0.0);
@@ -181,3 +183,13 @@
return tasks_value[id];
}
+double cReactionResult::GetTaskBonus(int id)
+{
+ if (GetActive() == false) return 0.0;
+ return task_reward_bonus[id];
+}
+
+void cReactionResult::AddTaskBonus(int id, double bonus)
+{
+ task_reward_bonus[id] += bonus;
+}
Modified: branches/matt/FuncOverlap/source/main/cReactionResult.h
===================================================================
--- branches/matt/FuncOverlap/source/main/cReactionResult.h 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/main/cReactionResult.h 2008-05-12 14:55:19 UTC (rev 2584)
@@ -38,9 +38,10 @@
tArray<bool> tasks_done;
tArray<double> tasks_quality;
tArray<double> tasks_value;
- tArray<bool> reactions_triggered;
- tArray<double> reaction_add_bonus;
- double energy_add;
+ tArray<double> task_reward_bonus;
+ tArray<bool> reactions_triggered;
+ tArray<double> reaction_add_bonus;
+ double energy_add;
double bonus_add;
double bonus_mult;
tArray<int> insts_triggered;
@@ -85,6 +86,9 @@
double GetReactionAddBonus(const int i) { return reaction_add_bonus[i]; }
double GetMultBonus() { return bonus_mult; }
tArray<int>& GetInstArray() { return insts_triggered; }
+
+ double GetTaskBonus(int id);
+ void AddTaskBonus(int id, double bonus);
};
Modified: branches/matt/FuncOverlap/source/main/cStats.cc
===================================================================
--- branches/matt/FuncOverlap/source/main/cStats.cc 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/main/cStats.cc 2008-05-12 14:55:19 UTC (rev 2584)
@@ -137,6 +137,13 @@
task_last_max_quality.SetAll(0);
task_exe_count.SetAll(0);
+ //@MRR Functional Overlap
+ org_func_overlap_tasks.Resize(num_tasks, 11);
+ org_func_overlap_tasks.SetAll(0);
+ gen_func_overlap_tasks.Resize(num_tasks, 11);
+ gen_func_overlap_tasks.SetAll(0);
+
+
#if INSTRUCTION_COUNT
sum_exe_inst_array.Resize(m_world->GetNumInstructions());
ZeroInst();
@@ -1080,3 +1087,11 @@
}
df.Endl();
}
+
+void cStats::IncGenFuncOverlap(const tArray<double>& p)
+{
+}
+
+void cStats::IncOrgFuncOverlap(const tArray<double>& p)
+{
+}
Modified: branches/matt/FuncOverlap/source/main/cStats.h
===================================================================
--- branches/matt/FuncOverlap/source/main/cStats.h 2008-05-08 18:00:40 UTC (rev 2583)
+++ branches/matt/FuncOverlap/source/main/cStats.h 2008-05-12 14:55:19 UTC (rev 2584)
@@ -52,6 +52,9 @@
#ifndef tDataManager_h
#include "tDataManager.h"
#endif
+#ifndef tMatrix_h
+#include "tMatrix.h"
+#endif
#ifndef nGeometry_h
#include "nGeometry.h"
#endif
@@ -236,6 +239,11 @@
int num_resamplings;
int num_failedResamplings;
+ // Functional Overlap @MRR
+ // Total number of organisms with functional overlap detected
+ tMatrix<int> org_func_overlap_tasks; // num_tasks x [<=10%, (10,20%] ... 100%]
+ // Total number of genomes with functional overlap detected
+ tMatrix<int> gen_func_overlap_tasks;
// State variables
int last_update;
@@ -418,6 +426,11 @@
void IncResamplings() { ++num_resamplings; } // @AWC 06/29/06
void IncFailedResamplings() { ++num_failedResamplings; } // @AWC 06/29/06
+ void IncGenFuncOverlap(const tArray<double>& task_probs); // @MRR
+ void IncOrgFuncOverlap(const tArray<double>& task_probs); // @MRR
+ tMatrix<int>& GetGenFuncOverlap() {return gen_func_overlap_tasks;} // @MRR
+ tMatrix<int>& GetOrgFuncOverlap() {return org_func_overlap_tasks;} // @MRR
+
void CalcEnergy();
void CalcFidelity();
More information about the Avida-cvs
mailing list