From 575f265a4587e5717a492392b014e5796b52fc5c Mon Sep 17 00:00:00 2001 From: Hamed Gorjiara Date: Tue, 8 Sep 2020 14:14:11 -0700 Subject: [PATCH] Finding the best tuner --- src/Test/analyzemultituner.cc | 3 ++- src/Tuner/comptuner.cc | 39 +++++++++++++++++++++++++++++++++++ src/Tuner/comptuner.h | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Test/analyzemultituner.cc b/src/Test/analyzemultituner.cc index 93487f0..9054d18 100644 --- a/src/Test/analyzemultituner.cc +++ b/src/Test/analyzemultituner.cc @@ -27,7 +27,8 @@ int main(int argc, char **argv) { printf("Number of Runs: %u\n", numruns); CompTuner *multituner = new CompTuner(0, 0); multituner->readData(numruns); - multituner->findBestTwoTuners(); + //multituner->findBestTwoTuners(); + multituner->findTheBestTuner(); delete multituner; return 0; } diff --git a/src/Tuner/comptuner.cc b/src/Tuner/comptuner.cc index 029efe9..bc35c60 100644 --- a/src/Tuner/comptuner.cc +++ b/src/Tuner/comptuner.cc @@ -16,6 +16,45 @@ CompTuner::~CompTuner() { } +void CompTuner::findTheBestTuner() { + if (allTuners.getSize() < 1) { + printData(); + return; + } + TunerRecord *bestTuner = NULL; + double score = DBL_MAX; + for (uint j = 0; j < allTuners.getSize() - 1; j++) { + TunerRecord *tuner1 = allTuners.get(j); + double mintimes[problems.getSize()]; + for (uint l = 0; l < problems.getSize(); l++) { + Problem *problem = problems.get(l); + long long time1 = tuner1->getTime(problem); + if(time1 < 0){ + time1=LLONG_MAX; + } + mintimes[l] = pow(time1, (double)1 / problems.getSize()); + } + double result = 1; + for (uint l = 0; l < problems.getSize(); l++) { + result *= mintimes[l]; + } + if (result < score) { + score = result; + bestTuner = tuner1; + } + } + model_print("The Best tuner:\n"); + + SearchTuner *stun = bestTuner->getTuner(); + char buffer[512]; + snprintf(buffer, sizeof(buffer), "best.tuner"); + stun->serialize(buffer); + model_print("Tuner %u\n", bestTuner->getTunerNumber()); + stun->print(); + bestTuner->printProblemsInfo(); + model_print("----------------------------------\n\n\n"); +} + void CompTuner::findBestTwoTuners() { if (allTuners.getSize() < 2) { printData(); diff --git a/src/Tuner/comptuner.h b/src/Tuner/comptuner.h index 74183bc..9f86ffb 100644 --- a/src/Tuner/comptuner.h +++ b/src/Tuner/comptuner.h @@ -12,6 +12,7 @@ public: void readData(uint numRuns); void tune(); void findBestTwoTuners(); + void findTheBestTuner(); protected: }; -- 2.34.1