ASTNode(_type),
encoding(this),
anyValue(false),
- frozen(false){
+ frozen(false) {
}
ElementSet::ElementSet(Set *s) :
Vector<ASTNode *> parents;
ElementEncoding encoding;
inline ElementEncoding *getElementEncoding() { return &encoding; }
- inline void freezeElement(){frozen = true;}
- inline bool isFrozen(){return frozen;}
+ inline void freezeElement() {frozen = true;}
+ inline bool isFrozen() {return frozen;}
virtual Element *clone(CSolver *solver, CloneMap *map) {ASSERT(0); return NULL;};
virtual void serialize(Serializer *serializer) = 0;
virtual void print() = 0;
while (orderit->hasNext()) {
Order *order = orderit->next();
if (order->type == SATC_PARTIAL)
- continue;
+ continue;
if (GETVARTUNABLE(solver->getTuner(), order->set->type, ORDERINTEGERENCODING, &offon))
integerEncode(order);
}
addArrayClauseLiteral(cnf->solver, numliterals, literals);
}
-void freezeVariable(CNF *cnf, Edge e){
+void freezeVariable(CNF *cnf, Edge e) {
int literal = getEdgeVar(e);
freeze(cnf->solver, literal);
}
}
readSolver(This, &This->solution[1], numVars * sizeof(int));
This->solutionsize = numVars;
- } else { //Reading unsat explanation
+ } else {//Reading unsat explanation
int numVars = readIntSolver(This);
if (numVars > This->solutionsize) {
if (This->solution != NULL)
generateAnyValueBinaryValueEncoding(encoding);
}
-void SATEncoder::freezeElementVariables(ElementEncoding *encoding){
+void SATEncoder::freezeElementVariables(ElementEncoding *encoding) {
ASSERT(encoding->element->frozen);
- for(uint i=0; i< encoding->numVars; i++){
+ for (uint i = 0; i < encoding->numVars; i++) {
Edge e = encoding->variables[i];
ASSERT(edgeIsVarConst(e));
freezeVariable(cnf, e);
long long startTime = getTimeNano();
finishedClauses(cnf->solver);
cnf->encodeTime = getTimeNano() - startTime;
- if(solver->isIncrementalMode()){
+ if (solver->isIncrementalMode()) {
solver->freezeElementsVariables();
}
return solveCNF(cnf);
SetIteratorBooleanEdge *iterator = csolver->getConstraints();
while (iterator->hasNext()) {
BooleanEdge constraint = iterator->next();
- if(!csolver->isConstraintEncoded(constraint)){
+ if (!csolver->isConstraintEncoded(constraint)) {
Edge c = encodeConstraintSATEncoder(constraint);
addConstraintCNF(cnf, c);
csolver->addEncodedConstraint(constraint);
type *array; \
}; \
typedef struct Vector ## name Vector ## name; \
- Vector ## name *allocVector ## name(uint capacity); \
- Vector ## name *allocDefVector ## name(); \
- Vector ## name *allocVectorArray ## name(uint capacity, type * array); \
+ Vector ## name * allocVector ## name(uint capacity); \
+ Vector ## name * allocDefVector ## name(); \
+ Vector ## name * allocVectorArray ## name(uint capacity, type * array); \
void pushVector ## name(Vector ## name * vector, type item); \
type lastVector ## name(Vector ## name * vector); \
void popVector ## name(Vector ## name * vector); \
void initVectorArray ## name(Vector ## name * vector, uint capacity, type * array);
#define VectorImpl(name, type, defcap) \
- Vector ## name *allocDefVector ## name() { \
+ Vector ## name * allocDefVector ## name() { \
return allocVector ## name(defcap); \
} \
- Vector ## name *allocVector ## name(uint capacity) { \
- Vector ## name *tmp = (Vector ## name *)ourmalloc(sizeof(Vector ## name)); \
+ Vector ## name * allocVector ## name(uint capacity) { \
+ Vector ## name * tmp = (Vector ## name *)ourmalloc(sizeof(Vector ## name)); \
tmp->size = 0; \
tmp->capacity = capacity; \
tmp->array = (type *) ourmalloc(sizeof(type) * capacity); \
return tmp; \
} \
- Vector ## name *allocVectorArray ## name(uint capacity, type * array) { \
- Vector ## name *tmp = allocVector ## name(capacity); \
+ Vector ## name * allocVectorArray ## name(uint capacity, type * array) { \
+ Vector ## name * tmp = allocVector ## name(capacity); \
tmp->size = capacity; \
memcpy(tmp->array, array, capacity * sizeof(type)); \
return tmp; \
solver->addConstraint(b);
solver->freezeElement(e1);
solver->freezeElement(e2);
- if (solver->solve() == 1){
+ if (solver->solve() == 1) {
int run = 1;
- do{
+ do {
printf("result %d: e1=%" PRIu64 " e2=%" PRIu64 "\n", run, solver->getElementValue(e1), solver->getElementValue(e2));
- for(int i=0; i< INPUTSIZE; i++){
+ for (int i = 0; i < INPUTSIZE; i++) {
uint64_t val = solver->getElementValue(inputs[i]);
Element *econst = solver->getElementConst(0, val);
- Element * tmpInputs[] = {inputs[i], econst};
+ Element *tmpInputs[] = {inputs[i], econst};
BooleanEdge b = solver->applyPredicate(equals, tmpInputs, INPUTSIZE);
solver->addConstraint(solver->applyLogicalOperation(SATC_NOT, b));
}
run++;
- }while(solver->solveIncremental() == 1);
+ } while (solver->solveIncremental() == 1);
printf("After %d runs, there are no more models to find ...\n", run);
- }else{
+ } else {
printf("UNSAT\n");
}
delete solver;
updateTimeout(problem, metric);
snprintf(buffer, sizeof(buffer), "tuner%uused", execnum);
tuner->getTuner()->addUsed(buffer);
- } else if (status == 124 << 8){ // timeout happens ...
+ } else if (status == 124 << 8) {// timeout happens ...
tuner->getTuner()->copySettingstoUsedSettings();
}
-
+
//Increment execution count
execnum++;
void *applyLogicalOperation(void *solver,unsigned int op, void **array, unsigned int asize) {
BooleanEdge constr [asize];
- for(uint i=0; i< asize; i++){
- constr[i] = BooleanEdge((Boolean*)array[i]);
+ for (uint i = 0; i < asize; i++) {
+ constr[i] = BooleanEdge((Boolean *)array[i]);
}
return CCSOLVER(solver)->applyLogicalOperation((LogicOp) op, constr, (uint) asize).getRaw();
}
void *applyExactlyOneConstraint(void *solver, void **array, unsigned int asize) {
BooleanEdge constr [asize];
- for(uint i=0; i< asize; i++){
- constr[i] = BooleanEdge((Boolean*)array[i]);
+ for (uint i = 0; i < asize; i++) {
+ constr[i] = BooleanEdge((Boolean *)array[i]);
}
return CCSOLVER(solver)->applyExactlyOneConstraint( constr, (uint) asize).getRaw();
}
}
void CSolver::freezeElementsVariables() {
-
- for(uint i=0; i< allElements.getSize(); i++){
+
+ for (uint i = 0; i < allElements.getSize(); i++) {
Element *e = allElements.get(i);
- if(e->frozen){
+ if (e->frozen) {
satEncoder->freezeElementVariables(&e->encoding);
}
}
return applyLogicalOperation(op, newarray, asize);
}
-BooleanEdge CSolver::applyExactlyOneConstraint (BooleanEdge *array, uint asize){
+BooleanEdge CSolver::applyExactlyOneConstraint (BooleanEdge *array, uint asize) {
BooleanEdge newarray[asize + 1];
newarray[asize] = applyLogicalOperation(SATC_OR, array, asize);
- for (uint i=0; i< asize; i++){
+ for (uint i = 0; i < asize; i++) {
BooleanEdge oprand1 = array[i];
- BooleanEdge carray [asize -1];
+ BooleanEdge carray [asize - 1];
uint index = 0;
- for( uint j =0; j< asize; j++){
- if(i != j){
+ for ( uint j = 0; j < asize; j++) {
+ if (i != j) {
BooleanEdge oprand2 = applyLogicalOperation(SATC_NOT, array[j]);
carray[index++] = applyLogicalOperation(SATC_IMPLIES, oprand1, oprand2);
}
}
- ASSERT(index == asize -1);
- newarray[i] = applyLogicalOperation(SATC_AND, carray, asize-1);
+ ASSERT(index == asize - 1);
+ newarray[i] = applyLogicalOperation(SATC_AND, carray, asize - 1);
}
- return applyLogicalOperation(SATC_AND, newarray, asize+1);
+ return applyLogicalOperation(SATC_AND, newarray, asize + 1);
}
BooleanEdge CSolver::applyLogicalOperation(LogicOp op, BooleanEdge *array, uint asize) {
if (isUnSAT()) {
return IS_UNSAT;
}
-
-
+
+
long long startTime = getTimeNano();
bool deleteTuner = false;
if (tuner == NULL) {
}
int result = IS_INDETER;
ASSERT (!useInterpreter());
-
+
computePolarities(this);
// long long time1 = getTimeNano();
// model_print("Polarity time: %f\n", (time1 - startTime) / NANOSEC);
//Doing element optimization on new constraints
// ElementOpt eop(this);
// eop.doTransform();
-
+
//Since no new element is added, we assuming adding new constraint
//has no impact on previous encoding decisions
// EncodingGraph eg(this);
time2 = getTimeNano();
elapsedTime = time2 - startTime;
model_print("CSOLVER solve time: %f\n", elapsedTime / NANOSEC);
-
+
if (deleteTuner) {
delete tuner;
tuner = NULL;
model_print("Elapse Encode time: %f\n", (time1 - startTime) / NANOSEC);
model_print("Is problem UNSAT after encoding: %d\n", unsat);
-
+
result = unsat ? IS_UNSAT : satEncoder->solve(satsolverTimeout);
model_print("Result Computed in SAT solver:\t%s\n", result == IS_SAT ? "SAT" : result == IS_INDETER ? "INDETERMINATE" : " UNSAT");
exit(-1);
}
-void CSolver::freezeElement(Element *e){
+void CSolver::freezeElement(Element *e) {
e->freezeElement();
- if(!incrementalMode){
+ if (!incrementalMode) {
incrementalMode = true;
}
}
Set *getElementRange (Element *element);
void mustHaveValue(Element *element);
-
+
BooleanEdge getBooleanTrue();
BooleanEdge getBooleanFalse();
/** This exactly one element of array can be true! (i.e. a1 + a2 + a3 + ... + an = 1)*/
BooleanEdge applyExactlyOneConstraint (BooleanEdge *array, uint asize);
-
+
/** This function applies a logical operation to the Booleans in its input. */
-
+
BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
/** This function applies a logical operation to the Booleans in its input. */
* Incremental Solving for SATUNE.
* It only supports incremental solving for elements!
* No support for BooleanVar, BooleanOrder or using interpreters
- * @return
+ * @return
*/
int solveIncremental();
-
+
/** After getting the solution from the SAT solver, client can get the value of an element via this function*/
uint64_t getElementValue(Element *element);
void freezeElement(Element *e);
-
+
/** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
bool getBooleanValue(BooleanEdge boolean);
SetIteratorBooleanEdge *getConstraints() { return constraints.iterator(); }
bool isConstraintEncoded(BooleanEdge be) { return encodedConstraints.contains(be);}
void addEncodedConstraint(BooleanEdge be) {encodedConstraints.add(be);}
-
+
SATEncoder *getSATEncoder() {return satEncoder;}
void replaceBooleanWithTrue(BooleanEdge bexpr);
void handleIFFTrue(BooleanLogic *bexpr, BooleanEdge child);
void handleANDTrue(BooleanLogic *bexpr, BooleanEdge child);
void handleFunction(ElementFunction *ef, BooleanEdge child);
-
+
//These two functions are helpers if the client has a pointer to a
//Boolean object that we have since replaced
BooleanEdge rewriteLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
/* DO NOT EDIT THIS FILE - it is machine generated */
#include "satune_SatuneJavaAPI.h"
#include "ccsolver.h"
-#define CCSOLVER(solver) (void*)solver
+#define CCSOLVER(solver) (void *)solver
/* Header for class SatuneJavaAPI */
/*
(JNIEnv *env, jobject obj)
{
return (jlong)createCCSolver();
-
+
}
/*
* Signature: (JI)J
*/
JNIEXPORT jlong JNICALL Java_satune_SatuneJavaAPI_getBooleanTrue
- (JNIEnv * env, jobject obj, jlong solver)
+ (JNIEnv *env, jobject obj, jlong solver)
{
return (jlong)getBooleanTrue((void *)solver);
}
* Signature: (JI)J
*/
JNIEXPORT jlong JNICALL Java_satune_SatuneJavaAPI_getBooleanFalse
- (JNIEnv * env, jobject obj, jlong solver)
+ (JNIEnv *env, jobject obj, jlong solver)
{
return (jlong)getBooleanFalse((void *)solver);
}
* Signature: (JIJI)J
*/
JNIEXPORT jlong JNICALL Java_satune_SatuneJavaAPI_createSet
- (JNIEnv *, jobject , jlong , jint , jlongArray arr);
+ (JNIEnv *, jobject, jlong, jint, jlongArray arr);
/*
* Class: satune_SatuneJavaAPI