Merge branch 'tuner' of ssh://demsky.eecs.uci.edu/home/git/constraint_compiler into...
author <hamed@DESKTOP-SG54322.localdomain> <>
Thu, 6 Dec 2018 23:10:14 +0000 (15:10 -0800)
committer <hamed@DESKTOP-SG54322.localdomain> <>
Thu, 6 Dec 2018 23:10:14 +0000 (15:10 -0800)
src/ASTTransform/elementopt.cc
src/ASTTransform/preprocess.cc
src/Tuner/multituner.cc
src/Tuner/multituner.h
src/Tuner/searchtuner.cc
src/Tuner/searchtuner.h
src/csolver.cc
src/csolver.h

index b0866ed..96ca8f6 100644 (file)
@@ -9,7 +9,7 @@
 
 ElementOpt::ElementOpt(CSolver *_solver)
        : Transform(_solver),
-       updateSets(solver->getTuner()->getTunable(ELEMENTOPTSETS, &onoff) == 1)
+         updateSets(false)
 {
 }
 
@@ -20,6 +20,9 @@ void ElementOpt::doTransform() {
        if (solver->getTuner()->getTunable(ELEMENTOPT, &onoff) == 0)
                return;
 
+       //Set once we know we are going to use it.
+       updateSets = solver->getTuner()->getTunable(ELEMENTOPTSETS, &onoff) == 1;
+       
        SetIteratorBooleanEdge *iterator = solver->getConstraints();
        while (iterator->hasNext()) {
                BooleanEdge constraint = iterator->next();
index 1e60c19..7b4877b 100644 (file)
@@ -13,7 +13,7 @@ Preprocess::~Preprocess() {
 }
 
 void Preprocess::doTransform() {
-       if (solver->getTuner()->getTunable(PREPROCESS, &onoff) == 0)
+       if (!solver->isBooleanVarUsed() && solver->getTuner()->getTunable(PREPROCESS, &onoff) == 0)
                return;
 
        BooleanIterator bit(solver);
index 0beab16..c69891f 100644 (file)
@@ -133,6 +133,15 @@ void MultiTuner::findBestThreeTuners() {
        }
 }
 
+bool MultiTuner::finishTunerExist(TunerRecord *tunerRec){
+       SearchTuner *tuner = tunerRec->getTuner();
+       for(uint i=0; i< explored.getSize(); i++){
+               if(explored.get(i)->getTuner()->equalUsed(tuner))
+                       return true;
+       }
+       return false;
+}
+
 void MultiTuner::addTuner(SearchTuner *tuner) {
        TunerRecord *t = new TunerRecord(tuner);
        tuners.push(t);
@@ -263,7 +272,9 @@ long long MultiTuner::evaluate(Problem *problem, TunerRecord *tuner) {
                updateTimeout(problem, metric);
                snprintf(buffer, sizeof(buffer), "tuner%uused", execnum);
                tuner->getTuner()->addUsed(buffer);
-               explored.push(tuner);
+               if(!finishTunerExist(tuner)){
+                       explored.push(tuner);
+               }
        }
        //Increment execution count
        execnum++;
index 0c43785..e184540 100644 (file)
@@ -47,6 +47,7 @@ public:
        void readData(uint numRuns);
        void updateTimeout(Problem *problem, long long metric);
        void tuneK();
+       bool finishTunerExist(TunerRecord *tuner);
        void tuneComp();
        void printData();
        void findBestThreeTuners();
index 6b17a2a..b3c549a 100644 (file)
@@ -94,6 +94,29 @@ SearchTuner::SearchTuner(const char *filename) {
        }
 }
 
+bool SearchTuner::equalUsed(SearchTuner* tuner){
+       if(tuner->usedSettings.getSize() != usedSettings.getSize()){
+               return false;
+       }
+       bool result = true;
+       SetIteratorTunableSetting *iterator = usedSettings.iterator();
+       while(iterator->hasNext()){
+               TunableSetting *setting = iterator->next();
+               if(!tuner->usedSettings.contains(setting)){
+                       result = false;
+                       break;
+               }else{
+                       TunableSetting *tunerSetting = tuner->usedSettings.get(setting);
+                       if(tunerSetting->selectedValue != setting->selectedValue){
+                               result = false;
+                               break;
+                       }
+               }
+       }
+       delete iterator;
+       return result;
+}
+
 void SearchTuner::addUsed(const char *filename) {
        ifstream myfile;
        myfile.open (filename, ios::in);
index c75bfd8..7624425 100644 (file)
@@ -51,7 +51,7 @@ public:
        void serialize(const char *file);
        void serializeUsed(const char *file);
        void addUsed(const char *file);
-
+        bool equalUsed(SearchTuner *tuner);
        CMEMALLOC;
 protected:
        /** Used Settings keeps track of settings that were actually used by
index fbe0dd0..45163be 100644 (file)
@@ -34,6 +34,7 @@ CSolver::CSolver() :
        boolTrue(BooleanEdge(new BooleanConst(true))),
        boolFalse(boolTrue.negate()),
        unsat(false),
+       booleanVarUsed(false),
        tuner(NULL),
        elapsedTime(0),
        satsolverTimeout(NOTIMEOUT)
@@ -136,6 +137,7 @@ void CSolver::resetSolver() {
        boolTrue = BooleanEdge(new BooleanConst(true));
        boolFalse = boolTrue.negate();
        unsat = false;
+       booleanVarUsed = false;
        elapsedTime = 0;
        tuner = NULL;
        satEncoder->resetSATEncoder();
@@ -308,6 +310,8 @@ Function *CSolver::completeTable(Table *table, UndefinedBehavior behavior) {
 BooleanEdge CSolver::getBooleanVar(VarType type) {
        Boolean *boolean = new BooleanVar(type);
        allBooleans.push(boolean);
+       if(!booleanVarUsed)
+               booleanVarUsed = true;
        return BooleanEdge(boolean);
 }
 
index 16937dd..c604486 100644 (file)
@@ -141,7 +141,7 @@ public:
        void setUnSAT() { model_print("Setting UNSAT %%%%%%\n"); unsat = true; }
        void setSatSolverTimeout(long seconds) { satsolverTimeout = seconds;}
        bool isUnSAT() { return unsat; }
-
+        bool isBooleanVarUsed(){return booleanVarUsed;}
        void printConstraint(BooleanEdge boolean);
        void printConstraints();
 
@@ -218,7 +218,8 @@ private:
 
        SATEncoder *satEncoder;
        bool unsat;
-       Tuner *tuner;
+        bool booleanVarUsed;
+        Tuner *tuner;
        long long elapsedTime;
        long satsolverTimeout;
        friend class ElementOpt;