fix tuner situation
authorbdemsky <bdemsky@uci.edu>
Wed, 31 Oct 2018 21:06:31 +0000 (14:06 -0700)
committerbdemsky <bdemsky@uci.edu>
Wed, 31 Oct 2018 21:06:31 +0000 (14:06 -0700)
src/Test/deserializerstatictune.cc [deleted file]
src/Test/deserializerun.cc
src/Test/tunerrun.cc [new file with mode: 0644]
src/Tuner/searchtuner.h
src/Tuner/serializetuner.cc [new file with mode: 0644]
src/Tuner/serializetuner.h [new file with mode: 0644]
src/Tuner/staticautotuner.cc [deleted file]
src/Tuner/staticautotuner.h [deleted file]
src/Tuner/staticsearchtuner.cc [deleted file]
src/Tuner/staticsearchtuner.h [deleted file]
src/classlist.h

diff --git a/src/Test/deserializerstatictune.cc b/src/Test/deserializerstatictune.cc
deleted file mode 100644 (file)
index 7660e1e..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "csolver.h"
-#include "staticautotuner.h"
-
-int main(int argc, char **argv) {
-       if (argc < 2) {
-               printf("You should specify file names ...");
-               exit(-1);
-       }
-       CSolver *solvers[argc - 1];
-       StaticAutoTuner *autotuner = new StaticAutoTuner(300);
-       for (int i = 1; i < argc; i++) {
-               solvers[i - 1] = CSolver::deserialize(argv[i]);
-               autotuner->addProblem(solvers[i - 1]);
-       }
-
-       autotuner->tune();
-       delete autotuner;
-
-       for (int i = 1; i < argc; i++) {
-               delete solvers[i - 1];
-       }
-
-       return 1;
-}
index 1b7371b45b80714798ccd32c0725dba544a517df..bbfaab569b77144cde23c3eddd6b52c55673c0fb 100644 (file)
@@ -28,5 +28,6 @@ int main(int argc, char **argv) {
        tuner->serializeUsed(buffer);
 
        delete solver;
+       delete tuner;
        return 0;
 }
diff --git a/src/Test/tunerrun.cc b/src/Test/tunerrun.cc
new file mode 100644 (file)
index 0000000..40a0960
--- /dev/null
@@ -0,0 +1,33 @@
+#include "csolver.h"
+#include "serializetuner.h"
+#include <stdlib.h>
+#include <iostream>
+#include <fstream>
+
+int main(int argc, char **argv) {
+       if (argc != 5) {
+               printf("You only specify the name of the file ...");
+               exit(-1);
+       }
+       char buffer[512];
+       CSolver *solver = CSolver::deserialize(argv[1]);
+       uint timeout;
+       sscanf(argv[2], "%u", &timeout);
+       SerializeTuner *tuner = new SerializeTuner(argv[3]);
+       solver->setTuner(tuner);
+       solver->setSatSolverTimeout(timeout);
+       int sat = solver->solve();
+       long long metric = solver->getElapsedTime();
+       ofstream myfile;
+       myfile.open (argv[4], ios::out | ios::trunc);
+       myfile << metric << endl;
+       myfile << sat << endl;
+       myfile.close();
+       //serialize out the tuner we used
+       snprintf(buffer, sizeof(buffer), "%sused", argv[3]);
+       tuner->serializeUsed(buffer);
+
+       delete solver;
+       delete tuner;
+       return 0;
+}
index 2cd3118bda41514bf9939d94a86fbd85f8175c38..3db0064d099c3d1290d42f43a53cc96e6d32ce91 100644 (file)
@@ -28,7 +28,7 @@ private:
        friend unsigned int tunableSettingHash(TunableSetting *setting);
        friend bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2);
        friend class SearchTuner;
-       friend class StaticSearchTuner;
+       friend class SerializeTuner;
 };
 
 unsigned int tunableSettingHash(TunableSetting *setting);
@@ -42,9 +42,9 @@ public:
        SearchTuner();
        SearchTuner(const char *filename);
        ~SearchTuner();
-       int getTunable(TunableParam param, TunableDesc *descriptor);
+       virtual int getTunable(TunableParam param, TunableDesc *descriptor);
        int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor);
-       int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
+       virtual int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
        void setTunable(TunableParam param, TunableDesc *descriptor, uint value);
        void setVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor, uint value);
        void setVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor, uint value);
