Merge branch 'hamed' into brian
authorbdemsky <bdemsky@uci.edu>
Tue, 11 Jul 2017 01:48:32 +0000 (18:48 -0700)
committerbdemsky <bdemsky@uci.edu>
Tue, 11 Jul 2017 01:48:32 +0000 (18:48 -0700)
src/Backend/cnfexpr.c
src/Backend/cnfexpr.h
src/Backend/inc_solver.c
src/Backend/nodeedge.c
src/Test/testcnf.c

index 6bbbbfc..dbbd93f 100644 (file)
@@ -1,5 +1,5 @@
 #include "cnfexpr.h"
-
+#include <stdio.h>
 /* 
 V2 Copyright (c) 2014 Ben Chambers, Eugene Goldberg, Pete Manolios,
 Vasilis Papavasileiou, Sudarshan Srinivasan, and Daron Vroon.
@@ -445,5 +445,21 @@ void disjoinCNFExpr(CNFExpr *This, CNFExpr *expr, bool destroy) {
                deleteCNFExpr(expr);
 }
 
-
-
+void printCNFExpr(CNFExpr *This) {
+       for(uint i=0;i<getSizeLitVector(&This->singletons);i++) {
+               if (i!=0)
+                       printf(" ^ ");
+               Literal l=getLiteralLitVector(&This->singletons,i);
+               printf ("%d",l);
+       }
+       for(uint i=0;i<getSizeVectorLitVector(&This->clauses);i++) {
+               LitVector *lv=getVectorLitVector(&This->clauses,i);
+               printf(" ^ (");
+               for(uint j=0;j<getSizeLitVector(lv);j++) {
+                       if (j!=0)
+                               printf(" v ");
+                       printf("%d", getLiteralLitVector(lv, j));
+               }
+               printf(")");
+       }
+}
index 5f1f907..1b64528 100644 (file)
@@ -43,6 +43,7 @@ CNFExpr * allocCNFExprBool(bool isTrue);
 CNFExpr * allocCNFExprLiteral(Literal l);
 void deleteCNFExpr(CNFExpr *This);
 void clearCNFExpr(CNFExpr *This, bool isTrue);
+void printCNFExpr(CNFExpr *This);
 
 void copyCNF(CNFExpr *This, CNFExpr *expr, bool destroy);
 static inline bool alwaysTrueCNF(CNFExpr * This) {return (This->litSize==0) && This->isTrue;}
index 307114e..935aff9 100644 (file)
@@ -11,6 +11,7 @@
 #define SATSOLVER "sat_solver"
 #include <fcntl.h>
 #include "common.h"
+#include <string.h>
 
 IncrementalSolver * allocIncrementalSolver() {
        IncrementalSolver *This=(IncrementalSolver *)ourmalloc(sizeof(IncrementalSolver));
@@ -44,16 +45,25 @@ void addClauseLiteral(IncrementalSolver * This, int literal) {
 }
 
 void addArrayClauseLiteral(IncrementalSolver * This, uint numliterals, int * literals) {
-       for(uint i=0;i<numliterals; i++) {
-               This->buffer[This->offset++]=literals[i];
-               if (This->offset==IS_BUFFERSIZE) {
+       uint index=0;
+       while(true) {
+               uint bufferspace=IS_BUFFERSIZE-This->offset;
+               uint numtowrite=numliterals-index;
+               if (bufferspace > numtowrite) {
+                       memcpy(&This->buffer[This->offset], &literals[index], numtowrite*sizeof(int));
+                       This->offset+=numtowrite;
+                       This->buffer[This->offset++]=0; //have one extra spot always
+                       if (This->offset==IS_BUFFERSIZE) {//Check if full
+                               flushBufferSolver(This);
+                       }
+                       return;
+               } else {
+                       memcpy(&This->buffer[This->offset], &literals[index], bufferspace*sizeof(int));
+                       This->offset+=bufferspace;
+                       index+=bufferspace;
                        flushBufferSolver(This);
                }
        }
-       This->buffer[This->offset++]=0;
-       if (This->offset==IS_BUFFERSIZE) {
-               flushBufferSolver(This);
-       }
 }
 
 void finishedClauses(IncrementalSolver * This) {
index 9e85bfc..9d6e855 100644 (file)
@@ -167,7 +167,7 @@ Edge constraintOR(CNF * cnf, uint numEdges, Edge *edges) {
 Edge constraintOR2(CNF * cnf, Edge left, Edge right) {
        Edge lneg=constraintNegate(left);
        Edge rneg=constraintNegate(right);
-       Edge eand=constraintAND2(cnf, left, right);
+       Edge eand=constraintAND2(cnf, lneg, rneg);
        return constraintNegate(eand);
 }
 
index d5f4166..ddad6d7 100644 (file)
@@ -10,13 +10,17 @@ int main(int numargs, char ** argv) {
        printCNF(nv1);
        printf("\n");
        Edge nv2=constraintNegate(v2);
+       Edge nv3=constraintNegate(v3);
        Edge iff1=constraintIFF(cnf, nv1, v2);
        printCNF(iff1);
        printf("\n");
-       Edge iff2=constraintIFF(cnf, nv2, v3);
+
+       Edge iff2=constraintOR2(cnf, constraintAND2(cnf, v2, v3), constraintAND2(cnf, nv2, nv3));
+       printCNF(iff2);
+       printf("\n");
        Edge iff3=constraintIFF(cnf, v3, nv1);
        Edge cand=constraintAND(cnf, 3, (Edge[]) {iff1, iff2, iff3});
-       //Edge cand=constraintAND(cnf, 2, (Edge[]) {iff1, iff2});
+
        printCNF(cand);
        printf("\n");
        addConstraint(cnf, cand);