Adding a directed search based config for the tuner
authorHamed Gorjiara <hgorjiar@uci.edu>
Thu, 4 Oct 2018 18:50:30 +0000 (11:50 -0700)
committerHamed Gorjiara <hgorjiar@uci.edu>
Thu, 4 Oct 2018 18:50:30 +0000 (11:50 -0700)
src/Backend/satelemencoder.cc
src/Tuner/autotuner.cc
src/Tuner/autotuner.h
src/Tuner/searchtuner.cc
src/Tuner/searchtuner.h
src/config.h
src/csolver.cc

index d2c04f6..8f06eec 100644 (file)
@@ -226,7 +226,6 @@ void SATEncoder::generateBinaryIndexEncodingVars(ElementEncoding *encoding) {
        if (encoding->element->anyValue){
                uint setSize = encoding->element->getRange()->getSize();
                uint encArraySize = encoding->encArraySize;
-               model_print("setSize=%u\tencArraySize=%u\n", setSize, encArraySize);
                if(setSize < encArraySize * (uint)solver->getTuner()->getTunable(MUSTVALUE, &mustValueBinaryIndex)/10){
                        generateAnyValueBinaryIndexEncodingPositive(encoding);
                } else {
index 6b29755..857b21c 100644 (file)
@@ -55,6 +55,13 @@ SearchTuner *AutoTuner::mutateTuner(SearchTuner *oldTuner, uint k) {
        return newTuner;
 }
 
+#ifdef STATICENCGEN
+SearchTuner *AutoTuner::mutateTuner(SearchTuner *oldTuner) {
+       SearchTuner *newTuner = oldTuner->copyUsed();
+       result = newTuner->nextStaticTuner();
+       return result==EXIT_FAILURE? newTuner: NULL;
+}
+#endif
 
 void AutoTuner::tune() {
        SearchTuner *bestTuner = NULL;
@@ -64,6 +71,20 @@ void AutoTuner::tune() {
        double base_temperature = evaluateAll(oldTuner);
        double oldScore = base_temperature;
 
+#ifdef STATICENCGEN
+       while(true){
+               SearchTuner *newTuner = mutateTuner(oldTuner);
+               if(newTuner == NULL)
+                       return;
+               double newScore = evaluateAll(newTuner);
+               newTuner->printUsed();
+               model_print("Received score %f\n", newScore);
+               delete oldTuner;
+               oldScore = newScore;
+               oldTuner = newTuner;
+       }
+#endif
+       
        for (uint i = 0; i < budget; i++) {
                SearchTuner *newTuner = mutateTuner(oldTuner, i);
                double newScore = evaluateAll(newTuner);
index 72d4c2b..ed276ee 100644 (file)
@@ -16,7 +16,9 @@ private:
        long long evaluate(CSolver *problem, SearchTuner *tuner);
        double evaluateAll(SearchTuner *tuner);
        SearchTuner *mutateTuner(SearchTuner *oldTuner, uint k);
-
+#ifdef STATICENCGEN
+       SearchTuner *mutateTuner(SearchTuner *oldTuner);
+#endif
        Vector<CSolver *> solvers;
        uint budget;
        int result;
index bfe66bb..1aef3fc 100644 (file)
@@ -72,6 +72,10 @@ ostream &operator<<(ostream &os, const TunableSetting &ts)
 
 
 SearchTuner::SearchTuner() {
+#ifdef STATICENCGEN
+        graphEncoding =false;
+        naiveEncoding = ELEM_UNASSIGNED;
+#endif
        ifstream myfile;
        myfile.open (TUNEFILE, ios::in);
        if (myfile.is_open()) {
@@ -106,6 +110,12 @@ SearchTuner *SearchTuner::copyUsed() {
                TunableSetting *copy = new TunableSetting(setting);
                tuner->settings.add(copy);
        }
+#ifdef STATICENCGEN
+       if(naiveEncoding != ELEM_UNASSIGNED){
+               tuner->graphEncoding = graphEncoding;
+               tuner->naiveEncoding = naiveEncoding;
+       }
+#endif
        delete iterator;
        return tuner;
 }
@@ -169,6 +179,50 @@ void SearchTuner::randomMutate() {
        model_print("&&&&&&&&&&&&&&&&&&&&&&&\n");
 }
 
+#ifdef STATICENCGEN
+int SearchTuner::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;
+}
+#endif
+
 void SearchTuner::print() {
        SetIteratorTunableSetting *iterator = settings.iterator();
        while (iterator->hasNext()) {
index 26fd8df..612f60e 100644 (file)
@@ -59,6 +59,12 @@ private:
        HashsetTunableSetting usedSettings;
        /** Settings contains all settings. */
        HashsetTunableSetting settings;
+#ifdef STATICENCGEN
+        bool graphEncoding;
+        ElementEncodingType naiveEncoding;
+public:
+        int nextStaticTuner();
+#endif
 };
 
 
index 5ce22b0..ef0b9b1 100644 (file)
@@ -19,6 +19,7 @@
 //#define CONFIG_DEBUG
 #endif
 
+//#define STATICENCGEN
 
 #ifndef CONFIG_ASSERT
 #define CONFIG_ASSERT
index f1bd9b6..9f374cc 100644 (file)
@@ -154,7 +154,7 @@ CSolver *CSolver::clone() {
 }
 
 CSolver *CSolver::deserialize(const char *file) {
-       model_print("deserializing ...\n");
+       model_print("deserializing %s ...\n", file);
        Deserializer deserializer(file);
        return deserializer.deserialize();
 }