diff options
author | Mike Buland <mike@xagasoft.com> | 2012-08-05 01:26:45 -0600 |
---|---|---|
committer | Mike Buland <mike@xagasoft.com> | 2012-08-05 01:26:45 -0600 |
commit | 8a0d33b5ebb3497d158f2d5c050c69be3fcd1e0d (patch) | |
tree | 8519567e456d856a19892421ab50202118d4fb59 | |
parent | 2406848173c445a94a1710106116ad796a8bacb9 (diff) | |
download | libgenetic-8a0d33b5ebb3497d158f2d5c050c69be3fcd1e0d.tar.gz libgenetic-8a0d33b5ebb3497d158f2d5c050c69be3fcd1e0d.tar.bz2 libgenetic-8a0d33b5ebb3497d158f2d5c050c69be3fcd1e0d.tar.xz libgenetic-8a0d33b5ebb3497d158f2d5c050c69be3fcd1e0d.zip |
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.
-rw-r--r-- | src/explicitsimulation.cpp | 8 | ||||
-rw-r--r-- | 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; | |||
13 | 13 | ||
14 | Genetic::ExplicitSimulation::ExplicitSimulation( Genetic::Operator *pOper, | 14 | Genetic::ExplicitSimulation::ExplicitSimulation( Genetic::Operator *pOper, |
15 | Genetic::FitnessFunction *pFunc, int iThreads, int iPopSize, | 15 | Genetic::FitnessFunction *pFunc, int iThreads, int iPopSize, |
16 | float fKeep, float fRandom, bool bKeepBest ) : | 16 | float fKeep, float fRandom, bool bKeepBest, bool bRecalcSurvivors ) : |
17 | pOper( pOper ), | 17 | pOper( pOper ), |
18 | iPopSize( iPopSize ), | 18 | iPopSize( iPopSize ), |
19 | fKeep( fKeep ), | 19 | fKeep( fKeep ), |
20 | fRandom( fRandom ), | 20 | fRandom( fRandom ), |
21 | bKeepBest( bKeepBest ), | 21 | bKeepBest( bKeepBest ), |
22 | bRecalcSurvivors( bRecalcSurvivors ), | ||
22 | bRunning( true ) | 23 | bRunning( true ) |
23 | { | 24 | { |
24 | for( int j = 0; j < iPopSize; j++ ) | 25 | for( int j = 0; j < iPopSize; j++ ) |
@@ -102,7 +103,10 @@ void Genetic::ExplicitSimulation::timestep() | |||
102 | 103 | ||
103 | // Refill the population | 104 | // Refill the population |
104 | mFitness.lock(); | 105 | mFitness.lock(); |
105 | hFitness = hTempFitness; | 106 | if( bRecalcSurvivors ) |
107 | hFitness.clear(); | ||
108 | else | ||
109 | hFitness = hTempFitness; | ||
106 | mFitness.unlock(); | 110 | mFitness.unlock(); |
107 | xPop.clear(); | 111 | xPop.clear(); |
108 | xPop.timestep(); | 112 | 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 | |||
18 | public: | 18 | public: |
19 | ExplicitSimulation( Operator *pOper, FitnessFunction *pFunc, | 19 | ExplicitSimulation( Operator *pOper, FitnessFunction *pFunc, |
20 | int iThreads, int iPopSize, float fKeep, float fRandom, | 20 | int iThreads, int iPopSize, float fKeep, float fRandom, |
21 | bool bKeepBest=true ); | 21 | bool bKeepBest=true, bool bRecalcSurvivors=false ); |
22 | virtual ~ExplicitSimulation(); | 22 | virtual ~ExplicitSimulation(); |
23 | 23 | ||
24 | void timestep(); | 24 | void timestep(); |
@@ -47,6 +47,7 @@ namespace Genetic | |||
47 | float fKeep; | 47 | float fKeep; |
48 | float fRandom; | 48 | float fRandom; |
49 | bool bKeepBest; | 49 | bool bKeepBest; |
50 | bool bRecalcSurvivors; | ||
50 | typedef Bu::Hash<Genetic::PhenotypeId, double> FitnessHash; | 51 | typedef Bu::Hash<Genetic::PhenotypeId, double> FitnessHash; |
51 | FitnessHash hFitness; | 52 | FitnessHash hFitness; |
52 | double dMinFitness; | 53 | double dMinFitness; |