Fix tuner issues
authorbdemsky <bdemsky@uci.edu>
Mon, 15 Oct 2018 23:39:16 +0000 (16:39 -0700)
committerbdemsky <bdemsky@uci.edu>
Mon, 15 Oct 2018 23:39:16 +0000 (16:39 -0700)
src/Tuner/autotuner.cc
src/Tuner/autotuner.h
src/Tuner/multituner.cc
src/Tuner/multituner.h

index b769993..1bf29d8 100644 (file)
@@ -11,6 +11,8 @@ AutoTuner::AutoTuner(uint _budget) :
        budget(_budget), result(UNSETVALUE) {
 }
 
+AutoTuner::~AutoTuner() {}
+
 void AutoTuner::addProblem(CSolver *solver) {
        solvers.push(solver);
 }
index 8271008..e9c7b40 100644 (file)
@@ -9,6 +9,7 @@
 class AutoTuner {
 public:
        AutoTuner(uint budget);
+       virtual ~AutoTuner();
        void addProblem(CSolver *solver);
        virtual void tune();
        CMEMALLOC;
index fbf66c7..03bfeec 100644 (file)
@@ -59,11 +59,11 @@ void MultiTuner::addTuner(SearchTuner *tuner) {
        allTuners.push(t);
 }
 
-long long MultiTuner::evaluate(Problem *problem, SearchTuner *tuner) {
+long long MultiTuner::evaluate(Problem *problem, TunerRecord *tuner) {
        char buffer[512];
        //Write out the tuner
        snprintf(buffer, sizeof(buffer), "tuner%u", execnum);
-       tuner->serialize(buffer);
+       tuner->getTuner()->serialize(buffer);
 
        //Do run
        snprintf(buffer, sizeof(buffer), "./run.sh deserializerun %s %u tuner%u result%s%u > log%u", problem->getProblem(), timeout, execnum, problem->getProblem(), execnum, execnum);
@@ -71,6 +71,7 @@ long long MultiTuner::evaluate(Problem *problem, SearchTuner *tuner) {
 
        long long metric = -1;
        int sat = IS_INDETER;
+
        if (status == 0) {
                //Read data in from results file
                snprintf(buffer, sizeof(buffer), "result%s%u", problem->getProblem(), execnum);
@@ -84,6 +85,12 @@ long long MultiTuner::evaluate(Problem *problem, SearchTuner *tuner) {
                        myfile >> sat;
                        myfile.close();
                }
+
+               snprintf(buffer, sizeof(buffer), "tuner%uused", execnum);
+               SearchTuner *usedtuner = new SearchTuner(buffer);
+               delete tuner->getTuner();
+               tuner->updateTuner(usedtuner);
+
        }
        //Increment execution count
        execnum++;
@@ -113,7 +120,7 @@ void MultiTuner::tuneComp() {
                                TunerRecord *tuner = tunerV->get(j);
                                long long metric = tuner->getTime(problem);
                                if (metric == -1) {
-                                       metric = evaluate(problem, tuner->getTuner());
+                                       metric = evaluate(problem, tuner);
                                        if (metric != -1)
                                                tuner->setTime(problem, metric);
                                }
@@ -173,7 +180,7 @@ void MultiTuner::mapProblemsToTuners(Vector<TunerRecord *> *tunerV) {
                        TunerRecord *tuner = tunerV->get(j);
                        long long metric = tuner->getTime(problem);
                        if (metric == -1) {
-                               metric = evaluate(problem, tuner->getTuner());
+                               metric = evaluate(problem, tuner);
                                if (metric != -1)
                                        tuner->setTime(problem, metric);
                        }
@@ -227,7 +234,7 @@ double MultiTuner::evaluateAll(TunerRecord *tuner) {
                Problem *problem = tuner->problems.get(i);
                long long metric = tuner->getTime(problem);
                if (metric == -1) {
-                       metric = evaluate(problem, tuner->getTuner());
+                       metric = evaluate(problem, tuner);
                        if (metric != -1)
                                tuner->setTime(problem, metric);
                }
index 1162e82..69430cc 100644 (file)
@@ -22,6 +22,7 @@ public:
        TunerRecord(SearchTuner *_tuner) : tuner(_tuner) {}
        SearchTuner *getTuner() {return tuner;}
        TunerRecord *changeTuner(SearchTuner *_newtuner);
+       void updateTuner(SearchTuner *_newtuner) {tuner = _newtuner;}
        long long getTime(Problem *problem);
        void setTime(Problem *problem, long long time);
 private:
@@ -42,7 +43,7 @@ public:
        void tuneComp();
        CMEMALLOC;
 protected:
-       long long evaluate(Problem *problem, SearchTuner *tuner);
+       long long evaluate(Problem *problem, TunerRecord *tuner);
        double evaluateAll(TunerRecord *tuner);
        SearchTuner *mutateTuner(SearchTuner *oldTuner, uint k);
        void mapProblemsToTuners(Vector<TunerRecord *> *tunerV);