Add file to generate tuner files and fix tunable usage
authorbdemsky <bdemsky@uci.edu>
Mon, 15 Oct 2018 21:31:14 +0000 (14:31 -0700)
committerbdemsky <bdemsky@uci.edu>
Mon, 15 Oct 2018 21:31:14 +0000 (14:31 -0700)
src/Encoders/naiveencoder.cc
src/Test/runmultituner.cc [new file with mode: 0644]
src/Test/serializetuner.cc [new file with mode: 0644]
src/Tuner/multituner.cc
src/Tuner/searchtuner.cc
src/Tuner/searchtuner.h

index 3f9e44e..63ec82f 100644 (file)
@@ -69,7 +69,10 @@ void naiveEncodingElement(CSolver *csolver, Element *This) {
                if (This->type != ELEMCONST) {
                        model_print("INFO: naive encoder is making the decision about element %p....\n", This);
                }
-               encoding->setElementEncodingType((ElementEncodingType)csolver->getTuner()->getVarTunable(This->getRange()->getType(), NAIVEENCODER, &NaiveEncodingDesc));
+               uint enc = csolver->getTuner()->getVarTunable(This->getRange()->getType(), NODEENCODING, &NodeEncodingDesc);
+               if (enc == ELEM_UNASSIGNED)
+                       enc = csolver->getTuner()->getTunable(NAIVEENCODER, &NaiveEncodingDesc);
+               encoding->setElementEncodingType((ElementEncodingType)enc);
                encoding->encodingArrayInitialization();
        }
 
diff --git a/src/Test/runmultituner.cc b/src/Test/runmultituner.cc
new file mode 100644 (file)
index 0000000..b66fa5e
--- /dev/null
@@ -0,0 +1,37 @@
+#include "csolver.h"
+#include "multituner.h"
+#include "searchtuner.h"
+
+int main(int argc, char **argv) {
+       if (argc < 7) {
+               printf("You should specify %s budget rounds timeout problemfilenames - tunerfilenames", argv[0]);
+               exit(-1);
+       }
+       uint budget;
+       uint rounds;
+       uint timeout;
+       sscanf(argv[1], "%u", &budget);
+       sscanf(argv[2], "%u", &rounds);
+       sscanf(argv[3], "%u", &timeout);
+
+       MultiTuner *multituner = new MultiTuner(budget, rounds, timeout);
+       bool tunerfiles = false;
+       for (int i = 4; i < argc; i++) {
+               if (!tunerfiles) {
+                       if (argv[i][0] == '-' && argv[i][1] == 0)
+                               tunerfiles = true;
+                       else
+                               multituner->addProblem(argv[i]);
+               } else
+                       multituner->addTuner(new SearchTuner(argv[i]));
+       }
+
+       if (!tunerfiles) {
+               printf("You should specify %s budget rounds timeout problemfilenames - tunerfilenames", argv[0]);
+               exit(-1);
+       }
+
+       multituner->tuneK();
+       delete multituner;
+       return 0;
+}
diff --git a/src/Test/serializetuner.cc b/src/Test/serializetuner.cc
new file mode 100644 (file)
index 0000000..dcce0c5
--- /dev/null
@@ -0,0 +1,20 @@
+#include "csolver.h"
+#include "searchtuner.h"
+#include "tunable.h"
+#include <stdlib.h>
+
+int main(int argc, char **argv) {
+       SearchTuner *elem_bin = new SearchTuner();
+       SearchTuner *elem_onehot = new SearchTuner();
+       SearchTuner *elem_unary = new SearchTuner();
+       elem_bin->setTunable(NAIVEENCODER, &NaiveEncodingDesc, BINARYINDEX);
+       elem_onehot->setTunable(NAIVEENCODER, &NaiveEncodingDesc, ONEHOT);
+       elem_unary->setTunable(NAIVEENCODER, &NaiveEncodingDesc, UNARY);
+
+       elem_bin->serialize("binarytuner.conf");
+       elem_onehot->serialize("onehottuner.conf");
+       elem_unary->serialize("unarytuner.conf");
+       delete elem_bin;
+       delete elem_onehot;
+       delete elem_unary;
+}
index 2504110..a30b482 100644 (file)
@@ -155,11 +155,11 @@ 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);
-                 }
+                       TunerRecord *tuner = ranking.get(i);
+                       for (uint j = 0; j < tunerV->getSize(); j++) {
+                               if (tunerV->get(j) == tuner)
+                                       tunerV->removeAt(j);
+                       }
                }
        }
 }
index 674758e..e594abe 100644 (file)
@@ -122,6 +122,24 @@ SearchTuner::~SearchTuner() {
        delete iterator;
 }
 
+void SearchTuner::setTunable(TunableParam param, TunableDesc *descriptor, uint value) {
+       TunableSetting *result = new TunableSetting(param);
+       result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, value);
+       settings.add(result);
+       usedSettings.add(result);
+}
+
+void SearchTuner::setVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor, uint value) {
+       setVarTunable(vartype, 0, param, descriptor, value);
+}
+
+void SearchTuner::setVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor, uint value) {
+       TunableSetting *result = new TunableSetting(vartype1, vartype2, param);
+       result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, value);
+       settings.add(result);
+       usedSettings.add(result);
+}
+
 int SearchTuner::getTunable(TunableParam param, TunableDesc *descriptor) {
        TunableSetting setting(param);
        TunableSetting *result = usedSettings.get(&setting);
index e00a6dd..44dcd5c 100644 (file)
@@ -45,6 +45,9 @@ public:
        int getTunable(TunableParam param, TunableDesc *descriptor);
        int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor);
        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);
        SearchTuner *copyUsed();
        void randomMutate();
        uint getSize() { return usedSettings.getSize();}