Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 1b85a76

Browse files
author
Theodoros Theodoridis
committed
[genetic search] Handle invalid generations properly
1 parent 3ad88e7 commit 1b85a76

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

include/tc/autotuner/genetic_search.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class GeneticSearch {
107107

108108
void updateBestCandidate(const TuningConfiguration& c);
109109

110-
void resetPopulationIfNotEnoughCandidates();
110+
bool resetPopulationIfNotEnoughCandidates();
111111

112112
TuningConfiguration crossover(
113113
TuningConfiguration&,

src/autotuner/genetic_search.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

326335
namespace {
@@ -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

Comments
 (0)