Fix tuner issues
[satune.git] / src / Tuner / multituner.cc
index 4ccd29f..03bfeec 100644 (file)
@@ -59,18 +59,19 @@ 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), "deserializerun %s %u tuner%u result%s%u > log%u", problem->getProblem(), timeout, execnum, problem->getProblem(), execnum, execnum);
+       snprintf(buffer, sizeof(buffer), "./run.sh deserializerun %s %u tuner%u result%s%u > log%u", problem->getProblem(), timeout, execnum, problem->getProblem(), execnum, execnum);
        int status = system(buffer);
 
        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++;
@@ -99,7 +106,6 @@ long long MultiTuner::evaluate(Problem *problem, SearchTuner *tuner) {
 void MultiTuner::tuneComp() {
        Vector<TunerRecord *> *tunerV = new Vector<TunerRecord *>(&tuners);
        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);
@@ -114,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);
                                }
@@ -127,10 +133,10 @@ void MultiTuner::tuneComp() {
                                        places.insertAt(k, tuner);
                                }
                        }
-                       int points = 4;
+                       int points = 9;
                        for (uint k = 0; k < places.getSize() && points; k++) {
                                TunerRecord *tuner = places.get(k);
-                               points = points / 2;
+                               points = points / 3;
                                int currScore = 0;
                                if (scores.contains(tuner))
                                        currScore = scores.get(tuner);
@@ -155,6 +161,13 @@ void MultiTuner::tuneComp() {
                        }
                        ranking.insertAt(j, tuner);
                }
+               for (uint i = tuners.getSize(); i < ranking.getSize(); i++) {
+                       TunerRecord *tuner = ranking.get(i);
+                       for (uint j = 0; j < tunerV->getSize(); j++) {
+                               if (tunerV->get(j) == tuner)
+                                       tunerV->removeAt(j);
+                       }
+               }
        }
 }
 
@@ -167,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);
                        }
@@ -221,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);
                }