@@ -301,7 +301,7 @@ void GeneticSearch::breed() {
301301 }
302302}
303303
304- void GeneticSearch::resetPopulationIfNotEnoughCandidates () {
304+ bool GeneticSearch::resetPopulationIfNotEnoughCandidates () {
305305 if (population.size () < kMinCandidatesForBreeding ) {
306306 LOG_IF (ERROR, FLAGS_debug_tuner)
307307 << population.size () << " out of " << kMaxPopulationSize
@@ -320,7 +320,16 @@ void GeneticSearch::resetPopulationIfNotEnoughCandidates() {
320320 // Don't lose the first one which was the best from before
321321 CHECK_LT (0 , population.size ());
322322 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 ;
323331 }
332+ return false ;
324333}
325334
326335namespace {
@@ -351,8 +360,9 @@ void GeneticSearch::generateSelectionPool() {
351360 sortByRuntime (population);
352361 updateBestCandidate (
353362 population.size () > 0 ? population.front ()->configuration : lastBestConf);
354- resetPopulationIfNotEnoughCandidates ();
355- breed ();
363+ if (resetPopulationIfNotEnoughCandidates ()) {
364+ return ;
365+ }
356366 selectionPool.clear ();
357367 selectionPool.emplace_back (make_unique<CandidateConfiguration>(lastBestConf));
358368 breed ();
0 commit comments