#include "cnfexpr.h"
-
+#include <stdio.h>
/*
V2 Copyright (c) 2014 Ben Chambers, Eugene Goldberg, Pete Manolios,
Vasilis Papavasileiou, Sudarshan Srinivasan, and Daron Vroon.
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(")");
+ }
+}
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;}
#define SATSOLVER "sat_solver"
#include <fcntl.h>
#include "common.h"
+#include <string.h>
IncrementalSolver * allocIncrementalSolver() {
IncrementalSolver *This=(IncrementalSolver *)ourmalloc(sizeof(IncrementalSolver));
}
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) {
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);
}
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);