[Avida-SVN] r3396 - branches/goings/source/main
goingssh at myxo.css.msu.edu
goingssh at myxo.css.msu.edu
Sun Sep 6 20:20:55 PDT 2009
Author: goingssh
Date: 2009-09-06 23:20:54 -0400 (Sun, 06 Sep 2009)
New Revision: 3396
Modified:
branches/goings/source/main/cPopulation.cc
branches/goings/source/main/cPopulation.h
Log:
Fixed problem in fitshare for when child overwrites its own parent.
Modified: branches/goings/source/main/cPopulation.cc
===================================================================
--- branches/goings/source/main/cPopulation.cc 2009-09-04 00:49:43 UTC (rev 3395)
+++ branches/goings/source/main/cPopulation.cc 2009-09-07 03:20:54 UTC (rev 3396)
@@ -566,7 +566,28 @@
double niche_val = 1;
if (m_world->GetConfig().NICHE_RADIUS.Get() > 0)
{
- UpdateHDists(target_cell.GetID(), par_cell, in_genotype);
+
+ // only do this optimization if this organism has a parent, otherwise we're injecting and have to calculate
+ // all distances
+ int par_dist = -1;
+ if (par_cell >= 0)
+ {
+ // get proper parent genome, usually just in parent cell, but if child overwrote parent
+ // its stored in the saved genotype
+ cGenotype* par_gen;
+ if (par_cell == target_cell.GetID())
+ par_gen = old_genotype;
+ else
+ par_gen = cell_array[par_cell].GetOrganism()->GetGenotype();
+ // find distance between child and parent genomes
+ if ( par_gen->GetGenome() == in_organism->GetGenome() )
+ par_dist = 0;
+ else
+ par_dist = cGenomeUtil::FindEditDistance(par_gen->GetGenome(), in_organism->GetGenome());
+ }
+
+ // and update table accordingly
+ UpdateHDists(target_cell.GetID(), par_cell, in_genotype, par_dist);
niche_val = GetNicheVal(target_cell.GetID());
}
in_organism->GetPhenotype().SetMeritNicheVal(niche_val);
@@ -932,21 +953,11 @@
// maintain grid of hamming distances between each org in population and each other org
// cell_id is cell we're about to place a new org, gen is its genotype
-void cPopulation::UpdateHDists(int cell_id, int par_id, cGenotype* gen)
+void cPopulation::UpdateHDists(int cell_id, int par_id, cGenotype* gen, int par_dist)
{
- int par_dist=-1;
- if (par_id>=0 and par_id!=cell_id)
- {
- const cGenome& par_gen = cell_array[par_id].GetOrganism()->GetGenome();
- if ( par_gen == gen->GetGenome() )
- par_dist = 0;
- else
- par_dist = cGenomeUtil::FindEditDistance(par_gen, gen->GetGenome());
- }
for (int i=0; i<cell_array.GetSize(); i++)
{
int dist = m_world->GetConfig().NICHE_RADIUS.Get();
- int dist1 = -1;
if (cell_array[i].GetOrganism())
{
if (cell_id==i)
Modified: branches/goings/source/main/cPopulation.h
===================================================================
--- branches/goings/source/main/cPopulation.h 2009-09-04 00:49:43 UTC (rev 3395)
+++ branches/goings/source/main/cPopulation.h 2009-09-07 03:20:54 UTC (rev 3396)
@@ -183,7 +183,7 @@
void AddSellValue(const int data, const int label, const int sell_price, const int org_id, const int cell_id);
int BuyValue(const int label, const int buy_price, const int cell_id);
void SwapCells(cPopulationCell & cell1, cPopulationCell & cell2);
- void UpdateHDists(int cell_id, int parent_id, cGenotype* gen);
+ void UpdateHDists(int cell_id, int parent_id, cGenotype* gen, int par_dist);
double GetNicheVal(int cell_id);
// Deme-related methods
More information about the Avida-cvs
mailing list