From: bdemsky Date: Sat, 13 Oct 2018 02:13:32 +0000 (-0700) Subject: edits X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=commitdiff_plain;h=23975bc927f2cc13bf215f13ff7ba1dc0c012c01 edits --- diff --git a/src/Collections/cppvector.h b/src/Collections/cppvector.h index 1c44606..b4822ef 100644 --- a/src/Collections/cppvector.h +++ b/src/Collections/cppvector.h @@ -69,6 +69,21 @@ public: array[index] = item; } + void insertAt(uint index, type item) { + setSize(size + 1); + for (uint i = size - 1; i > index; i--) { + set(i, get(i - 1)); + } + array[index] = item; + } + + void removeAt(uint index) { + for (uint i = index; (i + 1) < size; i++) { + set(i, get(i + 1)); + } + setSize(size - 1); + } + inline uint getSize() const { return size; } diff --git a/src/Tuner/multituner.cc b/src/Tuner/multituner.cc index e20aa1f..4ccd29f 100644 --- a/src/Tuner/multituner.cc +++ b/src/Tuner/multituner.cc @@ -45,6 +45,8 @@ MultiTuner::MultiTuner(uint _budget, uint _rounds, uint _timeout) : MultiTuner::~MultiTuner() { for (uint i = 0; i < problems.getSize(); i++) ourfree(problems.get(i)); + for (uint i = 0; i < allTuners.getSize(); i++) + delete allTuners.get(i); } void MultiTuner::addProblem(const char *filename) { @@ -96,12 +98,64 @@ long long MultiTuner::evaluate(Problem *problem, SearchTuner *tuner) { void MultiTuner::tuneComp() { Vector *tunerV = new Vector(&tuners); - for (uint i = 0; i < problems.getSize(); i++) { - Problem *problem = problems.get(i); + for (uint b = 0; b < budget; b++) { + uint tSize = tunerV->getSize(); + for (uint i = 0; i < tSize; i++) { + SearchTuner *tmpTuner = mutateTuner(tunerV->get(i)->getTuner(), b); + tunerV->push(new TunerRecord(tmpTuner)); + } + Hashtable scores; + for (uint i = 0; i < problems.getSize(); i++) { + Problem *problem = problems.get(i); + Vector places; + for (uint j = 0; j < tunerV->getSize(); j++) { + TunerRecord *tuner = tunerV->get(j); + long long metric = tuner->getTime(problem); + if (metric == -1) { + metric = evaluate(problem, tuner->getTuner()); + if (metric != -1) + tuner->setTime(problem, metric); + } + if (metric != -1) { + uint k = 0; + for (; k < places.getSize(); k++) { + if (metric < places.get(k)->getTime(problem)) + break; + } + places.insertAt(k, tuner); + } + } + int points = 4; + for (uint k = 0; k < places.getSize() && points; k++) { + TunerRecord *tuner = places.get(k); + points = points / 2; + int currScore = 0; + if (scores.contains(tuner)) + currScore = scores.get(tuner); + currScore += points; + scores.put(tuner, currScore); + } + } + Vector ranking; + for (uint i = 0; i < tunerV->getSize(); i++) { + TunerRecord *tuner = tunerV->get(i); + int score = 0; + if (scores.contains(tuner)) + score = scores.get(tuner); + uint j = 0; + for (; j < ranking.getSize(); j++) { + TunerRecord *t = ranking.get(j); + int tscore = 0; + if (scores.contains(t)) + tscore = scores.get(t); + if (score > tscore) + break; + } + ranking.insertAt(j, tuner); + } } - } void MultiTuner::mapProblemsToTuners(Vector *tunerV) {