@@ -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 {
@@ -352,8 +361,9 @@ void GeneticSearch::generateSelectionPool() {
352361 sortByRuntime (population);
353362 updateBestCandidate (
354363 population.size () > 0 ? population.front ()->configuration : lastBestConf);
355- resetPopulationIfNotEnoughCandidates ();
356- breed ();
364+ if (resetPopulationIfNotEnoughCandidates ()) {
365+ return ;
366+ }
357367 selectionPool.clear ();
358368 selectionPool.emplace_back (make_unique<CandidateConfiguration>(lastBestConf));
359369 breed ();
0 commit comments