Edits to merge
[satune.git] / src / csolver.cc
index fe2111036f1281b8fb366cbf35d3e0f9c7782168..592d1d51baf89e7c8f6b4a3d043ea4b07604be34 100644 (file)
@@ -260,11 +260,11 @@ BooleanEdge CSolver::applyPredicateTable(Predicate *predicate, Element **inputs,
 }
 
 bool CSolver::isTrue(BooleanEdge b) {
-       return b.isNegated()?b->isFalse():b->isTrue();
+        return b.isNegated()?b->isFalse():b->isTrue();
 }
 
 bool CSolver::isFalse(BooleanEdge b) {
-       return b.isNegated()?b->isTrue():b->isFalse();
+        return b.isNegated()?b->isTrue():b->isFalse();
 }
 
 BooleanEdge CSolver::applyLogicalOperation(LogicOp op, BooleanEdge arg1, BooleanEdge arg2) {
@@ -312,9 +312,9 @@ BooleanEdge CSolver::applyLogicalOperation(LogicOp op, BooleanEdge *array, uint
        case SATC_IFF: {
                for (uint i = 0; i < 2; i++) {
                        if (array[i]->type == BOOLCONST) {
-                               if (array[i]->isTrue()) {
+                               if (isTrue(array[i])) { // It can be undefined
                                        return array[1 - i];
-                               } else {
+                               } else if(isFalse(array[i])) {
                                        newarray[0] = array[1 - i];
                                        return applyLogicalOperation(SATC_NOT, newarray, 1);
                                }
@@ -342,10 +342,11 @@ BooleanEdge CSolver::applyLogicalOperation(LogicOp op, BooleanEdge *array, uint
                                        return rewriteLogicalOperation(op, array, asize);
                        }
                        if (b->type == BOOLCONST) {
-                               if (b->isTrue())
+                               if (isTrue(b))
                                        continue;
-                               else
+                               else{
                                        return boolFalse;
+                                }
                        } else
                                newarray[newindex++] = b;
                }
@@ -380,21 +381,27 @@ BooleanEdge CSolver::applyLogicalOperation(LogicOp op, BooleanEdge *array, uint
                return BooleanEdge(boolean);
        } else {
                delete boolean;
-               return BooleanEdge(b);
+               return BooleanEdge(boolean);
        }
 }
 
 BooleanEdge CSolver::orderConstraint(Order *order, uint64_t first, uint64_t second) {
+       ASSERT(first != second);
        Boolean *constraint = new BooleanOrder(order, first, second);
        allBooleans.push(constraint);
        return BooleanEdge(constraint);
 }
 
 void CSolver::addConstraint(BooleanEdge constraint) {
+       if(constraint.isNegated())
+               model_print("!");
+       constraint.getBoolean()->print();
        if (isTrue(constraint))
                return;
-       else if (isFalse(constraint))
+       else if (isFalse(constraint)) {
+               int t=0;
                setUnSAT();
+       }
        else {
                if (constraint->type == LOGICOP) {
                        BooleanLogic *b=(BooleanLogic *) constraint.getBoolean();
@@ -414,8 +421,9 @@ void CSolver::addConstraint(BooleanEdge constraint) {
                constraints.add(constraint);
                Boolean *ptr=constraint.getBoolean();
                
-               if (ptr->boolVal == BV_UNSAT)
+               if (ptr->boolVal == BV_UNSAT) {
                        setUnSAT();
+               }
                
                replaceBooleanWithTrueNoRemove(constraint);
                constraint->parents.clear();
@@ -439,8 +447,8 @@ int CSolver::solve() {
        long long startTime = getTimeNano();
        computePolarities(this);
 
-//     Preprocess pp(this);
-//     pp.doTransform();
+       Preprocess pp(this);
+       pp.doTransform();
        
        DecomposeOrderTransform dot(this);
        dot.doTransform();
@@ -448,13 +456,15 @@ int CSolver::solve() {
        IntegerEncodingTransform iet(this);
        iet.doTransform();
 
-//     EncodingGraph eg(this);
-//     eg.buildGraph();
-//     eg.encode();
+       EncodingGraph eg(this);
+       eg.buildGraph();
+       eg.encode();
        
        naiveEncodingDecision(this);
        satEncoder->encodeAllSATEncoder(this);
+        model_print("Is problem UNSAT after encoding: %d\n", unsat);
        int result = unsat ? IS_UNSAT : satEncoder->solve();
+        model_print("Result Computed in CSolver: %d\n", result);
        long long finishTime = getTimeNano();
        elapsedTime = finishTime - startTime;
        if (deleteTuner) {