BooleanConst::BooleanConst(bool _isTrue) :
Boolean(BOOLCONST),
- isTrue(_isTrue) {
+ istrue(_isTrue) {
}
BooleanVar::BooleanVar(VarType t) :
}
Boolean *BooleanConst::clone(CSolver *solver, CloneMap *map) {
- if (isTrue)
+ if (istrue)
return solver->getBooleanTrue();
else
return solver->getBooleanFalse();
public:
Boolean(ASTNodeType _type);
virtual ~Boolean() {}
- virtual Boolean *clone(CSolver *solver, CloneMap *map) { ASSERT(0); return NULL; }
+ virtual Boolean *clone(CSolver *solver, CloneMap *map) = 0;
+ virtual bool isTrue() {return false;}
+ virtual bool isFalse() {return false;}
Polarity polarity;
BooleanValue boolVal;
Vector<Boolean *> parents;
public:
BooleanConst(bool isTrue);
Boolean *clone(CSolver *solver, CloneMap *map);
- bool isTrue;
+ bool isTrue() {return istrue;}
+ bool isFalse() {return !istrue;}
+ bool istrue;
CMEMALLOC;
};
Boolean *pred = solver->applyPredicate(equal2, inputs2, 2);
solver->addConstraint(pred);
- if (solver->startEncoding() == 1)
+ if (solver->solve() == 1)
printf("e1=%" PRIu64 " e2=%" PRIu64 " \n", solver->getElementValue(e1), solver->getElementValue(e2));
else
printf("UNSAT\n");
Boolean *b = solver->applyPredicate(equals, inputs, 2);
solver->addConstraint(b);
- if (solver->startEncoding() == 1)
+ if (solver->solve() == 1)
printf("e1=%" PRIu64 " e2=%" PRIu64 "\n", solver->getElementValue(e1), solver->getElementValue(e2));
else
printf("UNSAT\n");
Boolean *b = solver->applyPredicate(equals, inputs, 2);
solver->addConstraint(b);
- if (solver->startEncoding() == 1)
+ if (solver->solve() == 1)
printf("e1=%" PRIu64 " e2=%" PRIu64 "\n", solver->getElementValue(e1), solver->getElementValue(e2));
else
printf("UNSAT\n");
Boolean *pred = solver->applyPredicate(gt, inputs2, 2);
solver->addConstraint(pred);
- if (solver->startEncoding() == 1)
+ if (solver->solve() == 1)
printf("e1=%" PRIu64 " e2=%" PRIu64 " e7=%" PRIu64 "\n",
solver->getElementValue(e1), solver->getElementValue(e2), solver->getElementValue(e7));
else
solver->addConstraint(solver->applyLogicalOperation(SATC_OR, barray4, 2));
Boolean *barray5[] = {b1, b4};
solver->addConstraint(solver->applyLogicalOperation(SATC_XOR, barray5, 2));
- if (solver->startEncoding() == 1)
+ if (solver->solve() == 1)
printf("b1=%d b2=%d b3=%d b4=%d\n",
solver->getBooleanValue(b1), solver->getBooleanValue(b2),
solver->getBooleanValue(b3), solver->getBooleanValue(b4));
Element *inputs2[] = {e1, e2};
Boolean *b = solver->applyPredicate(lt, inputs2, 2);
solver->addConstraint(b);
- if (solver->startEncoding() == 1)
+ if (solver->solve() == 1)
printf("e1=%" PRIu64 " e2=%" PRIu64 "\n", solver->getElementValue(e1), solver->getElementValue(e2));
else
printf("UNSAT\n");
Boolean * array12[] = {o58, o81};
solver->addConstraint(solver->applyLogicalOperation(SATC_AND, array12, 2) );
- /* if (solver->startEncoding() == 1)
+ /* if (solver->solve() == 1)
printf("SAT\n");
else
printf("UNSAT\n");*/
Boolean *b2 = solver->orderConstraint(order, 1, 4);
solver->addConstraint(b1);
solver->addConstraint(b2);
- if (solver->startEncoding() == 1)
+ if (solver->solve() == 1)
printf("SAT\n");
else
printf("UNSAT\n");
Boolean *pred = solver->applyPredicate(lte, inputs2, 2);
solver->addConstraint(pred);
- if (solver->startEncoding() == 1)
+ if (solver->solve() == 1)
printf("e1=%" PRIu64 " e2=%" PRIu64 " e3=%" PRIu64 " e4=%" PRIu64 " overFlow:%d\n",
solver->getElementValue(e1), solver->getElementValue(e2), solver->getElementValue(e3),
solver->getElementValue(e4), solver->getBooleanValue(overflow));
Boolean *pred2 = solver->applyPredicate(eq, tmparray2, 2);
solver->addConstraint(pred2);
- if (solver->startEncoding() == 1)
+ if (solver->solve() == 1)
printf("e1=%" PRIu64 " e2=%" PRIu64 " e3=%" PRIu64 " undefFlag:%d\n",
solver->getElementValue(e1), solver->getElementValue(e2),
solver->getElementValue(e3), solver->getBooleanValue(undef));
long long AutoTuner::evaluate(CSolver * problem, SearchTuner *tuner) {
CSolver * copy=problem->clone();
copy->setTuner(tuner);
- int result = copy->startEncoding();
+ int result = copy->solve();
long long elapsedTime=copy->getElapsedTime();
long long encodeTime=copy->getEncodeTime();
long long solveTime=copy->getSolveTime();
return set;
}
+Element *CSolver::createRangeVar(VarType type, uint64_t lowrange, uint64_t highrange) {
+ Set *s = createRangeSet(type, lowrange, highrange);
+ return getElementVar(s);
+}
+
MutableSet *CSolver::createMutableSet(VarType type) {
MutableSet *set = new MutableSet(type);
allSets.push(set);
}
}
+bool CSolver::isTrue(Boolean *b) {
+ return b->isTrue();
+}
+
+bool CSolver::isFalse(Boolean *b) {
+ return b->isFalse();
+}
+
+Boolean *CSolver::applyLogicalOperation(LogicOp op, Boolean * arg1, Boolean * arg2) {
+ Boolean * array[] = {arg1, arg2};
+ return applyLogicalOperation(op, array, 2);
+}
+
+Boolean *CSolver::applyLogicalOperation(LogicOp op, Boolean *arg) {
+ Boolean * array[] = {arg};
+ return applyLogicalOperation(op, array, 1);
+}
+
+
Boolean *CSolver::applyLogicalOperation(LogicOp op, Boolean **array, uint asize) {
Boolean * newarray[asize];
switch(op) {
if (array[0]->type == LOGICOP && ((BooleanLogic *)array[0])->op==SATC_NOT) {
return ((BooleanLogic *) array[0])->inputs.get(0);
} else if (array[0]->type == BOOLCONST) {
- bool isTrue = ((BooleanConst *) array[0])->isTrue;
- return isTrue ? boolFalse : boolTrue;
+ return array[0]->isTrue() ? boolFalse : boolTrue;
}
break;
}
case SATC_XOR: {
for(uint i=0;i<2;i++) {
if (array[i]->type == BOOLCONST) {
- bool isTrue = ((BooleanConst *) array[i])->isTrue;
- if (isTrue) {
+ if (array[i]->isTrue()) {
newarray[0]=array[1-i];
return applyLogicalOperation(SATC_NOT, newarray, 1);
} else
for(uint i=0;i<asize;i++) {
Boolean *b=array[i];
if (b->type == BOOLCONST) {
- bool isTrue = ((BooleanConst *) b)->isTrue;
- if (isTrue)
+ if (b->isTrue())
return b;
else
continue;
for(uint i=0;i<asize;i++) {
Boolean *b=array[i];
if (b->type == BOOLCONST) {
- bool isTrue = ((BooleanConst *) b)->isTrue;
- if (isTrue)
+ if (b->isTrue())
continue;
else
return b;
}
case SATC_IMPLIES: {
if (array[0]->type == BOOLCONST) {
- BooleanConst *b=(BooleanConst *) array[0];
- if (b->isTrue) {
+ if (array[0]->isTrue()) {
return array[1];
} else {
return boolTrue;
}
} else if (array[1]->type == BOOLCONST) {
- BooleanConst *b=(BooleanConst *) array[0];
- if (b->isTrue) {
- return b;
+ if (array[1]->isTrue()) {
+ return array[1];
} else {
return applyLogicalOperation(SATC_NOT, array, 1);
}
return order;
}
-int CSolver::startEncoding() {
+int CSolver::solve() {
bool deleteTuner = false;
if (tuner == NULL) {
tuner = new DefaultTuner();
Set *createRangeSet(VarType type, uint64_t lowrange, uint64_t highrange);
+ Element *createRangeVar(VarType type, uint64_t lowrange, uint64_t highrange);
+
/** This function creates a mutable set. */
MutableSet *createMutableSet(VarType type);
Boolean *applyLogicalOperation(LogicOp op, Boolean **array, uint asize);
+ /** This function applies a logical operation to the Booleans in its input. */
+
+ Boolean *applyLogicalOperation(LogicOp op, Boolean * arg1, Boolean * arg2);
+
+ /** This function applies a logical operation to the Booleans in its input. */
+
+ Boolean *applyLogicalOperation(LogicOp op, Boolean *arg);
+
/** This function adds a boolean constraint to the set of constraints
to be satisfied */
Boolean *orderConstraint(Order *order, uint64_t first, uint64_t second);
/** When everything is done, the client calls this function and then csolver starts to encode*/
- int startEncoding();
+ int solve();
/** After getting the solution from the SAT solver, client can get the value of an element via this function*/
uint64_t getElementValue(Element *element);
HappenedBefore getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
+ bool isTrue(Boolean *b);
+ bool isFalse(Boolean *b);
+
void setUnSAT() { unsat = true; }
bool isUnSAT() { return unsat; }