#Ignoring netbeans configs
nbproject/
+sat_solver
+setup.sh
#Ignoring binary files
src/bin/
src/lib_cons_comp.so
/src/mymemory.cc
.*
-*.dSYM
\ No newline at end of file
+*.dSYM
void printConstraint(Constraint * c);
void dumpConstraint(Constraint * c, IncrementalSolver *solver);
static inline uint getVarConstraint(Constraint * c) {ASSERT(c->type==VAR); return c->numoperandsorvar;}
-VectorConstraint * simplify(Constraint * c);
+VectorConstraint * simplifyConstraint(Constraint * This);
static inline CType getType(Constraint * c) {return c->type;}
static inline bool isFalse(Constraint * c) {return c->type==FALSE;}
static inline bool isTrue(Constraint * c) {return c->type==TRUE;}
SATEncoder * allocSATEncoder() {
SATEncoder *This=ourmalloc(sizeof (SATEncoder));
This->varcount=1;
+ This->satSolver = allocIncrementalSolver();
return This;
}
void deleteSATEncoder(SATEncoder *This) {
+ deleteIncrementalSolver(This->satSolver);
ourfree(This);
}
generateElementEncodingVariables(encoder, getElementEncoding(This));
switch(getElementEncoding(This)->type){
case ONEHOT:
+ //FIXME
ASSERT(0);
break;
case UNARY:
return NULL;
}
+void addConstraintToSATSolver(Constraint *c, IncrementalSolver* satSolver) {
+ VectorConstraint* simplified = simplifyConstraint(c);
+ uint size = getSizeVectorConstraint(simplified);
+ for(uint i=0; i<size; i++) {
+ Constraint *simp=getVectorConstraint(simplified, i);
+ if (simp->type==TRUE)
+ continue;
+ ASSERT(simp->type!=FALSE);
+ dumpConstraint(simp, satSolver);
+ }
+ deleteVectorConstraint(simplified);
+}
+
void encodeAllSATEncoder(CSolver *csolver, SATEncoder * This) {
VectorBoolean *constraints=csolver->constraints;
uint size=getSizeVectorBoolean(constraints);
for(uint i=0;i<size;i++) {
Boolean *constraint=getVectorBoolean(constraints, i);
Constraint* c= encodeConstraintSATEncoder(This, constraint);
+ addConstraintToSATSolver(c, This->satSolver);
printConstraint(c);
model_print("\n\n");
+ //FIXME: When do we want to delete constraints? Should we keep an array of them
+ // and delete them later, or it would be better to just delete them right away?
}
}
#include "classlist.h"
#include "structs.h"
+#include "inc_solver.h"
struct SATEncoder {
uint varcount;
+ IncrementalSolver* satSolver;
};
SATEncoder * allocSATEncoder();
Constraint* encodeEnumTableElemFunctionSATEncoder(SATEncoder* encoder, ElementFunction* This);
Constraint* encodeTableElementFunctionSATEncoder(SATEncoder* encoder, ElementFunction* This);
Constraint* encodeOperatorElementFunctionSATEncoder(SATEncoder* encoder,ElementFunction* This);
+void addConstraintToSATSolver(Constraint *c, IncrementalSolver* satSolver);
#endif
Element* inputs2 [] = {e4, e3};
Boolean* pred = applyPredicate(solver, equal2, inputs2, 2);
addBoolean(solver, pred);
- startEncoding(solver);
+// startEncoding(solver);
deleteSolver(solver);
}
void startEncoding(CSolver* solver){
naiveEncodingDecision(solver);
SATEncoder* satEncoder = allocSATEncoder();
-// initializeConstraintVars(solver, satEncoder);
+ createSolver(satEncoder->satSolver);
encodeAllSATEncoder(solver, satEncoder);
+ finishedClauses(satEncoder->satSolver);
+ solve(satEncoder->satSolver);
+ int result= getSolution(satEncoder->satSolver);
+ model_print("sat_solver's result:%d\n", result);
+ killSolver(satEncoder->satSolver);
//For now, let's just delete it, and in future for doing queries
//we may need it.
deleteSATEncoder(satEncoder);