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 /src/explicitsimulation.cpp | |
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.
Diffstat (limited to '')
-rw-r--r-- | src/explicitsimulation.cpp | 8 |
1 files changed, 6 insertions, 2 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(); |