[Avida-SVN] r3359 - in branches/goings: source/classification source/main source/tools support/config
goingssh at myxo.css.msu.edu
goingssh at myxo.css.msu.edu
Wed Aug 5 11:40:40 PDT 2009
Author: goingssh
Date: 2009-08-05 14:40:40 -0400 (Wed, 05 Aug 2009)
New Revision: 3359
Modified:
branches/goings/source/classification/cClassificationManager.cc
branches/goings/source/classification/cGenotype.cc
branches/goings/source/main/cPhenotype.h
branches/goings/source/main/cPopulation.cc
branches/goings/source/tools/cMerit.cc
branches/goings/source/tools/cMerit.h
branches/goings/support/config/avida.cfg
Log:
Added fit share to my branch, if niche_radius is set to 0 "should" not slow down avida...
Modified: branches/goings/source/classification/cClassificationManager.cc
===================================================================
--- branches/goings/source/classification/cClassificationManager.cc 2009-08-05 16:47:47 UTC (rev 3358)
+++ branches/goings/source/classification/cClassificationManager.cc 2009-08-05 18:40:40 UTC (rev 3359)
@@ -116,20 +116,24 @@
void cClassificationManager::AddGenotype(cGenotype* in_genotype, int list_num)
{
assert( in_genotype != 0 );
-
+
if (list_num < 0) list_num = FindCRC(in_genotype->GetGenome());
m_active_genotypes[list_num].Push(in_genotype);
-
+ m_genotype_ctl->Insert(*in_genotype);
+
// for fitness sharing *SLG
- for (int i = 0; i < m_genotype_ctl->GetSize(); i++) {
- cGenotype * genotype = m_genotype_ctl->Get(0);
- int hd = genotype->AddHDist(in_genotype);
- in_genotype->AddHDist(genotype, hd);
- m_genotype_ctl->Next(0);
+ if (m_world->GetConfig().NICHE_RADIUS.Get() > 0)
+ {
+ m_genotype_ctl->Reset(0);
+ for (int i = 0; i < m_genotype_ctl->GetSize(); i++) {
+ cGenotype * genotype = m_genotype_ctl->Get(0);
+ int hd = genotype->AddHDist(in_genotype);
+ in_genotype->AddHDist(genotype, hd);
+ m_genotype_ctl->Next(0);
+ }
}
- m_genotype_ctl->Insert(*in_genotype);
m_world->GetStats().AddGenotype();
// Speciation... If we are creating a new genotype here, we must
@@ -263,13 +267,15 @@
m_active_genotypes[list_num].Remove(&in_genotype);
m_genotype_ctl->Remove(in_genotype);
- // for fitness sharing *SLG
- for (int i = 0; i < m_genotype_ctl->GetSize(); i++) {
- cGenotype * genotype = m_genotype_ctl->Get(0);
- genotype->RemHDist(&in_genotype);
- m_genotype_ctl->Next(0);
- }
-
+ m_genotype_ctl->Reset(0);
+ // for fitness sharing *SLG
+ for (int i = 0; i < m_genotype_ctl->GetSize(); i++) {
+ cGenotype * genotype = m_genotype_ctl->Get(0);
+ if (genotype!=NULL)
+ genotype->RemHDist(&in_genotype);
+ m_genotype_ctl->Next(0);
+ }
+
in_genotype.Deactivate(m_world->GetStats().GetUpdate(), m_world->GetStats().GetTotCreatures());
if (m_world->GetConfig().TRACK_MAIN_LINEAGE.Get()) {
m_genotype_ctl->InsertHistoric(in_genotype);
Modified: branches/goings/source/classification/cGenotype.cc
===================================================================
--- branches/goings/source/classification/cGenotype.cc 2009-08-05 16:47:47 UTC (rev 3358)
+++ branches/goings/source/classification/cGenotype.cc 2009-08-05 18:40:40 UTC (rev 3359)
@@ -211,6 +211,8 @@
share = 1 - pow((it->second / r),p);
sum += share * num_orgs;
}
+ if (sum<1)
+ sum = 1.0;
return sum;
}
Modified: branches/goings/source/main/cPhenotype.h
===================================================================
--- branches/goings/source/main/cPhenotype.h 2009-08-05 16:47:47 UTC (rev 3358)
+++ branches/goings/source/main/cPhenotype.h 2009-08-05 18:40:40 UTC (rev 3359)
@@ -450,6 +450,7 @@
//////////////////// Accessors -- Modifying ///////////////////
void SetMerit(const cMerit& in_merit) { merit = in_merit; }
+ void SetMeritNicheVal(const double in_niche_val) { merit.SetNicheVal(in_niche_val); }
void SetFitness(const double in_fit) { fitness = in_fit; }
void ReduceEnergy(const double cost);
void SetEnergy(const double value);
Modified: branches/goings/source/main/cPopulation.cc
===================================================================
--- branches/goings/source/main/cPopulation.cc 2009-08-05 16:47:47 UTC (rev 3358)
+++ branches/goings/source/main/cPopulation.cc 2009-08-05 18:40:40 UTC (rev 3359)
@@ -395,9 +395,8 @@
}
// for fitness sharing *SLG
- double niche_val = parent_genotype->GetNicheVal();
- cMerit parent_merit = parent_phenotype.GetMerit();
- parent_merit.SetNicheVal(niche_val);
+ double niche_val = parent_genotype->GetNicheVal();
+ parent_phenotype.SetMeritNicheVal(niche_val);
AdjustSchedule(parent_cell, parent_phenotype.GetMerit());
// In a local run, face the child toward the parent.
@@ -552,9 +551,10 @@
}
m_world->GetClassificationManager().AdjustGenotype(*in_genotype);
- // for fitness sharing *SLG
+ // for fitness sharing *SLG
double niche_val = in_genotype->GetNicheVal();
-
+ in_organism->GetPhenotype().SetMeritNicheVal(niche_val);
+
// Initialize the time-slice for this new organism.
AdjustSchedule(target_cell, in_organism->GetPhenotype().GetMerit());
@@ -3732,7 +3732,6 @@
cOrganism* cur_org = cell.GetOrganism();
cHardwareBase* hw = cell.GetHardware();
-
if (cell.GetSpeculativeState()) {
// We have already executed this instruction, just decrement the counter
cell.DecSpeculative();
@@ -3749,7 +3748,6 @@
m_world->GetStats().AddSpeculative(spec_count);
}
}
-
double merit = cur_org->GetPhenotype().GetMerit().GetDouble();
if (cur_org->GetPhenotype().GetToDelete() == true) {
delete cur_org;
Modified: branches/goings/source/tools/cMerit.cc
===================================================================
--- branches/goings/source/tools/cMerit.cc 2009-08-05 16:47:47 UTC (rev 3358)
+++ branches/goings/source/tools/cMerit.cc 2009-08-05 18:40:40 UTC (rev 3359)
@@ -36,6 +36,7 @@
offset = 0;
base = static_cast<unsigned int>(mant * exp.mult[bits - offset] * 2.0);
+ niche_val = 1.0;
}
Modified: branches/goings/source/tools/cMerit.h
===================================================================
--- branches/goings/source/tools/cMerit.h 2009-08-05 16:47:47 UTC (rev 3358)
+++ branches/goings/source/tools/cMerit.h 2009-08-05 18:40:40 UTC (rev 3359)
@@ -30,6 +30,7 @@
#include <cmath>
#include <climits>
#include <cassert>
+using namespace std;
class cWorld;
@@ -61,6 +62,7 @@
base = _merit.base;
offset = _merit.offset;
value = _merit.value;
+ niche_val = _merit.niche_val;
}
void operator=(double _merit) { UpdateValue(_merit); }
@@ -84,14 +86,16 @@
int operator!=(const double _m) const { return value != _m; }
int operator!=(const unsigned int _m) const { return (offset!=0 || base!=_m); }
- void Clear() { value = 0; base = 0; offset = 0; bits = 0; }
+ void Clear() { value = 0; base = 0; offset = 0; bits = 0; niche_val = 1.0; }
// @TCC - This function fails for values > UINT_MAX...
unsigned int GetUInt() const {
assert(value < UINT_MAX); // Fails for merit values > UINT_MAX.
return (unsigned int) value; }
- double GetDouble() const { return value/niche_val; }
+ double GetDouble() const {
+ if (niche_val<1) return value;
+ return value/niche_val; }
int GetBit(int bit_num) const {
assert(bit_num >= 0);
Modified: branches/goings/support/config/avida.cfg
===================================================================
--- branches/goings/support/config/avida.cfg 2009-08-05 16:47:47 UTC (rev 3358)
+++ branches/goings/support/config/avida.cfg 2009-08-05 18:40:40 UTC (rev 3359)
@@ -1,4 +1,4 @@
-#############################################################################
+ #############################################################################
# This file includes all the basic run-time defines for Avida.
# For more information, see doc/config.html
#############################################################################
@@ -176,6 +176,7 @@
# increased on divide (good with DIVIDE_METHOD 1).
RESET_INPUTS_ON_DIVIDE 0 # Reset environment inputs of parent upon successful divide.
REPRO_METHOD 1 # Replace existing organism: 1=yes
+NICHE_RADIUS 0.0
### RECOMBINATION_GROUP ###
# Sexual Recombination and Modularity
More information about the Avida-cvs
mailing list