diff --git a/src/Tuner/serializetuner.cc b/src/Tuner/serializetuner.cc
new file mode 100644 (file)
index 0000000..db043fb
--- /dev/null
@@ -0,0 +1,70 @@
+#include "serializetuner.h"
+#include <iostream>
+#include <fstream>
+using namespace std;
+
+SerializeTuner::SerializeTuner(const char *filename) {
+       ifstream myfile;
+       myfile.open (filename, ios::in);
+       if (myfile.is_open()) {
+               bool hasVar;
+               VarType type1;
+               VarType type2;
+               TunableParam param;
+               int lowValue;
+               int highValue;
+               int defaultValue;
+               int selectedValue;
+               while (myfile >> hasVar >> type1 >> type2 >> param >> lowValue >> highValue >> defaultValue >> selectedValue) {
+                       TunableSetting *setting;
+
+                       if (hasVar) {
+                               setting = new TunableSetting(type1, type2, param);
+                       } else {
+                               setting = new TunableSetting(param);
+                       }
+                       setting->setDecision(lowValue, highValue, defaultValue, selectedValue);
+                       settings.add(setting);
+                       usedSettings.add(setting);
+               }
+               myfile.close();
+       } else {
+               model_print("Warning: Tuner %s couldn't be loaded ... Using default tuner instead ....\n", filename);
+       }
+}
+
+/*SearchTuner::~SearchTuner() {
+   SetIteratorTunableSetting *iterator = settings.iterator();
+   while (iterator->hasNext()) {
+    TunableSetting *setting = iterator->next();
+    delete setting;
+   }
+   delete iterator;
+   }*/
+
+
+int SerializeTuner::getTunable(TunableParam param, TunableDesc *descriptor) {
+       TunableSetting setting(param);
+       TunableSetting *result = usedSettings.get(&setting);
+       if (result == NULL) {
+               result = settings.get(&setting);
+               if ( result == NULL) {
+                       return descriptor->defaultValue;
+               }
+               usedSettings.add(result);
+       }
+       return result->selectedValue;
+}
+
+int SerializeTuner::getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor) {
+       TunableSetting setting(vartype1, vartype2, param);
+       TunableSetting *result = usedSettings.get(&setting);
+       if (result == NULL) {
+               result = settings.get(&setting);
+               if ( result == NULL) {
+                       return descriptor->defaultValue;
+               }
+               usedSettings.add(result);
+       }
+       return result->selectedValue;
+}
diff --git a/src/Tuner/serializetuner.h b/src/Tuner/serializetuner.h
new file mode 100644 (file)
index 0000000..b0478ab
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef SERIALIZETUNER_H
+#define SERIALIZETUNER_H
+#include "searchtuner.h"
+
+class SerializeTuner : public SearchTuner {
+public:
+       SerializeTuner(const char *filename);
+       int getTunable(TunableParam param, TunableDesc *descriptor);
+       int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor);
+       int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
+       CMEMALLOC;
+};
+
+#endif
diff --git a/src/Tuner/staticautotuner.cc b/src/Tuner/staticautotuner.cc
deleted file mode 100644 (file)
index d4c9109..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "staticautotuner.h"
-#include "csolver.h"
-#include "staticsearchtuner.h"
-#include <math.h>
-#include <stdlib.h>
-#include <float.h>
-
-#define UNSETVALUE -1
-#define TIMEOUTSEC 5000
-StaticAutoTuner::StaticAutoTuner(uint _budget) : AutoTuner(_budget) {
-}
-
-StaticSearchTuner *StaticAutoTuner::mutateTuner(StaticSearchTuner *oldTuner) {
-       StaticSearchTuner *newTuner = oldTuner->copyUsed();
-       result = newTuner->nextStaticTuner();
-       if ( result == EXIT_FAILURE) {
-               return newTuner;
-       } else {
-               delete newTuner;
-               return NULL;
-       }
-}
-
-void StaticAutoTuner::tune() {
-       StaticSearchTuner *oldTuner = new StaticSearchTuner();
-       evaluateAll(oldTuner);
-       while (true) {
-               StaticSearchTuner *newTuner = mutateTuner(oldTuner);
-               if (newTuner == NULL) {
-                       break;
-               }
-               double newScore = evaluateAll(newTuner);
-               newTuner->printUsed();
-               model_print("Received score %f\n", newScore);
-               delete oldTuner;
-               oldTuner = newTuner;
-       }
-       delete oldTuner;
-}
diff --git a/src/Tuner/staticautotuner.h b/src/Tuner/staticautotuner.h
deleted file mode 100644 (file)
index 127d53f..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef STATICAUTOTUNER_H
-#define STATICAUTOTUNER_H
-#include "autotuner.h"
-
-
-class StaticAutoTuner : public AutoTuner {
-public:
-       StaticAutoTuner(uint budget);
-       virtual void tune();
-       CMEMALLOC;
-private:
-       StaticSearchTuner *mutateTuner(StaticSearchTuner *oldTuner);
-};
-#endif
diff --git a/src/Tuner/staticsearchtuner.cc b/src/Tuner/staticsearchtuner.cc
deleted file mode 100644 (file)
index 5cedc71..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-#include "staticsearchtuner.h"
-#include <iostream>
-#include <fstream>
-using namespace std;
-
-StaticSearchTuner::StaticSearchTuner() {
-       graphEncoding = false;
-       naiveEncoding = ELEM_UNASSIGNED;
-       ifstream myfile;
-       myfile.open (TUNEFILE, ios::in);
-       if (myfile.is_open()) {
-               bool hasVar;
-               VarType type1;
-               VarType type2;
-               TunableParam param;
-               int lowValue;
-               int highValue;
-               int defaultValue;
-               int selectedValue;
-               while (myfile >> hasVar >> type1 >> type2 >> param >> lowValue >> highValue >> defaultValue >> selectedValue) {
-                       TunableSetting *setting;
-
-                       if (hasVar) {
-                               setting = new TunableSetting(type1, type2, param);
-                       } else {
-                               setting = new TunableSetting(param);
-                       }
-                       setting->setDecision(lowValue, highValue, defaultValue, selectedValue);
-                       usedSettings.add(setting);
-               }
-               myfile.close();
-       }
-}
-
-StaticSearchTuner *StaticSearchTuner::copyUsed() {
-       StaticSearchTuner *tuner = new StaticSearchTuner();
-       SetIteratorTunableSetting *iterator = usedSettings.iterator();
-       while (iterator->hasNext()) {
-               TunableSetting *setting = iterator->next();
-               TunableSetting *copy = new TunableSetting(setting);
-               tuner->settings.add(copy);
-       }
-       if (naiveEncoding != ELEM_UNASSIGNED) {
-               tuner->graphEncoding = graphEncoding;
-               tuner->naiveEncoding = naiveEncoding;
-       }
-       delete iterator;
-       return tuner;
-}
-
-StaticSearchTuner::~StaticSearchTuner() {
-       SetIteratorTunableSetting *iterator = settings.iterator();
-       while (iterator->hasNext()) {
-               TunableSetting *setting = iterator->next();
-               delete setting;
-       }
-       delete iterator;
-}
-
-int StaticSearchTuner::nextStaticTuner() {
-       if (naiveEncoding == ELEM_UNASSIGNED) {
-               naiveEncoding = ONEHOT;
-               SetIteratorTunableSetting *iter = settings.iterator();
-               while (iter->hasNext()) {
-                       TunableSetting *setting = iter->next();
-                       if (setting->param == NAIVEENCODER) {
-                               setting->selectedValue = ONEHOT;
-                       } else if (setting->param == ENCODINGGRAPHOPT) {
-                               setting->selectedValue = false;
-                       }
-               }
-               delete iter;
-               return EXIT_FAILURE;
-       }
-       int result = EXIT_FAILURE;
-       if (naiveEncoding == BINARYINDEX && graphEncoding) {
-               model_print("Best tuner\n");
-               return EXIT_SUCCESS;
-       } else if (naiveEncoding == BINARYINDEX && !graphEncoding) {
-               naiveEncoding = ONEHOT;
-               graphEncoding = true;
-       } else {
-               naiveEncoding = (ElementEncodingType)((int)naiveEncoding + 1);
-       }
-       SetIteratorTunableSetting *iter = settings.iterator();
-       uint count = 0;
-       while (iter->hasNext()) {
-               TunableSetting *setting = iter->next();
-               if (setting->param == NAIVEENCODER) {
-                       setting->selectedValue = naiveEncoding;
-                       count++;
-               } else if (setting->param == ENCODINGGRAPHOPT) {
-                       setting->selectedValue = graphEncoding;
-                       count++;
-               }
-       }
-       model_print("Mutating %u settings\n", count);
-       delete iter;
-       return result;
-}
diff --git a/src/Tuner/staticsearchtuner.h b/src/Tuner/staticsearchtuner.h
deleted file mode 100644 (file)
index 7d7d78d..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef STATICSEARCHTUNER_H
-#define STATICSEARCHTUNER_H
-#include "searchtuner.h"
-#define TUNEFILE "tune.conf"
-
-class StaticSearchTuner : public SearchTuner {
-public:
-       StaticSearchTuner();
-       ~StaticSearchTuner();
-       int nextStaticTuner();
-       StaticSearchTuner *copyUsed();
-
-       CMEMALLOC;
-private:
-       bool graphEncoding;
-       ElementEncodingType naiveEncoding;
-};
-
-#endif
index 0def1ff48f8ff0be70cbe0000ef9a9ace68cd4fc..cccf6890fc596dda20286a1a8819846686639720 100644 (file)
@@ -61,8 +61,7 @@ class MultiTuner;
 class SearchTuner;
 class TunableSetting;
 
-class StaticAutoTuner;
-class StaticSearchTuner;
+class SerializeTuner;
 
 class TunableDesc;