Merging + fixing memory bugs
authorHamed Gorjiara <hgorjiar@uci.edu>
Thu, 5 Sep 2019 23:01:44 +0000 (16:01 -0700)
committerHamed Gorjiara <hgorjiar@uci.edu>
Thu, 5 Sep 2019 23:01:44 +0000 (16:01 -0700)
1  2 
src/Backend/satelemencoder.cc
src/Test/dirkreader.cc
src/ccsolver.cc
src/csolver.cc
src/csolver.h
src/satune_SatuneJavaAPI.cc
src/satune_SatuneJavaAPI.h

index d924e6a9062e0b900f0e65bdbc5988bb6c2f4b83,b380c3a78116387eb470362e2692331aa42959b0..7687f3532e6b5f84840588aa56ae4dd3df87e032
@@@ -220,22 -220,13 +220,22 @@@ void SATEncoder::generateBinaryValueEnc
                generateAnyValueBinaryValueEncoding(encoding);
  }
  
- void SATEncoder::freezeElementVariables(ElementEncoding *encoding){
+ void SATEncoder::freezeElementVariables(ElementEncoding *encoding) {
        ASSERT(encoding->element->frozen);
-       for(uint i=0; i< encoding->numVars; i++){
+       for (uint i = 0; i < encoding->numVars; i++) {
                Edge e = encoding->variables[i];
                ASSERT(edgeIsVarConst(e));
                freezeVariable(cnf, e);
        }
 +      for(uint i=0; i< encoding->encArraySize; i++){
 +              if(encoding->isinUseElement(i) && encoding->encoding != EENC_NONE && encoding->numVars > 1){
 +                      Edge e = encoding->edgeArray[i];
 +                      if(!edgeIsNull(e)){
 +                              ASSERT(edgeIsVarConst(e));
 +                              freezeVariable(cnf, e);
 +                      }
 +              }
 +      }
  }
  
  void SATEncoder::generateBinaryIndexEncodingVars(ElementEncoding *encoding) {
@@@ -303,9 -294,6 +303,9 @@@ void SATEncoder::generateElementEncodin
  }
  
  int SATEncoder::getMaximumUsedSize(ElementEncoding *encoding) {
 +      if(encoding->encArraySize == 1){
 +              return 1;
 +      }
        for (int i = encoding->encArraySize - 1; i >= 0; i--) {
                if (encoding->isinUseElement(i))
                        return i + 1;
diff --combined src/Test/dirkreader.cc
index 0000000000000000000000000000000000000000,60b4aee75bf8d1a3c0c1182621c58f9dd234fdcd..56393fb4858c1df3c93a35e74c120c901006adc0
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,340 +1,372 @@@
 -
+ #include <iostream>
+ #include <fstream>
+ #include "csolver.h"
+ #include "hashset.h"
+ #include "cppvector.h"
+ const char * assertstart = "ASSERTSTART";
+ const char * assertend = "ASSERTEND";
+ const char * satstart = "SATSTART";
+ const char * satend = "SATEND";
+ int skipahead(const char * token1, const char * token2);
+ char * readuntilend(const char * token);
+ BooleanEdge parseConstraint(CSolver * solver, char * constraint, int & offset);
+ void processEquality(char * constraint, int &offset);
+ std::ifstream * file;
+ Order * order;
+ MutableSet * set;
+ class intwrapper {
+ public:
+   intwrapper(int _val) : value(_val) {
+   }
+   int32_t value;
+ };
+ unsigned int iw_hash_function(intwrapper *i) {
+   return i->value;
+ }
+ bool iw_equals(intwrapper *key1, intwrapper *key2) {
+   return (key1->value == key2->value);
+ }
+ typedef Hashset<intwrapper *, uintptr_t, PTRSHIFT, iw_hash_function, iw_equals> HashsetIW;
+ class OrderRec {
+ public:
+   OrderRec() : set (NULL), value(-1), alloced(false) {
+   }
+   ~OrderRec() {
+     if (set != NULL) {
+       set->resetAndDelete();
+       delete set;
+     }
+   }
+   HashsetIW * set;
+   int32_t value;
+   bool alloced;
+ };
+ typedef Hashtable<intwrapper *, OrderRec *, uintptr_t, PTRSHIFT, iw_hash_function, iw_equals> HashtableIW;
+ typedef Hashtable<intwrapper *, Boolean *, uintptr_t, PTRSHIFT, iw_hash_function, iw_equals> HashtableBV;
 -    if (retval == 0)
++Vector<OrderRec*> * orderRecVector = NULL;
+ HashtableIW * ordertable = NULL;
+ HashtableBV * vartable = new HashtableBV();
++void cleanAndFreeOrderRecVector(){
++      for(uint i=0; i< orderRecVector->getSize(); i++){
++              delete orderRecVector->get(i);
++      }
++      orderRecVector->clear();
++}
++
+ int main(int numargs, char ** argv) {
+   file = new std::ifstream(argv[1]);
+   char * assert = NULL;
+   char * sat = NULL;
++  Vector<OrderRec*> orderRecs;
++  orderRecVector = &orderRecs;
+   while(true) {
+     int retval = skipahead(assertstart, satstart);
+     printf("%d\n", retval);
 -      if (assert != NULL)
++    if (retval == 0){
+       break;
++    }
+     if (retval == 1) {
 -      ordertable->resetAndDeleteVals();
++      if (assert != NULL){
+       free(assert);
++      assert = NULL;
++      }
+       assert = readuntilend(assertend);
+       printf("[%s]\n", assert);
+     } else if (retval == 2) {
+       if (sat != NULL) {
+       free(sat);
++      sat = NULL;
+       vartable->resetAndDeleteKeys();
 -  
++      ordertable->reset();
++      cleanAndFreeOrderRecVector();
+       } else {
+       ordertable = new HashtableIW();
+       }
+       sat = readuntilend(satend);
+       CSolver *solver = new CSolver();
++      solver->turnoffOptimizations();
+       set = solver->createMutableSet(1);
+       order = solver->createOrder(SATC_TOTAL, (Set *) set);
+       int offset = 0;
+       processEquality(sat, offset);
+       offset = 0;
+       processEquality(assert, offset);
+       offset = 0;
+       solver->addConstraint(parseConstraint(solver, sat, offset));
+       offset = 0;
+       solver->addConstraint(parseConstraint(solver, assert, offset));
+       printf("[%s]\n", sat);
+       solver->finalizeMutableSet(set);
+       solver->serialize();
+       solver->printConstraints();
+       delete solver;
+     }
+   }
++
++  cleanAndFreeOrderRecVector();
++  if(ordertable != NULL){
++      delete ordertable;
++  }
++  if(assert != NULL){
++      free(assert);
++  }
++  if(sat != NULL){
++      free(sat);
++  }
++  vartable->resetAndDeleteKeys();
++  delete vartable;
+   file->close();
++  delete file;
+ }
+ void skipwhitespace(char * constraint, int & offset) {
+   //skip whitespace
+   while (constraint[offset] == ' ' || constraint[offset] == '\n')
+     offset++;
+ }
+ void doExit() {
+   printf("PARSE ERROR\n");
+   exit(-1);
+ }
+ int32_t getOrderVar(char *constraint, int & offset) {
+   if (constraint[offset++] != 'O' || constraint[offset++] != '!' ) {
+     doExit();
+   }
+   int32_t num = 0;
+   while(true) {
+     char next = constraint[offset];
+     if (next >= '0' && next <= '9') {
+       num = (num * 10) + (next - '0');
+       offset++;
+     } else
+       return num;
+   }
+ }
+ int32_t getBooleanVar(char *constraint, int & offset) {
+   if (constraint[offset++] != 'S' || constraint[offset++] != '!' ) {
+     doExit();
+   }
+   int32_t num = 0;
+   while(true) {
+     char next = constraint[offset];
+     if (next >= '0' && next <= '9') {
+       num = (num * 10) + (next - '0');
+       offset++;
+     } else
+       return num;
+   }
+ }
+ BooleanEdge checkBooleanVar(CSolver *solver, int32_t value) {
+   intwrapper v(value);
+   if (vartable->contains(&v)) {
+     return BooleanEdge(vartable->get(&v));
+   } else {
+     Boolean* ve = solver->getBooleanVar(2).getBoolean();
+     vartable->put(new intwrapper(value), ve);
+     return BooleanEdge(ve);
+   }
+ }
+ void mergeVars(int32_t value1, int32_t value2) {
+   intwrapper v1(value1);
+   intwrapper v2(value2);
+   OrderRec *r1 = ordertable->get(&v1);
+   OrderRec *r2 = ordertable->get(&v2);
+   if (r1 == r2) {
+     if (r1 == NULL) {
+       OrderRec * r = new OrderRec();
++      orderRecVector->push(r);
+       r->value = value1;
+       r->set = new HashsetIW();
+       intwrapper * k1 = new intwrapper(v1);
+       intwrapper * k2 = new intwrapper(v2);
+       r->set->add(k1);
+       r->set->add(k2);
+       ordertable->put(k1, r);
+       ordertable->put(k2, r);
+     }
+   } else if (r1 == NULL) {
+     intwrapper * k = new intwrapper(v1);
+     ordertable->put(k, r2);
+     r2->set->add(k);
+   } else if (r2 == NULL) {
+     intwrapper * k = new intwrapper(v2);
+     ordertable->put(k, r1);
+     r1->set->add(k);
+   } else {
+     SetIterator<intwrapper *, uintptr_t, PTRSHIFT, iw_hash_function, iw_equals> * it1 = r1->set->iterator();
+     while (it1->hasNext()) {
+       intwrapper * k = it1->next();
+       ordertable->put(k, r2);
+       r2->set->add(k);
+     }
+     delete r2->set;
+     r2->set = NULL;
+     delete r2;
+     delete it1;
+   }
+ }
+ int32_t checkordervar(CSolver * solver, int32_t value) {
+   intwrapper v(value);
+   OrderRec * rec = ordertable->get(&v);
+   if (rec == NULL) {
+     intwrapper * k = new intwrapper(value);
+     rec = new OrderRec();
++    orderRecVector->push(rec);
+     rec->value = value;
++    rec->set = new HashsetIW();
++    rec->set->add(k);
+     ordertable->put(k, rec);
+   }
+   if (!rec->alloced) {
+     solver->addItem(set, rec->value);
+     rec->alloced = true;
+   }
+   return rec->value;
+ }
+ void processEquality(char * constraint, int &offset) {
+   skipwhitespace(constraint, offset);
+   if (strncmp(&constraint[offset], "(and",4) == 0) {
+     offset +=4;
+     Vector<BooleanEdge> vec;
+     while(true) {
+       skipwhitespace(constraint, offset);
+       if (constraint[offset] == ')') {
+       offset++;
+       return;
+       }
+       processEquality(constraint, offset);
+     }
+   } else if (strncmp(&constraint[offset], "(<", 2) == 0) {
+     offset+=2;
+     skipwhitespace(constraint, offset);
+     getOrderVar(constraint, offset);
+     skipwhitespace(constraint, offset);
+     getOrderVar(constraint, offset);
+     skipwhitespace(constraint, offset);
+     if (constraint[offset++] != ')')
+       doExit();
+     return;
+   } else if (strncmp(&constraint[offset], "(=", 2) == 0) {
+     offset+=2;
+     skipwhitespace(constraint, offset);
+     int v1=getOrderVar(constraint, offset);
+     skipwhitespace(constraint, offset);
+     int v2=getOrderVar(constraint, offset);
+     skipwhitespace(constraint, offset);
+     if (constraint[offset++] != ')')
+       doExit();
+     mergeVars(v1, v2);
+     return;
+   } else {
+     getBooleanVar(constraint, offset);
+     skipwhitespace(constraint, offset);
+     return;
+   }
+ }
+ BooleanEdge parseConstraint(CSolver * solver, char * constraint, int & offset) {
+   skipwhitespace(constraint, offset);
+   if (strncmp(&constraint[offset], "(and", 4) == 0) {
+     offset +=4;
+     Vector<BooleanEdge> vec;
+     while(true) {
+       skipwhitespace(constraint, offset);
+       if (constraint[offset] == ')') {
+       offset++;
+       return solver->applyLogicalOperation(SATC_AND, vec.expose(), vec.getSize());
+       }
+       vec.push(parseConstraint(solver, constraint, offset));
+     }
+   } else if (strncmp(&constraint[offset], "(<", 2) == 0) {
+     offset+=2;
+     skipwhitespace(constraint, offset);
+     int32_t v1 = getOrderVar(constraint, offset);
+     skipwhitespace(constraint, offset);
+     int32_t v2 = getOrderVar(constraint, offset);
+     skipwhitespace(constraint, offset);
+     if (constraint[offset++] != ')')
+       doExit();
+     return solver->orderConstraint(order, checkordervar(solver, v1), checkordervar(solver, v2));
+   } else if (strncmp(&constraint[offset], "(=", 2) == 0) {
+     offset+=2;
+     skipwhitespace(constraint, offset);
+     getOrderVar(constraint, offset);
+     skipwhitespace(constraint, offset);
+     getOrderVar(constraint, offset);
+     skipwhitespace(constraint, offset);
+     if (constraint[offset++] != ')')
+       doExit();
+     return solver->getBooleanTrue();
+   } else {
+     int32_t v = getBooleanVar(constraint, offset);
+     skipwhitespace(constraint, offset);
+     return checkBooleanVar(solver, v);
+   }
+ }
+ int skipahead(const char * token1, const char * token2) {
+   int index1 = 0, index2 = 0;
+   char buffer[256];
+   while(true) {
+     if (token1[index1] == 0)
+       return 1;
+     if (token2[index2] == 0)
+       return 2;
+     if (file->eof())
+       return 0;
+     file->read(buffer, 1);
+     if (buffer[0] == token1[index1])
+       index1++;
+     else
+       index1 = 0;
+     if (buffer[0] == token2[index2])
+       index2++;
+     else
+       index2 = 0;
+   }
+ }
+ char * readuntilend(const char * token) {
+   int index = 0;
+   char buffer[256];
+   int length = 256;
+   int offset = 0;
+   char * outbuffer = (char *) malloc(length);
+   while(true) {
+     if (token[index] == 0) {
+       outbuffer[offset - index] = 0;
+       return outbuffer;
+     }
+     if (file->eof()) {
+       free(outbuffer);
+       return NULL;
+     }
+       
+     file->read(buffer, 1);
+     outbuffer[offset++] = buffer[0];
+     if (offset == length) {
+       length = length * 2;
+       outbuffer = (char *) realloc(outbuffer, length);
+     }
+     if (buffer[0] == token[index])
+       index++;
+     else
+       index=0;
+   }
+ }
diff --combined src/ccsolver.cc
index 7707b74babcd70149011e1af8b9dea1f624c7398,aea2161e6da9eb5e8c62042a6c6f68ede22cb4cc..aca46a59e37331ee87b20281aaee464fa5e7e532
@@@ -104,16 -104,16 +104,16 @@@ void *applyPredicate(void *solver,void 
  
  void *applyLogicalOperation(void *solver,unsigned int op, void **array, unsigned int asize) {
        BooleanEdge constr [asize];
-       for(uint i=0; i< asize; i++){
-               constr[i] = BooleanEdge((Boolean*)array[i]);
+       for (uint i = 0; i < asize; i++) {
+               constr[i] = BooleanEdge((Boolean *)array[i]);
        }
        return CCSOLVER(solver)->applyLogicalOperation((LogicOp) op, constr, (uint) asize).getRaw();
  }
  
  void *applyExactlyOneConstraint(void *solver, void **array, unsigned int asize) {
        BooleanEdge constr [asize];
-       for(uint i=0; i< asize; i++){
-               constr[i] = BooleanEdge((Boolean*)array[i]);
+       for (uint i = 0; i < asize; i++) {
+               constr[i] = BooleanEdge((Boolean *)array[i]);
        }
        return CCSOLVER(solver)->applyExactlyOneConstraint( constr, (uint) asize).getRaw();
  }
@@@ -146,18 -146,10 +146,18 @@@ int solve(void *solver) 
        return CCSOLVER(solver)->solve();
  }
  
 +int solveIncremental(void *solver) {
 +      return CCSOLVER(solver)->solveIncremental();
 +}
 +
  long getElementValue(void *solver,void *element) {
        return (long) CCSOLVER(solver)->getElementValue((Element *)element);
  }
  
 +void freezeElement(void *solver,void *element) {
 +      CCSOLVER(solver)->freezeElement((Element *)element);
 +}
 +
  int getBooleanValue(void *solver, void *boolean) {
        return CCSOLVER(solver)->getBooleanValue(BooleanEdge((Boolean *) boolean));
  }
@@@ -170,10 -162,6 +170,10 @@@ void printConstraints(void *solver) 
        CCSOLVER(solver)->printConstraints();
  }
  
 +void turnoffOptimizations(void *solver) {
 +      CCSOLVER(solver)->turnoffOptimizations();
 +}
 +
  
  void serialize(void *solver) {
        CCSOLVER(solver)->serialize();
diff --combined src/csolver.cc
index 379858685235b90dd9514b4519417696d4bae906,17b3dc31b565db26711b89aebba6f4b31aa420c0..17e237888caa78445af6b5cb91b1b9c4ebcfcd39
@@@ -40,7 -40,6 +40,7 @@@ CSolver::CSolver() 
        unsat(false),
        booleanVarUsed(false),
        incrementalMode(false),
 +      optimizationsOff(false),
        tuner(NULL),
        elapsedTime(0),
        satsolverTimeout(NOTIMEOUT),
@@@ -244,10 -243,10 +244,10 @@@ void CSolver::mustHaveValue(Element *el
  }
  
  void CSolver::freezeElementsVariables() {
-       
-       for(uint i=0; i< allElements.getSize(); i++){
+       for (uint i = 0; i < allElements.getSize(); i++) {
                Element *e = allElements.get(i);
-               if(e->frozen){
+               if (e->frozen) {
                        satEncoder->freezeElementVariables(&e->encoding);
                }
        }
@@@ -409,24 -408,24 +409,24 @@@ BooleanEdge CSolver::rewriteLogicalOper
        return applyLogicalOperation(op, newarray, asize);
  }
  
- BooleanEdge CSolver::applyExactlyOneConstraint (BooleanEdge *array, uint asize){
+ BooleanEdge CSolver::applyExactlyOneConstraint (BooleanEdge *array, uint asize) {
        BooleanEdge newarray[asize + 1];
  
        newarray[asize] = applyLogicalOperation(SATC_OR, array, asize);
-       for (uint i=0; i< asize; i++){
+       for (uint i = 0; i < asize; i++) {
                BooleanEdge oprand1 = array[i];
-               BooleanEdge carray [asize -1];
+               BooleanEdge carray [asize - 1];
                uint index = 0;
-               for( uint j =0; j< asize; j++){
-                       if(i != j){
+               for ( uint j = 0; j < asize; j++) {
+                       if (i != j) {
                                BooleanEdge oprand2 = applyLogicalOperation(SATC_NOT, array[j]);
                                carray[index++] = applyLogicalOperation(SATC_IMPLIES, oprand1, oprand2);
                        }
                }
-               ASSERT(index == asize -1);
-               newarray[i] = applyLogicalOperation(SATC_AND, carray, asize-1);
+               ASSERT(index == asize - 1);
+               newarray[i] = applyLogicalOperation(SATC_AND, carray, asize - 1);
        }
-       return applyLogicalOperation(SATC_AND, newarray, asize+1);
+       return applyLogicalOperation(SATC_AND, newarray, asize + 1);
  }
  
  BooleanEdge CSolver::applyLogicalOperation(LogicOp op, BooleanEdge *array, uint asize) {
@@@ -567,7 -566,7 +567,7 @@@ BooleanEdge CSolver::orderConstraint(Or
  }
  
  void CSolver::addConstraint(BooleanEdge constraint) {
 -      if (!useInterpreter()) {
 +      if (!useInterpreter() && !optimizationsOff) {
                if (isTrue(constraint))
                        return;
                else if (isFalse(constraint)) {
@@@ -641,8 -640,8 +641,8 @@@ int CSolver::solveIncremental() 
        if (isUnSAT()) {
                return IS_UNSAT;
        }
-       
-       
        long long startTime = getTimeNano();
        bool deleteTuner = false;
        if (tuner == NULL) {
        }
        int result = IS_INDETER;
        ASSERT (!useInterpreter());
 -
 -      computePolarities(this);
 +      if(!optimizationsOff){
 +              computePolarities(this);
 +      }
  //    long long time1 = getTimeNano();
  //    model_print("Polarity time: %f\n", (time1 - startTime) / NANOSEC);
  //    Preprocess pp(this);
        //Doing element optimization on new constraints
  //    ElementOpt eop(this);
  //    eop.doTransform();
-       
        //Since no new element is added, we assuming adding new constraint
        //has no impact on previous encoding decisions
  //    EncodingGraph eg(this);
        time2 = getTimeNano();
        elapsedTime = time2 - startTime;
        model_print("CSOLVER solve time: %f\n", elapsedTime / NANOSEC);
-       
        if (deleteTuner) {
                delete tuner;
                tuner = NULL;
@@@ -735,39 -733,36 +735,39 @@@ int CSolver::solve() 
                        }
                        delete orderit;
                }
 +              long long time1, time2;
 +              
                computePolarities(this);
 -              long long time1 = getTimeNano();
 -              model_print("Polarity time: %f\n", (time1 - startTime) / NANOSEC);
 -              Preprocess pp(this);
 -              pp.doTransform();
 -              long long time2 = getTimeNano();
 -              model_print("Preprocess time: %f\n", (time2 - time1) / NANOSEC);
 -
 -              DecomposeOrderTransform dot(this);
 -              dot.doTransform();
                time1 = getTimeNano();
 -              model_print("Decompose Order: %f\n", (time1 - time2) / NANOSEC);
 +              model_print("Polarity time: %f\n", (time1 - startTime) / NANOSEC);
 +              if(!optimizationsOff){
 +                      Preprocess pp(this);
 +                      pp.doTransform();
 +                      time2 = getTimeNano();
 +                      model_print("Preprocess time: %f\n", (time2 - time1) / NANOSEC);
  
 -              IntegerEncodingTransform iet(this);
 -              iet.doTransform();
 +                      DecomposeOrderTransform dot(this);
 +                      dot.doTransform();
 +                      time1 = getTimeNano();
 +                      model_print("Decompose Order: %f\n", (time1 - time2) / NANOSEC);
  
 -              ElementOpt eop(this);
 -              eop.doTransform();
 +                      IntegerEncodingTransform iet(this);
 +                      iet.doTransform();
  
 -              EncodingGraph eg(this);
 -              eg.encode();
 +                      ElementOpt eop(this);
 +                      eop.doTransform();
  
 +                      EncodingGraph eg(this);
 +                      eg.encode();
 +              }
                naiveEncodingDecision(this);
                //      eg.validate();
 -
 -              VarOrderingOpt bor(this, satEncoder);
 -              bor.doTransform();
 -
 -              time2 = getTimeNano();
 -              model_print("Encoding Graph Time: %f\n", (time2 - time1) / NANOSEC);
 +              if(!optimizationsOff){
 +                      VarOrderingOpt bor(this, satEncoder);
 +                      bor.doTransform();
 +                      time2 = getTimeNano();
 +                      model_print("Encoding Graph Time: %f\n", (time2 - time1) / NANOSEC);
 +              }
  
                satEncoder->encodeAllSATEncoder(this);
                time1 = getTimeNano();
                model_print("Elapse Encode time: %f\n", (time1 - startTime) / NANOSEC);
  
                model_print("Is problem UNSAT after encoding: %d\n", unsat);
-               
  
                result = unsat ? IS_UNSAT : satEncoder->solve(satsolverTimeout);
                model_print("Result Computed in SAT solver:\t%s\n", result == IS_SAT ? "SAT" : result == IS_INDETER ? "INDETERMINATE" : " UNSAT");
@@@ -842,9 -837,9 +842,9 @@@ uint64_t CSolver::getElementValue(Eleme
        exit(-1);
  }
  
- void CSolver::freezeElement(Element *e){
+ void CSolver::freezeElement(Element *e) {
        e->freezeElement();
-       if(!incrementalMode){
+       if (!incrementalMode) {
                incrementalMode = true;
        }
  }
diff --combined src/csolver.h
index 49438b697b1235287cba1a437ec4b17aa63c9f7f,b27e3c00038d586908d6d17bb80f79a774b7eaed..eba7b3ccf47ffa7abb4dbae45e398591a8fd025c
@@@ -58,7 -58,7 +58,7 @@@ public
        Set *getElementRange (Element *element);
  
        void mustHaveValue(Element *element);
-       
        BooleanEdge getBooleanTrue();
  
        BooleanEdge getBooleanFalse();
  
        /** This exactly one element of array can be true! (i.e. a1 + a2 + a3 + ... + an = 1)*/
        BooleanEdge applyExactlyOneConstraint (BooleanEdge *array, uint asize);
-       
        /** This function applies a logical operation to the Booleans in its input. */
-       
        BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
  
        /** This function applies a logical operation to the Booleans in its input. */
         * Incremental Solving for SATUNE.
         * It only supports incremental solving for elements!
         * No support for BooleanVar, BooleanOrder or using interpreters
-        * @return 
+        * @return
         */
        int solveIncremental();
-       
        /** After getting the solution from the SAT solver, client can get the value of an element via this function*/
        uint64_t getElementValue(Element *element);
  
        void freezeElement(Element *e);
-       
 -
 +      void turnoffOptimizations(){optimizationsOff = true;}
-       
        /** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
        bool getBooleanValue(BooleanEdge boolean);
  
        SetIteratorBooleanEdge *getConstraints() { return constraints.iterator(); }
        bool isConstraintEncoded(BooleanEdge be) { return encodedConstraints.contains(be);}
        void addEncodedConstraint(BooleanEdge be) {encodedConstraints.add(be);}
-       
        SATEncoder *getSATEncoder() {return satEncoder;}
  
        void replaceBooleanWithTrue(BooleanEdge bexpr);
@@@ -196,7 -194,7 +194,7 @@@ private
        void handleIFFTrue(BooleanLogic *bexpr, BooleanEdge child);
        void handleANDTrue(BooleanLogic *bexpr, BooleanEdge child);
        void handleFunction(ElementFunction *ef, BooleanEdge child);
-       
        //These two functions are helpers if the client has a pointer to a
        //Boolean object that we have since replaced
        BooleanEdge rewriteLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
        bool unsat;
        bool booleanVarUsed;
        bool incrementalMode;
 +      bool optimizationsOff;
        Tuner *tuner;
        long long elapsedTime;
        long satsolverTimeout;
        Interpreter *interpreter;
 +      bool noOptimization;
        friend class ElementOpt;
        friend class VarOrderingOpt;
  };
index e337590fa92b409cb9272beb9e65a26ea8cfad77,37bfba46129c9db1664436af915ccd4af2ae030f..0a7d6725773f4219a85b45dea0eafe5cdf5bff96
@@@ -1,7 -1,7 +1,7 @@@
  /* DO NOT EDIT THIS FILE - it is machine generated */
  #include "satune_SatuneJavaAPI.h"
  #include "ccsolver.h"
- #define CCSOLVER(solver) (void*)solver
+ #define CCSOLVER(solver) (void *)solver
  /* Header for class SatuneJavaAPI */
  
  /*
@@@ -14,7 -14,7 +14,7 @@@ JNIEXPORT jlong JNICALL Java_satune_Sat
        (JNIEnv *env, jobject obj)
  {
        return (jlong)createCCSolver();
-       
  }
  
  /*
@@@ -158,7 -158,7 +158,7 @@@ JNIEXPORT jlong JNICALL Java_satune_Sat
   * Signature: (JI)J
   */
  JNIEXPORT jlong JNICALL Java_satune_SatuneJavaAPI_getBooleanTrue
-       (JNIEnv * env, jobject obj, jlong solver)
+       (JNIEnv *env, jobject obj, jlong solver)
  {
        return (jlong)getBooleanTrue((void *)solver);
  }
   * Signature: (JI)J
   */
  JNIEXPORT jlong JNICALL Java_satune_SatuneJavaAPI_getBooleanFalse
-       (JNIEnv * env, jobject obj, jlong solver)
+       (JNIEnv *env, jobject obj, jlong solver)
  {
        return (jlong)getBooleanFalse((void *)solver);
  }
@@@ -391,17 -391,6 +391,17 @@@ JNIEXPORT jint JNICALL Java_satune_Satu
        return (jint) solve((void *)solver);
  }
  
 +/*
 + * Class:     SatuneJavaAPI
 + * Method:    solveIncremental
 + * Signature: (J)I
 + */
 +JNIEXPORT jint JNICALL Java_satune_SatuneJavaAPI_solveIncremental
 +      (JNIEnv *env, jobject obj, jlong solver)
 +{
 +      return (jint) solveIncremental((void *)solver);
 +}
 +
  /*
   * Class:     SatuneJavaAPI
   * Method:    getElementValue
@@@ -413,17 -402,6 +413,17 @@@ JNIEXPORT jlong JNICALL Java_satune_Sat
        return (jlong) getElementValue((void *)solver,(void *)element);
  }
  
 +/*
 + * Class:     SatuneJavaAPI
 + * Method:    freezeElement
 + * Signature: (JJ)J
 + */
 +JNIEXPORT void JNICALL Java_satune_SatuneJavaAPI_freezeElement
 +      (JNIEnv *env, jobject obj, jlong solver, jlong element)
 +{
 +      freezeElement((void *)solver,(void *)element);
 +}
 +
  /*
   * Class:     SatuneJavaAPI
   * Method:    getBooleanValue
@@@ -457,17 -435,6 +457,17 @@@ JNIEXPORT void JNICALL Java_satune_Satu
        printConstraints((void *)solver);
  }
  
 +/*
 + * Class:     SatuneJavaAPI
 + * Method:    turnoffOptimizations
 + * Signature: (J)V
 + */
 +JNIEXPORT void JNICALL Java_satune_SatuneJavaAPI_turnoffOptimizations
 +      (JNIEnv *env, jobject obj, jlong solver)
 +{
 +      turnoffOptimizations((void *)solver);
 +}
 +
  /*
   * Class:     SatuneJavaAPI
   * Method:    serialize
index e606b44a74388e8cbb322e2f86b44019a83cce8b,93a386df53c7b49999410adbbbc45e53cd5e75e9..0a0b6e5c2cc8301f443a180444f9a60e71c6907e
@@@ -38,7 -38,7 +38,7 @@@ JNIEXPORT void JNICALL Java_satune_Satu
   * Signature: (JIJI)J
   */
  JNIEXPORT jlong JNICALL Java_satune_SatuneJavaAPI_createSet
-       (JNIEnv *, jobject , jlong , jint , jlongArray arr);
+       (JNIEnv *, jobject, jlong, jint, jlongArray arr);
  
  /*
   * Class:     satune_SatuneJavaAPI
@@@ -280,14 -280,6 +280,14 @@@ JNIEXPORT jlong JNICALL Java_satune_Sat
  JNIEXPORT jint JNICALL Java_satune_SatuneJavaAPI_solve
        (JNIEnv *, jobject, jlong);
  
 +/*
 + * Class:     satune_SatuneJavaAPI
 + * Method:    solveIncremental
 + * Signature: (J)I
 + */
 +JNIEXPORT jint JNICALL Java_satune_SatuneJavaAPI_solveIncremental
 +      (JNIEnv *, jobject, jlong);
 +
  /*
   * Class:     satune_SatuneJavaAPI
   * Method:    getElementValue
  JNIEXPORT jlong JNICALL Java_satune_SatuneJavaAPI_getElementValue
        (JNIEnv *, jobject, jlong, jlong);
  
 +
 +/*
 + * Class:     satune_SatuneJavaAPI
 + * Method:    getElementValue
 + * Signature: (JJ)J
 + */
 +JNIEXPORT void JNICALL Java_satune_SatuneJavaAPI_freezeElement
 +      (JNIEnv *, jobject, jlong, jlong);
 +
  /*
   * Class:     satune_SatuneJavaAPI
   * Method:    getBooleanValue
@@@ -329,14 -312,6 +329,14 @@@ JNIEXPORT jint JNICALL Java_satune_Satu
  JNIEXPORT void JNICALL Java_satune_SatuneJavaAPI_printConstraints
        (JNIEnv *, jobject, jlong);
  
 +/*
 + * Class:     satune_SatuneJavaAPI
 + * Method:    turnoffOptimizations
 + * Signature: (J)V
 + */
 +JNIEXPORT void JNICALL Java_satune_SatuneJavaAPI_turnoffOptimizations
 +      (JNIEnv *, jobject, jlong);
 +
  /*
   * Class:     satune_SatuneJavaAPI
   * Method:    serialize