From 8a0d33b5ebb3497d158f2d5c050c69be3fcd1e0d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 5 Aug 2012 01:26:45 -0600 Subject: Added option to recalculate survivors. This accomidates simulations where the test conditions can change as the simulation runs, which would effect the scores of phenotypes that have already been tested. --- src/explicitsimulation.cpp | 8 ++++++-- src/explicitsimulation.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/explicitsimulation.cpp b/src/explicitsimulation.cpp index 98df0b0..95b721b 100644 --- a/src/explicitsimulation.cpp +++ b/src/explicitsimulation.cpp @@ -13,12 +13,13 @@ using namespace Bu; Genetic::ExplicitSimulation::ExplicitSimulation( Genetic::Operator *pOper, Genetic::FitnessFunction *pFunc, int iThreads, int iPopSize, - float fKeep, float fRandom, bool bKeepBest ) : + float fKeep, float fRandom, bool bKeepBest, bool bRecalcSurvivors ) : pOper( pOper ), iPopSize( iPopSize ), fKeep( fKeep ), fRandom( fRandom ), bKeepBest( bKeepBest ), + bRecalcSurvivors( bRecalcSurvivors ), bRunning( true ) { for( int j = 0; j < iPopSize; j++ ) @@ -102,7 +103,10 @@ void Genetic::ExplicitSimulation::timestep() // Refill the population mFitness.lock(); - hFitness = hTempFitness; + if( bRecalcSurvivors ) + hFitness.clear(); + else + hFitness = hTempFitness; mFitness.unlock(); xPop.clear(); xPop.timestep(); diff --git a/src/explicitsimulation.h b/src/explicitsimulation.h index e71b489..78cb904 100644 --- a/src/explicitsimulation.h +++ b/src/explicitsimulation.h @@ -18,7 +18,7 @@ namespace Genetic public: ExplicitSimulation( Operator *pOper, FitnessFunction *pFunc, int iThreads, int iPopSize, float fKeep, float fRandom, - bool bKeepBest=true ); + bool bKeepBest=true, bool bRecalcSurvivors=false ); virtual ~ExplicitSimulation(); void timestep(); @@ -47,6 +47,7 @@ namespace Genetic float fKeep; float fRandom; bool bKeepBest; + bool bRecalcSurvivors; typedef Bu::Hash FitnessHash; FitnessHash hFitness; double dMinFitness; -- cgit v1.2.3