@@ -301,7 +301,7 @@ void GeneticSearch::breed() {
301
301
}
302
302
}
303
303
304
- void GeneticSearch::resetPopulationIfNotEnoughCandidates () {
304
+ bool GeneticSearch::resetPopulationIfNotEnoughCandidates () {
305
305
if (population.size () < kMinCandidatesForBreeding ) {
306
306
LOG_IF (ERROR, FLAGS_debug_tuner)
307
307
<< population.size () << " out of " << kMaxPopulationSize
@@ -320,7 +320,16 @@ void GeneticSearch::resetPopulationIfNotEnoughCandidates() {
320
320
// Don't lose the first one which was the best from before
321
321
CHECK_LT (0 , population.size ());
322
322
randomizePopulation (population.begin () + 1 , population.end (), rng);
323
+
324
+ selectionPool.clear ();
325
+ for (size_t i = 0 ; i < kSelectionPoolSize ; ++i) {
326
+ selectionPool.emplace_back (
327
+ make_unique<CandidateConfiguration>(lastBestConf));
328
+ }
329
+ randomizePopulation (selectionPool.begin () + 1 , selectionPool.end (), rng);
330
+ return true ;
323
331
}
332
+ return false ;
324
333
}
325
334
326
335
namespace {
@@ -352,8 +361,9 @@ void GeneticSearch::generateSelectionPool() {
352
361
sortByRuntime (population);
353
362
updateBestCandidate (
354
363
population.size () > 0 ? population.front ()->configuration : lastBestConf);
355
- resetPopulationIfNotEnoughCandidates ();
356
- breed ();
364
+ if (resetPopulationIfNotEnoughCandidates ()) {
365
+ return ;
366
+ }
357
367
selectionPool.clear ();
358
368
selectionPool.emplace_back (make_unique<CandidateConfiguration>(lastBestConf));
359
369
breed ();
0 commit comments