#include "element.h"
#include "order.h"
-Boolean* allocBooleanVar(VarType t) {
- BooleanVar* This=(BooleanVar *) ourmalloc(sizeof (BooleanVar));
- GETBOOLEANTYPE(This)=BOOLEANVAR;
+Boolean *allocBooleanVar(VarType t) {
+ BooleanVar *This = (BooleanVar *) ourmalloc(sizeof (BooleanVar));
+ GETBOOLEANTYPE(This) = BOOLEANVAR;
GETBOOLEANVALUE(This) = BV_UNDEFINED;
GETBOOLEANPOLARITY(This) = P_UNDEFINED;
- This->vtype=t;
- This->var=E_NULL;
+ This->vtype = t;
+ This->var = E_NULL;
initDefVectorBoolean(GETBOOLEANPARENTS(This));
- return & This->base;
+ return &This->base;
}
-Boolean* allocBooleanOrder(Order* order, uint64_t first, uint64_t second) {
- BooleanOrder* This=(BooleanOrder *) ourmalloc(sizeof (BooleanOrder));
- GETBOOLEANTYPE(This)=ORDERCONST;
+Boolean *allocBooleanOrder(Order *order, uint64_t first, uint64_t second) {
+ BooleanOrder *This = (BooleanOrder *) ourmalloc(sizeof (BooleanOrder));
+ GETBOOLEANTYPE(This) = ORDERCONST;
GETBOOLEANVALUE(This) = BV_UNDEFINED;
GETBOOLEANPOLARITY(This) = P_UNDEFINED;
- This->order=order;
- This->first=first;
- This->second=second;
+ This->order = order;
+ This->first = first;
+ This->second = second;
pushVectorBooleanOrder(&order->constraints, This);
initDefVectorBoolean(GETBOOLEANPARENTS(This));
- return & This -> base;
+ return &This->base;
}
-Boolean * allocBooleanPredicate(Predicate * predicate, Element ** inputs, uint numInputs, Boolean* undefinedStatus){
- BooleanPredicate* This = (BooleanPredicate*) ourmalloc(sizeof(BooleanPredicate));
- GETBOOLEANTYPE(This)= PREDICATEOP;
+Boolean *allocBooleanPredicate(Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus) {
+ BooleanPredicate *This = (BooleanPredicate *) ourmalloc(sizeof(BooleanPredicate));
+ GETBOOLEANTYPE(This) = PREDICATEOP;
GETBOOLEANVALUE(This) = BV_UNDEFINED;
GETBOOLEANPOLARITY(This) = P_UNDEFINED;
- This->predicate=predicate;
+ This->predicate = predicate;
initArrayInitElement(&This->inputs, inputs, numInputs);
initDefVectorBoolean(GETBOOLEANPARENTS(This));
- for(uint i=0;i<numInputs;i++) {
+ for (uint i = 0; i < numInputs; i++) {
pushVectorASTNode(GETELEMENTPARENTS(inputs[i]), (ASTNode *)This);
}
initPredicateEncoding(&This->encoding, (Boolean *) This);
This->undefStatus = undefinedStatus;
- return & This->base;
+ return &This->base;
}
-Boolean * allocBooleanLogicArray(CSolver *solver, LogicOp op, Boolean ** array, uint asize){
- BooleanLogic * This = ourmalloc(sizeof(BooleanLogic));
+Boolean *allocBooleanLogicArray(CSolver *solver, LogicOp op, Boolean **array, uint asize) {
+ BooleanLogic *This = ourmalloc(sizeof(BooleanLogic));
GETBOOLEANTYPE(This) = LOGICOP;
GETBOOLEANVALUE(This) = BV_UNDEFINED;
GETBOOLEANPOLARITY(This) = P_UNDEFINED;
initDefVectorBoolean(GETBOOLEANPARENTS(This));
initArrayInitBoolean(&This->inputs, array, asize);
pushVectorBoolean(solver->allBooleans, (Boolean *) This);
- return & This->base;
+ return &This->base;
}
-void deleteBoolean(Boolean * This) {
- switch(GETBOOLEANTYPE(This)){
- case PREDICATEOP:{
- BooleanPredicate *bp=(BooleanPredicate *)This;
- deleteInlineArrayElement(& bp->inputs );
- deleteFunctionEncoding(& bp->encoding);
- break;
- }
- case LOGICOP:{
- BooleanLogic* bl = (BooleanLogic*) This;
- deleteInlineArrayBoolean(&bl->inputs);
- break;
- }
- default:
- break;
+void deleteBoolean(Boolean *This) {
+ switch (GETBOOLEANTYPE(This)) {
+ case PREDICATEOP: {
+ BooleanPredicate *bp = (BooleanPredicate *)This;
+ deleteInlineArrayElement(&bp->inputs );
+ deleteFunctionEncoding(&bp->encoding);
+ break;
+ }
+ case LOGICOP: {
+ BooleanLogic *bl = (BooleanLogic *) This;
+ deleteInlineArrayBoolean(&bl->inputs);
+ break;
+ }
+ default:
+ break;
}
deleteVectorArrayBoolean(GETBOOLEANPARENTS(This));
ourfree(This);
#define GETBOOLEANTYPE(o) GETASTNODETYPE(o)
#define GETBOOLEANPARENTS(o) (&((Boolean *)(o))->parents)
-#define GETBOOLEANPOLARITY(b) (((Boolean*)b)->polarity)
-#define GETBOOLEANVALUE(b) (((Boolean*)b)->boolVal)
+#define GETBOOLEANPOLARITY(b) (((Boolean *)b)->polarity)
+#define GETBOOLEANVALUE(b) (((Boolean *)b)->boolVal)
struct Boolean {
ASTNode base;
struct BooleanOrder {
Boolean base;
- Order* order;
+ Order *order;
uint64_t first;
uint64_t second;
};
struct BooleanPredicate {
Boolean base;
- Predicate * predicate;
+ Predicate *predicate;
FunctionEncoding encoding;
ArrayElement inputs;
- Boolean* undefStatus;
+ Boolean *undefStatus;
};
-Boolean * allocBooleanVar(VarType t);
-Boolean * allocBooleanOrder(Order * order, uint64_t first, uint64_t second);
-Boolean * allocBooleanPredicate(Predicate * predicate, Element ** inputs, uint numInputs, Boolean* undefinedStatus);
-Boolean * allocBooleanLogicArray(CSolver *solver, LogicOp op, Boolean ** array, uint asize);
-void deleteBoolean(Boolean * This);
-static inline FunctionEncoding* getPredicateFunctionEncoding(BooleanPredicate* func){
+Boolean *allocBooleanVar(VarType t);
+Boolean *allocBooleanOrder(Order *order, uint64_t first, uint64_t second);
+Boolean *allocBooleanPredicate(Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus);
+Boolean *allocBooleanLogicArray(CSolver *solver, LogicOp op, Boolean **array, uint asize);
+void deleteBoolean(Boolean *This);
+static inline FunctionEncoding *getPredicateFunctionEncoding(BooleanPredicate *func) {
return &func->encoding;
}
#include "function.h"
#include "table.h"
-Element *allocElementSet(Set * s) {
- ElementSet * This=(ElementSet *)ourmalloc(sizeof(ElementSet));
- GETELEMENTTYPE(This)= ELEMSET;
- This->set=s;
+Element *allocElementSet(Set *s) {
+ ElementSet *This = (ElementSet *)ourmalloc(sizeof(ElementSet));
+ GETELEMENTTYPE(This) = ELEMSET;
+ This->set = s;
initDefVectorASTNode(GETELEMENTPARENTS(This));
initElementEncoding(&This->encoding, (Element *) This);
return &This->base;
}
-Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus){
- ElementFunction* This = (ElementFunction*) ourmalloc(sizeof(ElementFunction));
- GETELEMENTTYPE(This)= ELEMFUNCRETURN;
- This->function=function;
+Element *allocElementFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus) {
+ ElementFunction *This = (ElementFunction *) ourmalloc(sizeof(ElementFunction));
+ GETELEMENTTYPE(This) = ELEMFUNCRETURN;
+ This->function = function;
ASSERT(GETBOOLEANTYPE(overflowstatus) == BOOLEANVAR);
This->overflowstatus = overflowstatus;
initArrayInitElement(&This->inputs, array, numArrays);
initDefVectorASTNode(GETELEMENTPARENTS(This));
- for(uint i=0;i<numArrays;i++)
+ for (uint i = 0; i < numArrays; i++)
pushVectorASTNode(GETELEMENTPARENTS(array[i]), (ASTNode *) This);
initElementEncoding(&This->rangeencoding, (Element *) This);
initFunctionEncoding(&This->functionencoding, (Element *) This);
return &This->base;
}
-Element * allocElementConst(uint64_t value, VarType type) {
- ElementConst * This=(ElementConst *)ourmalloc(sizeof(ElementConst));
- GETELEMENTTYPE(This)= ELEMCONST;
- This->value=value;
- This->set=allocSet(type, (uint64_t[]){value}, 1);
+Element *allocElementConst(uint64_t value, VarType type) {
+ ElementConst *This = (ElementConst *)ourmalloc(sizeof(ElementConst));
+ GETELEMENTTYPE(This) = ELEMCONST;
+ This->value = value;
+ This->set = allocSet(type, (uint64_t[]) {value}, 1);
initDefVectorASTNode(GETELEMENTPARENTS(This));
initElementEncoding(&This->encoding, (Element *) This);
return &This->base;
}
-Set* getElementSet(Element* This){
- switch(GETELEMENTTYPE(This)){
+Set *getElementSet(Element *This) {
+ switch (GETELEMENTTYPE(This)) {
case ELEMSET:
- return ((ElementSet*)This)->set;
+ return ((ElementSet *)This)->set;
case ELEMCONST:
- return ((ElementConst*)This)->set;
+ return ((ElementConst *)This)->set;
case ELEMFUNCRETURN: {
- Function* func = ((ElementFunction*)This)->function;
- switch(GETFUNCTIONTYPE(func)){
+ Function *func = ((ElementFunction *)This)->function;
+ switch (GETFUNCTIONTYPE(func)) {
case TABLEFUNC:
- return ((FunctionTable*)func)->table->range;
+ return ((FunctionTable *)func)->table->range;
case OPERATORFUNC:
- return ((FunctionOperator*)func)->range;
+ return ((FunctionOperator *)func)->range;
default:
ASSERT(0);
}
}
void deleteElement(Element *This) {
- switch(GETELEMENTTYPE(This)) {
+ switch (GETELEMENTTYPE(This)) {
case ELEMFUNCRETURN: {
ElementFunction *ef = (ElementFunction *) This;
deleteInlineArrayElement(&ef->inputs);
#include "boolean.h"
#define GETELEMENTTYPE(o) GETASTNODETYPE(o)
-#define GETELEMENTPARENTS(o) (&((Element*)o)->parents)
+#define GETELEMENTPARENTS(o) (&((Element *)o)->parents)
struct Element {
ASTNode base;
VectorASTNode parents;
struct ElementConst {
Element base;
- Set * set;
+ Set *set;
uint64_t value;
ElementEncoding encoding;
};
struct ElementSet {
Element base;
- Set * set;
+ Set *set;
ElementEncoding encoding;
};
struct ElementFunction {
Element base;
- Function * function;
+ Function *function;
ArrayElement inputs;
- Boolean * overflowstatus;
+ Boolean *overflowstatus;
FunctionEncoding functionencoding;
ElementEncoding rangeencoding;
};
-Element * allocElementConst(uint64_t value, VarType type);
-Element * allocElementSet(Set *s);
-Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus);
+Element *allocElementConst(uint64_t value, VarType type);
+Element *allocElementSet(Set *s);
+Element *allocElementFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus);
void deleteElement(Element *This);
-Set* getElementSet(Element* This);
+Set *getElementSet(Element *This);
-static inline ElementEncoding* getElementEncoding(Element* This){
- switch(GETELEMENTTYPE(This)){
- case ELEMSET:
- return &((ElementSet*)This)->encoding;
- case ELEMFUNCRETURN:
- return &((ElementFunction*)This)->rangeencoding;
- case ELEMCONST:
- return &((ElementConst*)This)->encoding;
- default:
- ASSERT(0);
+static inline ElementEncoding *getElementEncoding(Element *This) {
+ switch (GETELEMENTTYPE(This)) {
+ case ELEMSET:
+ return &((ElementSet *)This)->encoding;
+ case ELEMFUNCRETURN:
+ return &((ElementFunction *)This)->rangeencoding;
+ case ELEMCONST:
+ return &((ElementConst *)This)->encoding;
+ default:
+ ASSERT(0);
}
return NULL;
}
-static inline FunctionEncoding* getElementFunctionEncoding(ElementFunction* func){
+static inline FunctionEncoding *getElementFunctionEncoding(ElementFunction *func) {
return &func->functionencoding;
}
#endif
#include "set.h"
-Function* allocFunctionOperator(ArithOp op, Set ** domain, uint numDomain, Set * range, OverFlowBehavior overflowbehavior) {
- FunctionOperator* This = (FunctionOperator*) ourmalloc(sizeof(FunctionOperator));
- GETFUNCTIONTYPE(This)=OPERATORFUNC;
+Function *allocFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range, OverFlowBehavior overflowbehavior) {
+ FunctionOperator *This = (FunctionOperator *) ourmalloc(sizeof(FunctionOperator));
+ GETFUNCTIONTYPE(This) = OPERATORFUNC;
initArrayInitSet(&This->domains, domain, numDomain);
- This->op=op;
+ This->op = op;
This->overflowbehavior = overflowbehavior;
- This->range=range;
+ This->range = range;
return &This->base;
}
-Function* allocFunctionTable (Table* table, UndefinedBehavior undefBehavior){
- FunctionTable* This = (FunctionTable*) ourmalloc(sizeof(FunctionTable));
- GETFUNCTIONTYPE(This)=TABLEFUNC;
+Function *allocFunctionTable (Table *table, UndefinedBehavior undefBehavior) {
+ FunctionTable *This = (FunctionTable *) ourmalloc(sizeof(FunctionTable));
+ GETFUNCTIONTYPE(This) = TABLEFUNC;
This->table = table;
This->undefBehavior = undefBehavior;
return &This->base;
}
-uint64_t applyFunctionOperator(FunctionOperator* This, uint numVals, uint64_t * values) {
+uint64_t applyFunctionOperator(FunctionOperator *This, uint numVals, uint64_t *values) {
ASSERT(numVals == 2);
- switch(This->op){
- case ADD:
- return values[0] + values[1];
- break;
- case SUB:
- return values[0] - values[1];
- break;
- default:
- ASSERT(0);
+ switch (This->op) {
+ case ADD:
+ return values[0] + values[1];
+ break;
+ case SUB:
+ return values[0] - values[1];
+ break;
+ default:
+ ASSERT(0);
}
}
return existsInSet(This->range, val);
}
-void deleteFunction(Function* This){
- switch(GETFUNCTIONTYPE(This)){
+void deleteFunction(Function *This) {
+ switch (GETFUNCTIONTYPE(This)) {
case TABLEFUNC:
break;
case OPERATORFUNC:
- deleteInlineArraySet(&((FunctionOperator*) This)->domains);
+ deleteInlineArraySet(&((FunctionOperator *) This)->domains);
break;
default:
ASSERT(0);
#include "ops.h"
#include "structs.h"
-#define GETFUNCTIONTYPE(o) (((Function*)o)->type)
+#define GETFUNCTIONTYPE(o) (((Function *)o)->type)
struct Function {
FunctionType type;
Function base;
ArithOp op;
ArraySet domains;
- Set * range;
+ Set *range;
OverFlowBehavior overflowbehavior;
};
struct FunctionTable {
Function base;
- Table* table;
+ Table *table;
UndefinedBehavior undefBehavior;
};
-Function* allocFunctionOperator(ArithOp op, Set ** domain, uint numDomain, Set * range, OverFlowBehavior overflowbehavior);
-Function* allocFunctionTable (Table* table, UndefinedBehavior behavior);
-uint64_t applyFunctionOperator(FunctionOperator* This, uint numVals, uint64_t * values);
+Function *allocFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range, OverFlowBehavior overflowbehavior);
+Function *allocFunctionTable (Table *table, UndefinedBehavior behavior);
+uint64_t applyFunctionOperator(FunctionOperator *This, uint numVals, uint64_t *values);
bool isInRangeFunction(FunctionOperator *This, uint64_t val);
-void deleteFunction(Function* This);
+void deleteFunction(Function *This);
#endif
#include "mutableset.h"
-MutableSet * allocMutableSet(VarType t) {
- MutableSet * This=(MutableSet *)ourmalloc(sizeof(MutableSet));
- This->type=t;
- This->isRange=false;
- This->low=0;
- This->high=0;
- This->members=allocDefVectorInt();
+MutableSet *allocMutableSet(VarType t) {
+ MutableSet *This = (MutableSet *)ourmalloc(sizeof(MutableSet));
+ This->type = t;
+ This->isRange = false;
+ This->low = 0;
+ This->high = 0;
+ This->members = allocDefVectorInt();
return This;
}
-void addElementMSet(MutableSet * set, uint64_t element) {
+void addElementMSet(MutableSet *set, uint64_t element) {
pushVectorInt(set->members, element);
}
#define MUTABLESET_H
#include "set.h"
-MutableSet * allocMutableSet(VarType t);
-void addElementMSet(MutableSet * set, uint64_t element);
+MutableSet *allocMutableSet(VarType t);
+void addElementMSet(MutableSet *set, uint64_t element);
#endif
#include "set.h"
#include "boolean.h"
-Order* allocOrder(OrderType type, Set * set){
- Order* This = (Order*)ourmalloc(sizeof(Order));
- This->set=set;
- initDefVectorBooleanOrder(& This->constraints);
- This->type=type;
- initOrderEncoding(& This->order, This);
+Order *allocOrder(OrderType type, Set *set) {
+ Order *This = (Order *)ourmalloc(sizeof(Order));
+ This->set = set;
+ initDefVectorBooleanOrder(&This->constraints);
+ This->type = type;
+ initOrderEncoding(&This->order, This);
This->orderPairTable = NULL;
return This;
}
-void initializeOrderHashTable(Order* This){
- This->orderPairTable=allocHashTableOrderPair(HT_INITIAL_CAPACITY, HT_DEFAULT_FACTOR);
+void initializeOrderHashTable(Order *This) {
+ This->orderPairTable = allocHashTableOrderPair(HT_INITIAL_CAPACITY, HT_DEFAULT_FACTOR);
}
-void addOrderConstraint(Order* This, BooleanOrder* constraint){
+void addOrderConstraint(Order *This, BooleanOrder *constraint) {
pushVectorBooleanOrder( &This->constraints, constraint);
}
-void setOrderEncodingType(Order* This, OrderEncodingType type){
+void setOrderEncodingType(Order *This, OrderEncodingType type) {
This->order.type = type;
}
-void deleteOrder(Order* This){
- deleteVectorArrayBooleanOrder(& This->constraints);
- deleteOrderEncoding(& This->order);
- if(This->orderPairTable != NULL) {
+void deleteOrder(Order *This) {
+ deleteVectorArrayBooleanOrder(&This->constraints);
+ deleteOrderEncoding(&This->order);
+ if (This->orderPairTable != NULL) {
resetAndDeleteHashTableOrderPair(This->orderPairTable);
deleteHashTableOrderPair(This->orderPairTable);
}
struct Order {
OrderType type;
- Set * set;
- HashTableOrderPair * orderPairTable;
+ Set *set;
+ HashTableOrderPair *orderPairTable;
VectorBooleanOrder constraints;
OrderEncoding order;
};
-Order* allocOrder(OrderType type, Set * set);
-void initializeOrderHashTable(Order * This);
-void addOrderConstraint(Order * This, BooleanOrder * constraint);
-void setOrderEncodingType(Order * This, OrderEncodingType type);
-void deleteOrder(Order * This);
+Order *allocOrder(OrderType type, Set *set);
+void initializeOrderHashTable(Order *This);
+void addOrderConstraint(Order *This, BooleanOrder *constraint);
+void setOrderEncodingType(Order *This, OrderEncodingType type);
+void deleteOrder(Order *This);
#endif
#include "set.h"
#include "table.h"
-Predicate* allocPredicateOperator(CompOp op, Set ** domain, uint numDomain){
- PredicateOperator* This = ourmalloc(sizeof(PredicateOperator));
- GETPREDICATETYPE(This)=OPERATORPRED;
+Predicate *allocPredicateOperator(CompOp op, Set **domain, uint numDomain) {
+ PredicateOperator *This = ourmalloc(sizeof(PredicateOperator));
+ GETPREDICATETYPE(This) = OPERATORPRED;
initArrayInitSet(&This->domains, domain, numDomain);
- This->op=op;
+ This->op = op;
return &This->base;
}
-Predicate* allocPredicateTable(Table* table, UndefinedBehavior undefBehavior){
+Predicate *allocPredicateTable(Table *table, UndefinedBehavior undefBehavior) {
ASSERT(table->range == NULL);
- PredicateTable* This = ourmalloc(sizeof(PredicateTable));
+ PredicateTable *This = ourmalloc(sizeof(PredicateTable));
GETPREDICATETYPE(This) = TABLEPRED;
- This->table=table;
- This->undefinedbehavior=undefBehavior;
+ This->table = table;
+ This->undefinedbehavior = undefBehavior;
return &This->base;
}
-void deletePredicate(Predicate* This){
- switch(GETPREDICATETYPE(This)) {
+void deletePredicate(Predicate *This) {
+ switch (GETPREDICATETYPE(This)) {
case OPERATORPRED: {
- PredicateOperator * operpred=(PredicateOperator *) This;
+ PredicateOperator *operpred = (PredicateOperator *) This;
deleteInlineArraySet(&operpred->domains);
break;
}
ourfree(This);
}
-bool evalPredicateOperator(PredicateOperator * This, uint64_t * inputs) {
- switch(This->op) {
+bool evalPredicateOperator(PredicateOperator *This, uint64_t *inputs) {
+ switch (This->op) {
case EQUALS:
- return inputs[0]==inputs[1];
+ return inputs[0] == inputs[1];
case LT:
- return inputs[0]<inputs[1];
+ return inputs[0] < inputs[1];
case GT:
- return inputs[0]>inputs[1];
+ return inputs[0] > inputs[1];
case LTE:
- return inputs[0]<=inputs[1];
+ return inputs[0] <= inputs[1];
case GTE:
- return inputs[0]>=inputs[1];
+ return inputs[0] >= inputs[1];
}
ASSERT(0);
return false;
struct PredicateTable {
Predicate base;
- Table* table;
+ Table *table;
UndefinedBehavior undefinedbehavior;
};
-Predicate* allocPredicateOperator(CompOp op, Set ** domain, uint numDomain);
-Predicate* allocPredicateTable(Table* table, UndefinedBehavior undefBehavior);
-bool evalPredicateOperator(PredicateOperator * This, uint64_t * inputs);
-void deletePredicate(Predicate* This);
+Predicate *allocPredicateOperator(CompOp op, Set **domain, uint numDomain);
+Predicate *allocPredicateTable(Table *table, UndefinedBehavior undefBehavior);
+bool evalPredicateOperator(PredicateOperator *This, uint64_t *inputs);
+void deletePredicate(Predicate *This);
#endif
#include "rewriter.h"
#include "boolean.h"
-void replaceBooleanWithTrue(Boolean * This) {
- uint size=getSizeVectorBoolean(&This->parents);
- for(uint i=0;i<size;i++) {
- Boolean * parent=getVectorBoolean(&This->parents, i);
- BooleanLogic * logicop=(BooleanLogic*) parent;
- switch(logicop->op) {
+void replaceBooleanWithTrue(Boolean *This) {
+ uint size = getSizeVectorBoolean(&This->parents);
+ for (uint i = 0; i < size; i++) {
+ Boolean *parent = getVectorBoolean(&This->parents, i);
+ BooleanLogic *logicop = (BooleanLogic *) parent;
+ switch (logicop->op) {
case L_AND:
handleANDTrue(logicop, This);
break;
}
void replaceBooleanWithBoolean(Boolean *oldb, Boolean *newb) {
- uint size=getSizeVectorBoolean(&oldb->parents);
- for(uint i=0;i<size;i++) {
- Boolean * parent=getVectorBoolean(&oldb->parents, i);
- BooleanLogic * logicop=(BooleanLogic*) parent;
-
- uint parentsize=getSizeArrayBoolean(&logicop->inputs);
-
- for(uint j=0;j<parentsize;j++) {
- Boolean *b=getArrayBoolean(&logicop->inputs, i);
- if (b==oldb) {
+ uint size = getSizeVectorBoolean(&oldb->parents);
+ for (uint i = 0; i < size; i++) {
+ Boolean *parent = getVectorBoolean(&oldb->parents, i);
+ BooleanLogic *logicop = (BooleanLogic *) parent;
+
+ uint parentsize = getSizeArrayBoolean(&logicop->inputs);
+
+ for (uint j = 0; j < parentsize; j++) {
+ Boolean *b = getArrayBoolean(&logicop->inputs, i);
+ if (b == oldb) {
setArrayBoolean(&logicop->inputs, i, newb);
pushVectorBoolean(&newb->parents, parent);
}
}
void handleXORTrue(BooleanLogic *This, Boolean *child) {
- uint size=getSizeArrayBoolean(&This->inputs);
- Boolean *b=getArrayBoolean(&This->inputs, 0);
- uint otherindex=(b==child)?1:0;
+ uint size = getSizeArrayBoolean(&This->inputs);
+ Boolean *b = getArrayBoolean(&This->inputs, 0);
+ uint otherindex = (b == child) ? 1 : 0;
removeElementArrayBoolean(&This->inputs, otherindex);
- This->op=L_NOT;
+ This->op = L_NOT;
}
void handleXORFalse(BooleanLogic *This, Boolean *child) {
- uint size=getSizeArrayBoolean(&This->inputs);
- Boolean *b=getArrayBoolean(&This->inputs, 0);
- uint otherindex=(b==child)?1:0;
+ uint size = getSizeArrayBoolean(&This->inputs);
+ Boolean *b = getArrayBoolean(&This->inputs, 0);
+ uint otherindex = (b == child) ? 1 : 0;
replaceBooleanWithBoolean((Boolean *)This, getArrayBoolean(&This->inputs, otherindex));
}
void handleIMPLIESTrue(BooleanLogic *This, Boolean *child) {
- uint size=getSizeArrayBoolean(&This->inputs);
- Boolean *b=getArrayBoolean(&This->inputs, 0);
- if (b==child) {
+ uint size = getSizeArrayBoolean(&This->inputs);
+ Boolean *b = getArrayBoolean(&This->inputs, 0);
+ if (b == child) {
//Replace with other term
replaceBooleanWithBoolean((Boolean *)This, getArrayBoolean(&This->inputs, 1));
} else {
}
void handleIMPLIESFalse(BooleanLogic *This, Boolean *child) {
- uint size=getSizeArrayBoolean(&This->inputs);
- Boolean *b=getArrayBoolean(&This->inputs, 0);
- if (b==child) {
+ uint size = getSizeArrayBoolean(&This->inputs);
+ Boolean *b = getArrayBoolean(&This->inputs, 0);
+ if (b == child) {
//Statement is true...
replaceBooleanWithTrue((Boolean *)This);
} else {
//Make into negation of first term
removeElementArrayBoolean(&This->inputs, 1);
- This->op=L_NOT;
+ This->op = L_NOT;
}
}
void handleANDTrue(BooleanLogic *This, Boolean *child) {
- uint size=getSizeArrayBoolean(&This->inputs);
+ uint size = getSizeArrayBoolean(&This->inputs);
- if (size==1) {
+ if (size == 1) {
replaceBooleanWithTrue((Boolean *)This);
return;
}
-
- for(uint i=0;i<size;i++) {
- Boolean *b=getArrayBoolean(&This->inputs, i);
- if (b==child) {
+
+ for (uint i = 0; i < size; i++) {
+ Boolean *b = getArrayBoolean(&This->inputs, i);
+ if (b == child) {
removeElementArrayBoolean(&This->inputs, i);
}
}
-
- if (size==2) {
+
+ if (size == 2) {
replaceBooleanWithBoolean((Boolean *)This, getArrayBoolean(&This->inputs, 0));
}
}
void handleORFalse(BooleanLogic *This, Boolean *child) {
- uint size=getSizeArrayBoolean(&This->inputs);
+ uint size = getSizeArrayBoolean(&This->inputs);
- if (size==1) {
- replaceBooleanWithFalse((Boolean*) This);
+ if (size == 1) {
+ replaceBooleanWithFalse((Boolean *) This);
}
-
- for(uint i=0;i<size;i++) {
- Boolean *b=getArrayBoolean(&This->inputs, i);
- if (b==child) {
+
+ for (uint i = 0; i < size; i++) {
+ Boolean *b = getArrayBoolean(&This->inputs, i);
+ if (b == child) {
removeElementArrayBoolean(&This->inputs, i);
}
}
- if (size==2) {
+ if (size == 2) {
replaceBooleanWithBoolean((Boolean *)This, getArrayBoolean(&This->inputs, 0));
}
}
-void replaceBooleanWithFalse(Boolean * This) {
- uint size=getSizeVectorBoolean(&This->parents);
- for(uint i=0;i<size;i++) {
- Boolean * parent=getVectorBoolean(&This->parents, i);
- BooleanLogic * logicop=(BooleanLogic*) parent;
- switch(logicop->op) {
+void replaceBooleanWithFalse(Boolean *This) {
+ uint size = getSizeVectorBoolean(&This->parents);
+ for (uint i = 0; i < size; i++) {
+ Boolean *parent = getVectorBoolean(&This->parents, i);
+ BooleanLogic *logicop = (BooleanLogic *) parent;
+ switch (logicop->op) {
case L_AND:
replaceBooleanWithFalse(parent);
break;
handleIMPLIESFalse(logicop, This);
break;
}
- }
+ }
}
#define REWRITER_H
#include "classlist.h"
-void replaceBooleanWithTrue(Boolean * This);
-void replaceBooleanWithFalse(Boolean * This);
+void replaceBooleanWithTrue(Boolean *This);
+void replaceBooleanWithFalse(Boolean *This);
void replaceBooleanWithBoolean(Boolean *oldb, Boolean *newb);
void handleXORTrue(BooleanLogic *This, Boolean *child);
void handleXORFalse(BooleanLogic *This, Boolean *child);
#include "set.h"
#include <stddef.h>
-Set * allocSet(VarType t, uint64_t* elements, uint num) {
- Set * This=(Set *)ourmalloc(sizeof(Set));
- This->type=t;
- This->isRange=false;
- This->low=0;
- This->high=0;
- This->members=allocVectorArrayInt(num, elements);
+Set *allocSet(VarType t, uint64_t *elements, uint num) {
+ Set *This = (Set *)ourmalloc(sizeof(Set));
+ This->type = t;
+ This->isRange = false;
+ This->low = 0;
+ This->high = 0;
+ This->members = allocVectorArrayInt(num, elements);
return This;
}
-Set * allocSetRange(VarType t, uint64_t lowrange, uint64_t highrange) {
- Set * This=(Set *)ourmalloc(sizeof(Set));
- This->type=t;
- This->isRange=true;
- This->low=lowrange;
- This->high=highrange;
- This->members=NULL;
+Set *allocSetRange(VarType t, uint64_t lowrange, uint64_t highrange) {
+ Set *This = (Set *)ourmalloc(sizeof(Set));
+ This->type = t;
+ This->isRange = true;
+ This->low = lowrange;
+ This->high = highrange;
+ This->members = NULL;
return This;
}
-bool existsInSet(Set* This, uint64_t element){
- if(This->isRange){
+bool existsInSet(Set *This, uint64_t element) {
+ if (This->isRange) {
return element >= This->low && element <= This->high;
} else {
uint size = getSizeVectorInt(This->members);
- for(uint i=0; i< size; i++){
- if(element == getVectorInt(This->members, i))
+ for (uint i = 0; i < size; i++) {
+ if (element == getVectorInt(This->members, i))
return true;
}
return false;
}
}
-uint64_t getSetElement(Set * This, uint index) {
+uint64_t getSetElement(Set *This, uint index) {
if (This->isRange)
- return This->low+index;
+ return This->low + index;
else
return getVectorInt(This->members, index);
}
-uint getSetSize(Set* This){
- if(This->isRange){
- return This->high - This->low+1;
- }else{
+uint getSetSize(Set *This) {
+ if (This->isRange) {
+ return This->high - This->low + 1;
+ } else {
return getSizeVectorInt(This->members);
}
}
-void deleteSet(Set * This) {
+void deleteSet(Set *This) {
if (!This->isRange)
deleteVectorInt(This->members);
ourfree(This);
bool isRange;
uint64_t low;//also used to count unique items
uint64_t high;
- VectorInt * members;
+ VectorInt *members;
};
-Set * allocSet(VarType t, uint64_t * elements, uint num);
-Set * allocSetRange(VarType t, uint64_t lowrange, uint64_t highrange);
-bool existsInSet(Set * This, uint64_t element);
-uint getSetSize(Set * This);
-uint64_t getSetElement(Set * This, uint index);
-void deleteSet(Set * This);
+Set *allocSet(VarType t, uint64_t *elements, uint num);
+Set *allocSetRange(VarType t, uint64_t lowrange, uint64_t highrange);
+bool existsInSet(Set *This, uint64_t element);
+uint getSetSize(Set *This);
+uint64_t getSetElement(Set *This, uint index);
+void deleteSet(Set *This);
#endif/* SET_H */
#include "set.h"
#include "mutableset.h"
-Table * allocTable(Set **domains, uint numDomain, Set * range){
- Table* This = (Table*) ourmalloc(sizeof(Table));
+Table *allocTable(Set **domains, uint numDomain, Set *range) {
+ Table *This = (Table *) ourmalloc(sizeof(Table));
initArrayInitSet(&This->domains, domains, numDomain);
- This->entries= allocHashSetTableEntry(HT_INITIAL_CAPACITY, HT_DEFAULT_FACTOR);
- This->range =range;
+ This->entries = allocHashSetTableEntry(HT_INITIAL_CAPACITY, HT_DEFAULT_FACTOR);
+ This->range = range;
return This;
}
-void addNewTableEntry(Table* This, uint64_t* inputs, uint inputSize, uint64_t result){
+void addNewTableEntry(Table *This, uint64_t *inputs, uint inputSize, uint64_t result) {
ASSERT(getSizeArraySet( &This->domains) == inputSize);
#ifdef CONFIG_ASSERT
- if(This->range==NULL)
+ if (This->range == NULL)
ASSERT(result == true || result == false);
#endif
- TableEntry* tb = allocTableEntry(inputs, inputSize, result);
+ TableEntry *tb = allocTableEntry(inputs, inputSize, result);
ASSERT(!containsHashSetTableEntry(This->entries, tb));
- bool status= addHashSetTableEntry(This->entries, tb);
+ bool status = addHashSetTableEntry(This->entries, tb);
ASSERT(status);
}
-TableEntry* getTableEntryFromTable(Table* table, uint64_t* inputs, uint inputSize){
- TableEntry* temp = allocTableEntry(inputs, inputSize, -1);
- TableEntry* result= getHashSetTableEntry(table->entries, temp);
+TableEntry *getTableEntryFromTable(Table *table, uint64_t *inputs, uint inputSize) {
+ TableEntry *temp = allocTableEntry(inputs, inputSize, -1);
+ TableEntry *result = getHashSetTableEntry(table->entries, temp);
deleteTableEntry(temp);
return result;
}
-void deleteTable(Table* This){
- deleteInlineArraySet(&This->domains);
- HSIteratorTableEntry* iterator = iteratorTableEntry(This->entries);
- while(hasNextTableEntry(iterator)){
- deleteTableEntry( nextTableEntry(iterator) );
- }
- deleteIterTableEntry(iterator);
- deleteHashSetTableEntry(This->entries);
- ourfree(This);
+void deleteTable(Table *This) {
+ deleteInlineArraySet(&This->domains);
+ HSIteratorTableEntry *iterator = iteratorTableEntry(This->entries);
+ while (hasNextTableEntry(iterator)) {
+ deleteTableEntry( nextTableEntry(iterator) );
+ }
+ deleteIterTableEntry(iterator);
+ deleteHashSetTableEntry(This->entries);
+ ourfree(This);
}
struct Table {
ArraySet domains;
- Set * range;
- HashSetTableEntry* entries;
+ Set *range;
+ HashSetTableEntry *entries;
};
-Table * allocTable(Set ** domains, uint numDomain, Set * range);
-void addNewTableEntry(Table * This, uint64_t * inputs, uint inputSize, uint64_t result);
-TableEntry* getTableEntryFromTable(Table* table, uint64_t* inputs, uint inputSize);
-void deleteTable(Table * This);
+Table *allocTable(Set **domains, uint numDomain, Set *range);
+void addNewTableEntry(Table *This, uint64_t *inputs, uint inputSize, uint64_t result);
+TableEntry *getTableEntryFromTable(Table *table, uint64_t *inputs, uint inputSize);
+void deleteTable(Table *This);
#endif
#include "tableentry.h"
#include <string.h>
-TableEntry* allocTableEntry(uint64_t* inputs, uint inputSize, uint64_t result){
- TableEntry* te = (TableEntry*) ourmalloc(sizeof(TableEntry)+inputSize*sizeof(uint64_t));
- te->output=result;
- te->inputSize=inputSize;
+TableEntry *allocTableEntry(uint64_t *inputs, uint inputSize, uint64_t result) {
+ TableEntry *te = (TableEntry *) ourmalloc(sizeof(TableEntry) + inputSize * sizeof(uint64_t));
+ te->output = result;
+ te->inputSize = inputSize;
memcpy(te->inputs, inputs, inputSize * sizeof(uint64_t));
return te;
}
-void deleteTableEntry(TableEntry* tableEntry){
+void deleteTableEntry(TableEntry *tableEntry) {
ourfree(tableEntry);
}
uint64_t inputs[];
};
-TableEntry* allocTableEntry(uint64_t* inputs, uint inputSize, uint64_t result);
-void deleteTableEntry(TableEntry* tableEntry);
+TableEntry *allocTableEntry(uint64_t *inputs, uint inputSize, uint64_t result);
+void deleteTableEntry(TableEntry *tableEntry);
#endif/* TABLEENTRY_H */
#include "cnfexpr.h"
#include <stdio.h>
-/*
-V2 Copyright (c) 2014 Ben Chambers, Eugene Goldberg, Pete Manolios,
-Vasilis Papavasileiou, Sudarshan Srinivasan, and Daron Vroon.
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software. If
-you download or use the software, send email to Pete Manolios
-(pete@ccs.neu.edu) with your name, contact information, and a short
-note describing what you want to use BAT for. For any reuse or
-distribution, you must make clear to others the license terms of this
-work.
-
-Contact Pete Manolios if you want any of these conditions waived.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-/*
-C port of CNF SAT Conversion Copyright Brian Demsky 2017.
-*/
+/*
+ V2 Copyright (c) 2014 Ben Chambers, Eugene Goldberg, Pete Manolios,
+ Vasilis Papavasileiou, Sudarshan Srinivasan, and Daron Vroon.
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software. If
+ you download or use the software, send email to Pete Manolios
+ (pete@ccs.neu.edu) with your name, contact information, and a short
+ note describing what you want to use BAT for. For any reuse or
+ distribution, you must make clear to others the license terms of this
+ work.
+
+ Contact Pete Manolios if you want any of these conditions waived.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ C port of CNF SAT Conversion Copyright Brian Demsky 2017.
+ */
#define LITCAPACITY 4
#define MERGESIZE 5
VectorImpl(LitVector, LitVector *, 4)
-static inline uint boundedSize(uint x) { return (x > MERGESIZE)?MERGESIZE:x; }
+static inline uint boundedSize(uint x) { return (x > MERGESIZE) ? MERGESIZE : x; }
-LitVector * allocLitVector() {
- LitVector *This=ourmalloc(sizeof(LitVector));
+LitVector *allocLitVector() {
+ LitVector *This = ourmalloc(sizeof(LitVector));
initLitVector(This);
return This;
}
void initLitVector(LitVector *This) {
- This->size=0;
- This->capacity=LITCAPACITY;
- This->literals=ourmalloc(This->capacity * sizeof(Literal));
+ This->size = 0;
+ This->capacity = LITCAPACITY;
+ This->literals = ourmalloc(This->capacity * sizeof(Literal));
}
LitVector *cloneLitVector(LitVector *orig) {
- LitVector *This=ourmalloc(sizeof(LitVector));
- This->size=orig->size;
- This->capacity=orig->capacity;
- This->literals=ourmalloc(This->capacity * sizeof(Literal));
+ LitVector *This = ourmalloc(sizeof(LitVector));
+ This->size = orig->size;
+ This->capacity = orig->capacity;
+ This->literals = ourmalloc(This->capacity * sizeof(Literal));
memcpy(This->literals, orig->literals, sizeof(Literal) * This->size);
return This;
}
void clearLitVector(LitVector *This) {
- This->size=0;
+ This->size = 0;
}
void freeLitVector(LitVector *This) {
}
void setLiteralLitVector(LitVector *This, uint index, Literal l) {
- This->literals[index]=l;
+ This->literals[index] = l;
}
void addLiteralLitVector(LitVector *This, Literal l) {
Literal labs = abs(l);
- uint vec_size=This->size;
- uint searchsize=boundedSize(vec_size);
- uint i=0;
+ uint vec_size = This->size;
+ uint searchsize = boundedSize(vec_size);
+ uint i = 0;
for (; i < searchsize; i++) {
Literal curr = This->literals[i];
Literal currabs = abs(curr);
break;
if (currabs == labs) {
if (curr == -l)
- This->size = 0; //either true or false now depending on whether this is a conj or disj
+ This->size = 0; //either true or false now depending on whether this is a conj or disj
return;
}
}
if ((++This->size) >= This->capacity) {
This->capacity <<= 1;
- This->literals=ourrealloc(This->literals, This->capacity * sizeof(Literal));
+ This->literals = ourrealloc(This->literals, This->capacity * sizeof(Literal));
}
-
+
if (vec_size < MERGESIZE) {
- memmove(&This->literals[i+1], &This->literals[i], (vec_size-i) * sizeof(Literal));
- This->literals[i]=l;
+ memmove(&This->literals[i + 1], &This->literals[i], (vec_size - i) * sizeof(Literal));
+ This->literals[i] = l;
} else {
- This->literals[vec_size]=l;
+ This->literals[vec_size] = l;
}
}
-CNFExpr * allocCNFExprBool(bool isTrue) {
- CNFExpr *This=ourmalloc(sizeof(CNFExpr));
- This->litSize=0;
- This->isTrue=isTrue;
+CNFExpr *allocCNFExprBool(bool isTrue) {
+ CNFExpr *This = ourmalloc(sizeof(CNFExpr));
+ This->litSize = 0;
+ This->isTrue = isTrue;
initVectorLitVector(&This->clauses, 2);
initLitVector(&This->singletons);
return This;
}
-CNFExpr * allocCNFExprLiteral(Literal l) {
- CNFExpr *This=ourmalloc(sizeof(CNFExpr));
- This->litSize=1;
- This->isTrue=false;
+CNFExpr *allocCNFExprLiteral(Literal l) {
+ CNFExpr *This = ourmalloc(sizeof(CNFExpr));
+ This->litSize = 1;
+ This->isTrue = false;
initVectorLitVector(&This->clauses, 2);
initLitVector(&This->singletons);
addLiteralLitVector(&This->singletons, l);
}
void clearCNFExpr(CNFExpr *This, bool isTrue) {
- for(uint i=0;i<getSizeVectorLitVector(&This->clauses);i++) {
+ for (uint i = 0; i < getSizeVectorLitVector(&This->clauses); i++) {
deleteLitVector(getVectorLitVector(&This->clauses, i));
}
clearVectorLitVector(&This->clauses);
clearLitVector(&This->singletons);
- This->litSize=0;
- This->isTrue=isTrue;
+ This->litSize = 0;
+ This->isTrue = isTrue;
}
void deleteCNFExpr(CNFExpr *This) {
- for(uint i=0;i<getSizeVectorLitVector(&This->clauses);i++) {
+ for (uint i = 0; i < getSizeVectorLitVector(&This->clauses); i++) {
deleteLitVector(getVectorLitVector(&This->clauses, i));
}
deleteVectorArrayLitVector(&This->clauses);
}
void conjoinCNFLit(CNFExpr *This, Literal l) {
- if (This->litSize==0 && !This->isTrue) //Handle False
+ if (This->litSize == 0 && !This->isTrue)//Handle False
return;
-
- This->litSize-=getSizeLitVector(&This->singletons);
+
+ This->litSize -= getSizeLitVector(&This->singletons);
addLiteralLitVector(&This->singletons, l);
- uint newsize=getSizeLitVector(&This->singletons);
- if (newsize==0)
- clearCNFExpr(This, false); //We found a conflict
+ uint newsize = getSizeLitVector(&This->singletons);
+ if (newsize == 0)
+ clearCNFExpr(This, false);//We found a conflict
else
- This->litSize+=getSizeLitVector(&This->singletons);
+ This->litSize += getSizeLitVector(&This->singletons);
}
void copyCNF(CNFExpr *This, CNFExpr *expr, bool destroy) {
if (destroy) {
ourfree(This->singletons.literals);
ourfree(This->clauses.array);
- This->litSize=expr->litSize;
- This->singletons.literals=expr->singletons.literals;
- This->singletons.capacity=expr->singletons.capacity;
- This->clauses.size=expr->clauses.size;
- This->clauses.array=expr->clauses.array;
- This->clauses.capacity=expr->clauses.capacity;
+ This->litSize = expr->litSize;
+ This->singletons.literals = expr->singletons.literals;
+ This->singletons.capacity = expr->singletons.capacity;
+ This->clauses.size = expr->clauses.size;
+ This->clauses.array = expr->clauses.array;
+ This->clauses.capacity = expr->clauses.capacity;
ourfree(expr);
} else {
- for(uint i=0;i<getSizeLitVector(&expr->singletons);i++) {
- Literal l=getLiteralLitVector(&expr->singletons,i);
+ for (uint i = 0; i < getSizeLitVector(&expr->singletons); i++) {
+ Literal l = getLiteralLitVector(&expr->singletons,i);
addLiteralLitVector(&This->singletons, l);
}
- for(uint i=0;i<getSizeVectorLitVector(&expr->clauses);i++) {
- LitVector *lv=getVectorLitVector(&expr->clauses,i);
+ for (uint i = 0; i < getSizeVectorLitVector(&expr->clauses); i++) {
+ LitVector *lv = getVectorLitVector(&expr->clauses,i);
pushVectorLitVector(&This->clauses, cloneLitVector(lv));
}
- This->litSize=expr->litSize;
+ This->litSize = expr->litSize;
}
}
void conjoinCNFExpr(CNFExpr *This, CNFExpr *expr, bool destroy) {
- if (expr->litSize==0) {
+ if (expr->litSize == 0) {
if (!This->isTrue) {
clearCNFExpr(This, false);
}
}
return;
}
- if (This->litSize==0) {
+ if (This->litSize == 0) {
if (This->isTrue) {
copyCNF(This, expr, destroy);
} else if (destroy) {
}
return;
}
- uint litSize=This->litSize;
- litSize-=getSizeLitVector(&expr->singletons);
- for(uint i=0;i<getSizeLitVector(&expr->singletons);i++) {
- Literal l=getLiteralLitVector(&expr->singletons,i);
+ uint litSize = This->litSize;
+ litSize -= getSizeLitVector(&expr->singletons);
+ for (uint i = 0; i < getSizeLitVector(&expr->singletons); i++) {
+ Literal l = getLiteralLitVector(&expr->singletons,i);
addLiteralLitVector(&This->singletons, l);
- if (getSizeLitVector(&This->singletons)==0) {
+ if (getSizeLitVector(&This->singletons) == 0) {
//Found conflict...
clearCNFExpr(This, false);
if (destroy) {
return;
}
}
- litSize+=getSizeLitVector(&expr->singletons);
+ litSize += getSizeLitVector(&expr->singletons);
if (destroy) {
- for(uint i=0;i<getSizeVectorLitVector(&expr->clauses);i++) {
- LitVector *lv=getVectorLitVector(&expr->clauses,i);
- litSize+=getSizeLitVector(lv);
+ for (uint i = 0; i < getSizeVectorLitVector(&expr->clauses); i++) {
+ LitVector *lv = getVectorLitVector(&expr->clauses,i);
+ litSize += getSizeLitVector(lv);
pushVectorLitVector(&This->clauses, lv);
}
clearVectorLitVector(&expr->clauses);
deleteCNFExpr(expr);
} else {
- for(uint i=0;i<getSizeVectorLitVector(&expr->clauses);i++) {
- LitVector *lv=getVectorLitVector(&expr->clauses,i);
- litSize+=getSizeLitVector(lv);
+ for (uint i = 0; i < getSizeVectorLitVector(&expr->clauses); i++) {
+ LitVector *lv = getVectorLitVector(&expr->clauses,i);
+ litSize += getSizeLitVector(lv);
pushVectorLitVector(&This->clauses, cloneLitVector(lv));
}
}
- This->litSize=litSize;
+ This->litSize = litSize;
}
void disjoinCNFLit(CNFExpr *This, Literal l) {
- if (This->litSize==0) {
+ if (This->litSize == 0) {
if (!This->isTrue) {
This->litSize++;
addLiteralLitVector(&This->singletons, l);
return;
}
- uint litSize=0;
- uint newindex=0;
- for(uint i=0;i<getSizeVectorLitVector(&This->clauses);i++) {
- LitVector * lv=getVectorLitVector(&This->clauses, i);
+ uint litSize = 0;
+ uint newindex = 0;
+ for (uint i = 0; i < getSizeVectorLitVector(&This->clauses); i++) {
+ LitVector *lv = getVectorLitVector(&This->clauses, i);
addLiteralLitVector(lv, l);
- uint newSize=getSizeLitVector(lv);
- if (newSize!=0) {
+ uint newSize = getSizeLitVector(lv);
+ if (newSize != 0) {
setVectorLitVector(&This->clauses, newindex++, lv);
} else {
deleteLitVector(lv);
}
- litSize+=newSize;
+ litSize += newSize;
}
setSizeVectorLitVector(&This->clauses, newindex);
- bool hasSameSingleton=false;
- for(uint i=0;i<getSizeLitVector(&This->singletons);i++) {
- Literal lsing=getLiteralLitVector(&This->singletons, i);
+ bool hasSameSingleton = false;
+ for (uint i = 0; i < getSizeLitVector(&This->singletons); i++) {
+ Literal lsing = getLiteralLitVector(&This->singletons, i);
if (lsing == l) {
- hasSameSingleton=true;
+ hasSameSingleton = true;
} else if (lsing != -l) {
//Create new LitVector with both l and lsing
- LitVector *newlitvec=allocLitVector();
+ LitVector *newlitvec = allocLitVector();
addLiteralLitVector(newlitvec, l);
addLiteralLitVector(newlitvec, lsing);
- litSize+=2;
+ litSize += 2;
pushVectorLitVector(&This->clauses, newlitvec);
}
}
if (hasSameSingleton) {
addLiteralLitVector(&This->singletons, l);
litSize++;
- } else if (litSize==0) {
- This->isTrue=true;//we are true
+ } else if (litSize == 0) {
+ This->isTrue = true;//we are true
}
- This->litSize=litSize;
+ This->litSize = litSize;
}
#define MERGETHRESHOLD 2
-LitVector * mergeLitVectors(LitVector *This, LitVector *expr) {
- uint maxsize=This->size+expr->size+MERGETHRESHOLD;
- LitVector *merged=ourmalloc(sizeof(LitVector));
- merged->literals=ourmalloc(sizeof(Literal)*maxsize);
- merged->capacity=maxsize;
- uint thisSize=boundedSize(This->size);
- uint exprSize=boundedSize(expr->size);
- uint iThis=0, iExpr=0, iMerge=0;
- Literal lThis=This->literals[iThis];
- Literal lExpr=expr->literals[iExpr];
- Literal thisAbs=abs(lThis);
- Literal exprAbs=abs(lExpr);
-
- while(iThis<thisSize && iExpr<exprSize) {
- if (thisAbs<exprAbs) {
- merged->literals[iMerge++]=lThis;
- lThis=This->literals[++iThis];
- thisAbs=abs(lThis);
- } else if(thisAbs>exprAbs) {
- merged->literals[iMerge++]=lExpr;
- lExpr=expr->literals[++iExpr];
- exprAbs=abs(lExpr);
- } else if(lThis==lExpr) {
- merged->literals[iMerge++]=lExpr;
- lExpr=expr->literals[++iExpr];
- exprAbs=abs(lExpr);
- lThis=This->literals[++iThis];
- thisAbs=abs(lThis);
- } else if(lThis==-lExpr) {
- merged->size=0;
+LitVector *mergeLitVectors(LitVector *This, LitVector *expr) {
+ uint maxsize = This->size + expr->size + MERGETHRESHOLD;
+ LitVector *merged = ourmalloc(sizeof(LitVector));
+ merged->literals = ourmalloc(sizeof(Literal) * maxsize);
+ merged->capacity = maxsize;
+ uint thisSize = boundedSize(This->size);
+ uint exprSize = boundedSize(expr->size);
+ uint iThis = 0, iExpr = 0, iMerge = 0;
+ Literal lThis = This->literals[iThis];
+ Literal lExpr = expr->literals[iExpr];
+ Literal thisAbs = abs(lThis);
+ Literal exprAbs = abs(lExpr);
+
+ while (iThis < thisSize && iExpr < exprSize) {
+ if (thisAbs < exprAbs) {
+ merged->literals[iMerge++] = lThis;
+ lThis = This->literals[++iThis];
+ thisAbs = abs(lThis);
+ } else if (thisAbs > exprAbs) {
+ merged->literals[iMerge++] = lExpr;
+ lExpr = expr->literals[++iExpr];
+ exprAbs = abs(lExpr);
+ } else if (lThis == lExpr) {
+ merged->literals[iMerge++] = lExpr;
+ lExpr = expr->literals[++iExpr];
+ exprAbs = abs(lExpr);
+ lThis = This->literals[++iThis];
+ thisAbs = abs(lThis);
+ } else if (lThis == -lExpr) {
+ merged->size = 0;
return merged;
}
}
if (iThis < thisSize) {
- memcpy(&merged->literals[iMerge], &This->literals[iThis], (thisSize-iThis) * sizeof(Literal));
- iMerge += (thisSize-iThis);
+ memcpy(&merged->literals[iMerge], &This->literals[iThis], (thisSize - iThis) * sizeof(Literal));
+ iMerge += (thisSize - iThis);
}
if (iExpr < exprSize) {
- memcpy(&merged->literals[iMerge], &expr->literals[iExpr], (exprSize-iExpr) * sizeof(Literal));
- iMerge += (exprSize-iExpr);
+ memcpy(&merged->literals[iMerge], &expr->literals[iExpr], (exprSize - iExpr) * sizeof(Literal));
+ iMerge += (exprSize - iExpr);
}
- merged->size=iMerge;
+ merged->size = iMerge;
return merged;
}
-LitVector * mergeLitVectorLiteral(LitVector *This, Literal l) {
- LitVector *copy=cloneLitVector(This);
+LitVector *mergeLitVectorLiteral(LitVector *This, Literal l) {
+ LitVector *copy = cloneLitVector(This);
addLiteralLitVector(copy, l);
return copy;
}
}
return;
} else if (destroy && This->litSize == 1) {
- Literal l=getLiteralLitVector(&This->singletons,0);
+ Literal l = getLiteralLitVector(&This->singletons,0);
copyCNF(This, expr, true);
disjoinCNFLit(This, l);
return;
}
-
+
/** Handle the full cross product */
- uint mergeIndex=0;
- uint newCapacity=getClauseSizeCNF(This)*getClauseSizeCNF(expr);
- LitVector ** mergeArray=ourmalloc(newCapacity*sizeof(LitVector*));
- uint singleIndex=0;
+ uint mergeIndex = 0;
+ uint newCapacity = getClauseSizeCNF(This) * getClauseSizeCNF(expr);
+ LitVector **mergeArray = ourmalloc(newCapacity * sizeof(LitVector *));
+ uint singleIndex = 0;
/** First do the singleton, clause pairs */
- for(uint i=0;i<getSizeLitVector(&This->singletons);i++) {
- Literal lThis=getLiteralLitVector(&This->singletons, i);
- for(uint j=0;j<getSizeVectorLitVector(&expr->clauses);j++) {
- LitVector * lExpr=getVectorLitVector(&expr->clauses, j);
- LitVector * copy=cloneLitVector(lExpr);
+ for (uint i = 0; i < getSizeLitVector(&This->singletons); i++) {
+ Literal lThis = getLiteralLitVector(&This->singletons, i);
+ for (uint j = 0; j < getSizeVectorLitVector(&expr->clauses); j++) {
+ LitVector *lExpr = getVectorLitVector(&expr->clauses, j);
+ LitVector *copy = cloneLitVector(lExpr);
addLiteralLitVector(copy, lThis);
- if (getSizeLitVector(copy)==0) {
+ if (getSizeLitVector(copy) == 0) {
deleteLitVector(copy);
} else {
- mergeArray[mergeIndex++]=copy;
+ mergeArray[mergeIndex++] = copy;
}
}
}
/** Next do the clause, singleton pairs */
- for(uint i=0;i<getSizeLitVector(&expr->singletons);i++) {
- Literal lExpr=getLiteralLitVector(&expr->singletons, i);
- for(uint j=0;j<getSizeVectorLitVector(&This->clauses);j++) {
- LitVector * lThis=getVectorLitVector(&This->clauses, j);
- LitVector * copy=cloneLitVector(lThis);
+ for (uint i = 0; i < getSizeLitVector(&expr->singletons); i++) {
+ Literal lExpr = getLiteralLitVector(&expr->singletons, i);
+ for (uint j = 0; j < getSizeVectorLitVector(&This->clauses); j++) {
+ LitVector *lThis = getVectorLitVector(&This->clauses, j);
+ LitVector *copy = cloneLitVector(lThis);
addLiteralLitVector(copy, lExpr);
- if (getSizeLitVector(copy)==0) {
+ if (getSizeLitVector(copy) == 0) {
deleteLitVector(copy);
} else {
- mergeArray[mergeIndex++]=copy;
+ mergeArray[mergeIndex++] = copy;
}
}
}
/** Next do the clause, clause pairs */
- for(uint i=0;i<getSizeVectorLitVector(&This->clauses);i++) {
- LitVector * lThis=getVectorLitVector(&This->clauses, i);
- for(uint j=0;j<getSizeVectorLitVector(&expr->clauses);j++) {
- LitVector * lExpr=getVectorLitVector(&expr->clauses, j);
- LitVector * merge=mergeLitVectors(lThis, lExpr);
- if (getSizeLitVector(merge)==0) {
+ for (uint i = 0; i < getSizeVectorLitVector(&This->clauses); i++) {
+ LitVector *lThis = getVectorLitVector(&This->clauses, i);
+ for (uint j = 0; j < getSizeVectorLitVector(&expr->clauses); j++) {
+ LitVector *lExpr = getVectorLitVector(&expr->clauses, j);
+ LitVector *merge = mergeLitVectors(lThis, lExpr);
+ if (getSizeLitVector(merge) == 0) {
deleteLitVector(merge);
} else {
- mergeArray[mergeIndex++]=merge;
+ mergeArray[mergeIndex++] = merge;
}
}
deleteLitVector(lThis);//Done with this litVector
}
-
+
/** Finally do the singleton, singleton pairs */
- for(uint i=0;i<getSizeLitVector(&This->singletons);i++) {
- Literal lThis=getLiteralLitVector(&This->singletons, i);
- for(uint j=0;j<getSizeLitVector(&expr->singletons);j++) {
- Literal lExpr=getLiteralLitVector(&expr->singletons, j);
- if (lThis==lExpr) {
- //We have a singleton still in the final result
- setLiteralLitVector(&This->singletons, singleIndex++, lThis);
- } else if (lThis!=-lExpr) {
- LitVector *mergeLV=allocLitVector();
- addLiteralLitVector(mergeLV, lThis);
- addLiteralLitVector(mergeLV, lExpr);
- mergeArray[mergeIndex++]=mergeLV;
- }
+ for (uint i = 0; i < getSizeLitVector(&This->singletons); i++) {
+ Literal lThis = getLiteralLitVector(&This->singletons, i);
+ for (uint j = 0; j < getSizeLitVector(&expr->singletons); j++) {
+ Literal lExpr = getLiteralLitVector(&expr->singletons, j);
+ if (lThis == lExpr) {
+ //We have a singleton still in the final result
+ setLiteralLitVector(&This->singletons, singleIndex++, lThis);
+ } else if (lThis != -lExpr) {
+ LitVector *mergeLV = allocLitVector();
+ addLiteralLitVector(mergeLV, lThis);
+ addLiteralLitVector(mergeLV, lExpr);
+ mergeArray[mergeIndex++] = mergeLV;
}
+ }
}
-
+
ourfree(This->clauses.array);
setSizeLitVector(&This->singletons, singleIndex);
- This->clauses.capacity=newCapacity;
- This->clauses.array=mergeArray;
- This->clauses.size=mergeIndex;
+ This->clauses.capacity = newCapacity;
+ This->clauses.array = mergeArray;
+ This->clauses.size = mergeIndex;
if (destroy)
deleteCNFExpr(expr);
}
void printCNFExpr(CNFExpr *This) {
- for(uint i=0;i<getSizeLitVector(&This->singletons);i++) {
- if (i!=0)
+ for (uint i = 0; i < getSizeLitVector(&This->singletons); i++) {
+ if (i != 0)
printf(" ^ ");
- Literal l=getLiteralLitVector(&This->singletons,i);
+ Literal l = getLiteralLitVector(&This->singletons,i);
printf ("%d",l);
}
- for(uint i=0;i<getSizeVectorLitVector(&This->clauses);i++) {
- LitVector *lv=getVectorLitVector(&This->clauses,i);
+ 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)
+ for (uint j = 0; j < getSizeLitVector(lv); j++) {
+ if (j != 0)
printf(" v ");
printf("%d", getLiteralLitVector(lv, j));
}
typedef struct CNFExpr CNFExpr;
-LitVector * allocLitVector();
+LitVector *allocLitVector();
void initLitVector(LitVector *This);
void clearLitVector(LitVector *This);
void freeLitVector(LitVector *This);
void addLiteralLitVector(LitVector *This, Literal l);
Literal getLiteralLitVector(LitVector *This, uint index);
void setLiteralLitVector(LitVector *This, uint index, Literal l);
-LitVector * mergeLitVectorLiteral(LitVector *This, Literal l);
-LitVector * mergeLitVectors(LitVector *This, LitVector *expr);
+LitVector *mergeLitVectorLiteral(LitVector *This, Literal l);
+LitVector *mergeLitVectors(LitVector *This, LitVector *expr);
static inline uint getSizeLitVector(LitVector *This) {return This->size;}
-static inline void setSizeLitVector(LitVector *This, uint size) {This->size=size;}
+static inline void setSizeLitVector(LitVector *This, uint size) {This->size = size;}
-CNFExpr * allocCNFExprBool(bool isTrue);
-CNFExpr * allocCNFExprLiteral(Literal l);
+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;}
-static inline bool alwaysFalseCNF(CNFExpr * This) {return (This->litSize==0) && !This->isTrue;}
-static inline uint getLitSizeCNF(CNFExpr * This) {return This->litSize;}
-static inline uint getClauseSizeCNF(CNFExpr * This) {return getSizeLitVector(&This->singletons) + getSizeVectorLitVector(&This->clauses);}
+static inline bool alwaysTrueCNF(CNFExpr *This) {return (This->litSize == 0) && This->isTrue;}
+static inline bool alwaysFalseCNF(CNFExpr *This) {return (This->litSize == 0) && !This->isTrue;}
+static inline uint getLitSizeCNF(CNFExpr *This) {return This->litSize;}
+static inline uint getClauseSizeCNF(CNFExpr *This) {return getSizeLitVector(&This->singletons) + getSizeVectorLitVector(&This->clauses);}
void conjoinCNFLit(CNFExpr *This, Literal l);
void disjoinCNFLit(CNFExpr *This, Literal l);
void disjoinCNFExpr(CNFExpr *This, CNFExpr *expr, bool destroy);
#include "inc_solver.h"
#include "cnfexpr.h"
#include "common.h"
-/*
-V2 Copyright (c) 2014 Ben Chambers, Eugene Goldberg, Pete Manolios,
-Vasilis Papavasileiou, Sudarshan Srinivasan, and Daron Vroon.
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software. If
-you download or use the software, send email to Pete Manolios
-(pete@ccs.neu.edu) with your name, contact information, and a short
-note describing what you want to use BAT for. For any reuse or
-distribution, you must make clear to others the license terms of this
-work.
-
-Contact Pete Manolios if you want any of these conditions waived.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-/*
-C port of CNF SAT Conversion Copyright Brian Demsky 2017.
-*/
+/*
+ V2 Copyright (c) 2014 Ben Chambers, Eugene Goldberg, Pete Manolios,
+ Vasilis Papavasileiou, Sudarshan Srinivasan, and Daron Vroon.
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software. If
+ you download or use the software, send email to Pete Manolios
+ (pete@ccs.neu.edu) with your name, contact information, and a short
+ note describing what you want to use BAT for. For any reuse or
+ distribution, you must make clear to others the license terms of this
+ work.
+
+ Contact Pete Manolios if you want any of these conditions waived.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ C port of CNF SAT Conversion Copyright Brian Demsky 2017.
+ */
VectorImpl(Edge, Edge, 16)
-Edge E_True={(Node *)(uintptr_t) EDGE_IS_VAR_CONSTANT};
-Edge E_False={(Node *)(uintptr_t) (EDGE_IS_VAR_CONSTANT | NEGATE_EDGE)};
-Edge E_BOGUS={(Node *)0x12345673};
-Edge E_NULL={(Node *)NULL};
-
-
-CNF * createCNF() {
- CNF * cnf=ourmalloc(sizeof(CNF));
- cnf->varcount=1;
- cnf->capacity=DEFAULT_CNF_ARRAY_SIZE;
- cnf->mask=cnf->capacity-1;
- cnf->node_array=ourcalloc(1, sizeof(Node *)*cnf->capacity);
- cnf->size=0;
- cnf->maxsize=(uint)(((double)cnf->capacity)*LOAD_FACTOR);
- cnf->enableMatching=true;
- initDefVectorEdge(& cnf->constraints);
- initDefVectorEdge(& cnf->args);
- cnf->solver=allocIncrementalSolver();
+Edge E_True = {(Node *)(uintptr_t) EDGE_IS_VAR_CONSTANT};
+Edge E_False = {(Node *)(uintptr_t) (EDGE_IS_VAR_CONSTANT | NEGATE_EDGE)};
+Edge E_BOGUS = {(Node *)0x12345673};
+Edge E_NULL = {(Node *)NULL};
+
+
+CNF *createCNF() {
+ CNF *cnf = ourmalloc(sizeof(CNF));
+ cnf->varcount = 1;
+ cnf->capacity = DEFAULT_CNF_ARRAY_SIZE;
+ cnf->mask = cnf->capacity - 1;
+ cnf->node_array = ourcalloc(1, sizeof(Node *) * cnf->capacity);
+ cnf->size = 0;
+ cnf->maxsize = (uint)(((double)cnf->capacity) * LOAD_FACTOR);
+ cnf->enableMatching = true;
+ initDefVectorEdge(&cnf->constraints);
+ initDefVectorEdge(&cnf->args);
+ cnf->solver = allocIncrementalSolver();
return cnf;
}
-void deleteCNF(CNF * cnf) {
- for(uint i=0;i<cnf->capacity;i++) {
- Node *n=cnf->node_array[i];
- if (n!=NULL)
+void deleteCNF(CNF *cnf) {
+ for (uint i = 0; i < cnf->capacity; i++) {
+ Node *n = cnf->node_array[i];
+ if (n != NULL)
ourfree(n);
}
- deleteVectorArrayEdge(& cnf->constraints);
- deleteVectorArrayEdge(& cnf->args);
+ deleteVectorArrayEdge(&cnf->constraints);
+ deleteVectorArrayEdge(&cnf->args);
deleteIncrementalSolver(cnf->solver);
ourfree(cnf->node_array);
ourfree(cnf);
}
void resizeCNF(CNF *cnf, uint newCapacity) {
- Node **old_array=cnf->node_array;
- Node **new_array=ourcalloc(1, sizeof(Node *)*newCapacity);
- uint oldCapacity=cnf->capacity;
- uint newMask=newCapacity-1;
- for(uint i=0;i<oldCapacity;i++) {
- Node *n=old_array[i];
- uint hashCode=n->hashCode;
- uint newindex=hashCode & newMask;
- for(;;newindex=(newindex+1) & newMask) {
+ Node **old_array = cnf->node_array;
+ Node **new_array = ourcalloc(1, sizeof(Node *) * newCapacity);
+ uint oldCapacity = cnf->capacity;
+ uint newMask = newCapacity - 1;
+ for (uint i = 0; i < oldCapacity; i++) {
+ Node *n = old_array[i];
+ uint hashCode = n->hashCode;
+ uint newindex = hashCode & newMask;
+ for (;; newindex = (newindex + 1) & newMask) {
if (new_array[newindex] == NULL) {
- new_array[newindex]=n;
+ new_array[newindex] = n;
break;
}
}
}
ourfree(old_array);
- cnf->node_array=new_array;
- cnf->capacity=newCapacity;
- cnf->maxsize=(uint)(((double)cnf->capacity)*LOAD_FACTOR);
- cnf->mask=newMask;
-}
-
-Node * allocNode(NodeType type, uint numEdges, Edge * edges, uint hashcode) {
- Node *n=(Node *)ourmalloc(sizeof(Node)+sizeof(Edge)*numEdges);
- memcpy(n->edges, edges, sizeof(Edge)*numEdges);
- n->flags.type=type;
- n->flags.wasExpanded=0;
- n->flags.cnfVisitedDown=0;
- n->flags.cnfVisitedUp=0;
- n->flags.varForced=0;
- n->numEdges=numEdges;
- n->hashCode=hashcode;
- n->intAnnot[0]=0;n->intAnnot[1]=0;
- n->ptrAnnot[0]=NULL;n->ptrAnnot[1]=NULL;
+ cnf->node_array = new_array;
+ cnf->capacity = newCapacity;
+ cnf->maxsize = (uint)(((double)cnf->capacity) * LOAD_FACTOR);
+ cnf->mask = newMask;
+}
+
+Node *allocNode(NodeType type, uint numEdges, Edge *edges, uint hashcode) {
+ Node *n = (Node *)ourmalloc(sizeof(Node) + sizeof(Edge) * numEdges);
+ memcpy(n->edges, edges, sizeof(Edge) * numEdges);
+ n->flags.type = type;
+ n->flags.wasExpanded = 0;
+ n->flags.cnfVisitedDown = 0;
+ n->flags.cnfVisitedUp = 0;
+ n->flags.varForced = 0;
+ n->numEdges = numEdges;
+ n->hashCode = hashcode;
+ n->intAnnot[0] = 0;n->intAnnot[1] = 0;
+ n->ptrAnnot[0] = NULL;n->ptrAnnot[1] = NULL;
return n;
}
-Edge createNode(CNF *cnf, NodeType type, uint numEdges, Edge * edges) {
+Edge createNode(CNF *cnf, NodeType type, uint numEdges, Edge *edges) {
if (cnf->size > cnf->maxsize) {
resizeCNF(cnf, cnf->capacity << 1);
}
- uint hashvalue=hashNode(type, numEdges, edges);
- uint mask=cnf->mask;
- uint index=hashvalue & mask;
+ uint hashvalue = hashNode(type, numEdges, edges);
+ uint mask = cnf->mask;
+ uint index = hashvalue & mask;
Node **n_ptr;
- for(;;index=(index+1)&mask) {
- n_ptr=&cnf->node_array[index];
- if (*n_ptr!=NULL) {
- if ((*n_ptr)->hashCode==hashvalue) {
+ for (;; index = (index + 1) & mask) {
+ n_ptr = &cnf->node_array[index];
+ if (*n_ptr != NULL) {
+ if ((*n_ptr)->hashCode == hashvalue) {
if (compareNodes(*n_ptr, type, numEdges, edges)) {
- Edge e={*n_ptr};
+ Edge e = {*n_ptr};
return e;
}
}
break;
}
}
- *n_ptr=allocNode(type, numEdges, edges, hashvalue);
- Edge e={*n_ptr};
+ *n_ptr = allocNode(type, numEdges, edges, hashvalue);
+ Edge e = {*n_ptr};
return e;
}
-uint hashNode(NodeType type, uint numEdges, Edge * edges) {
- uint hashvalue=type ^ numEdges;
- for(uint i=0;i<numEdges;i++) {
+uint hashNode(NodeType type, uint numEdges, Edge *edges) {
+ uint hashvalue = type ^ numEdges;
+ for (uint i = 0; i < numEdges; i++) {
hashvalue ^= (uint) ((uintptr_t) edges[i].node_ptr);
- hashvalue = (hashvalue << 3) | (hashvalue >> 29); //rotate left by 3 bits
+ hashvalue = (hashvalue << 3) | (hashvalue >> 29); //rotate left by 3 bits
}
return (uint) hashvalue;
}
-bool compareNodes(Node * node, NodeType type, uint numEdges, Edge *edges) {
- if (node->flags.type!=type || node->numEdges != numEdges)
+bool compareNodes(Node *node, NodeType type, uint numEdges, Edge *edges) {
+ if (node->flags.type != type || node->numEdges != numEdges)
return false;
- Edge *nodeedges=node->edges;
- for(uint i=0;i<numEdges;i++) {
+ Edge *nodeedges = node->edges;
+ for (uint i = 0; i < numEdges; i++) {
if (!equalsEdge(nodeedges[i], edges[i]))
return false;
}
return true;
}
-Edge constraintOR(CNF * cnf, uint numEdges, Edge *edges) {
+Edge constraintOR(CNF *cnf, uint numEdges, Edge *edges) {
Edge edgearray[numEdges];
-
- for(uint i=0; i<numEdges; i++) {
- edgearray[i]=constraintNegate(edges[i]);
+
+ for (uint i = 0; i < numEdges; i++) {
+ edgearray[i] = constraintNegate(edges[i]);
}
- Edge eand=constraintAND(cnf, numEdges, edgearray);
+ Edge eand = constraintAND(cnf, numEdges, edgearray);
return constraintNegate(eand);
}
-Edge constraintOR2(CNF * cnf, Edge left, Edge right) {
- Edge lneg=constraintNegate(left);
- Edge rneg=constraintNegate(right);
- Edge eand=constraintAND2(cnf, lneg, rneg);
+Edge constraintOR2(CNF *cnf, Edge left, Edge right) {
+ Edge lneg = constraintNegate(left);
+ Edge rneg = constraintNegate(right);
+ Edge eand = constraintAND2(cnf, lneg, rneg);
return constraintNegate(eand);
}
-int comparefunction(const Edge * e1, const Edge * e2) {
- return ((uintptr_t)e1->node_ptr)-((uintptr_t)e2->node_ptr);
+int comparefunction(const Edge *e1, const Edge *e2) {
+ return ((uintptr_t)e1->node_ptr) - ((uintptr_t)e2->node_ptr);
}
-Edge constraintAND(CNF * cnf, uint numEdges, Edge * edges) {
- ASSERT(numEdges!=0);
- qsort(edges, numEdges, sizeof(Edge), (int (*)(const void *, const void *)) comparefunction);
- int initindex=0;
- while(initindex<numEdges && equalsEdge(edges[initindex], E_True))
+Edge constraintAND(CNF *cnf, uint numEdges, Edge *edges) {
+ ASSERT(numEdges != 0);
+ qsort(edges, numEdges, sizeof(Edge), (int (*)(const void *, const void *))comparefunction);
+ int initindex = 0;
+ while (initindex < numEdges && equalsEdge(edges[initindex], E_True))
initindex++;
- uint remainSize=numEdges-initindex;
+ uint remainSize = numEdges - initindex;
if (remainSize == 0)
return E_True;
return E_False;
/** De-duplicate array */
- uint lowindex=0;
- edges[lowindex]=edges[initindex++];
+ uint lowindex = 0;
+ edges[lowindex] = edges[initindex++];
- for(;initindex<numEdges;initindex++) {
- Edge e1=edges[lowindex];
- Edge e2=edges[initindex];
+ for (; initindex < numEdges; initindex++) {
+ Edge e1 = edges[lowindex];
+ Edge e2 = edges[initindex];
if (sameNodeVarEdge(e1, e2)) {
if (!sameSignEdge(e1, e2)) {
return E_False;
}
} else
- edges[++lowindex]=edges[initindex];
+ edges[++lowindex] = edges[initindex];
}
- lowindex++; //Make lowindex look like size
+ lowindex++; //Make lowindex look like size
- if (lowindex==1)
+ if (lowindex == 1)
return edges[0];
- if (cnf->enableMatching && lowindex==2 &&
+ if (cnf->enableMatching && lowindex == 2 &&
isNegNodeEdge(edges[0]) && isNegNodeEdge(edges[1]) &&
getNodeType(edges[0]) == NodeType_AND &&
getNodeType(edges[1]) == NodeType_AND &&
getNodeSize(edges[0]) == 2 &&
getNodeSize(edges[1]) == 2) {
- Edge * e0edges=getEdgeArray(edges[0]);
- Edge * e1edges=getEdgeArray(edges[1]);
+ Edge *e0edges = getEdgeArray(edges[0]);
+ Edge *e1edges = getEdgeArray(edges[1]);
if (sameNodeOppSign(e0edges[0], e1edges[0])) {
return constraintNegate(constraintITE(cnf, e0edges[0], e0edges[1], e1edges[1]));
} else if (sameNodeOppSign(e0edges[0], e1edges[1])) {
return createNode(cnf, NodeType_AND, lowindex, edges);
}
-Edge constraintAND2(CNF * cnf, Edge left, Edge right) {
- Edge edges[2]={left, right};
+Edge constraintAND2(CNF *cnf, Edge left, Edge right) {
+ Edge edges[2] = {left, right};
return constraintAND(cnf, 2, edges);
}
-Edge constraintIMPLIES(CNF * cnf, Edge left, Edge right) {
+Edge constraintIMPLIES(CNF *cnf, Edge left, Edge right) {
Edge array[2];
- array[0]=left;
- array[1]=constraintNegate(right);
- Edge eand=constraintAND(cnf, 2, array);
+ array[0] = left;
+ array[1] = constraintNegate(right);
+ Edge eand = constraintAND(cnf, 2, array);
return constraintNegate(eand);
}
-Edge constraintIFF(CNF * cnf, Edge left, Edge right) {
- bool negate=!sameSignEdge(left, right);
- Edge lpos=getNonNeg(left);
- Edge rpos=getNonNeg(right);
+Edge constraintIFF(CNF *cnf, Edge left, Edge right) {
+ bool negate = !sameSignEdge(left, right);
+ Edge lpos = getNonNeg(left);
+ Edge rpos = getNonNeg(right);
Edge e;
if (equalsEdge(lpos, rpos)) {
- e=E_True;
+ e = E_True;
} else if (ltEdge(lpos, rpos)) {
- Edge edges[]={lpos, rpos};
- e=(edgeIsConst(lpos)) ? rpos : createNode(cnf, NodeType_IFF, 2, edges);
+ Edge edges[] = {lpos, rpos};
+ e = (edgeIsConst(lpos)) ? rpos : createNode(cnf, NodeType_IFF, 2, edges);
} else {
- Edge edges[]={rpos, lpos};
- e=(edgeIsConst(rpos)) ? lpos : createNode(cnf, NodeType_IFF, 2, edges);
+ Edge edges[] = {rpos, lpos};
+ e = (edgeIsConst(rpos)) ? lpos : createNode(cnf, NodeType_IFF, 2, edges);
}
if (negate)
- e=constraintNegate(e);
+ e = constraintNegate(e);
return e;
}
-Edge constraintITE(CNF * cnf, Edge cond, Edge thenedge, Edge elseedge) {
+Edge constraintITE(CNF *cnf, Edge cond, Edge thenedge, Edge elseedge) {
if (isNegEdge(cond)) {
- cond=constraintNegate(cond);
- Edge tmp=thenedge;
- thenedge=elseedge;
- elseedge=tmp;
+ cond = constraintNegate(cond);
+ Edge tmp = thenedge;
+ thenedge = elseedge;
+ elseedge = tmp;
}
-
+
bool negate = isNegEdge(thenedge);
if (negate) {
- thenedge=constraintNegate(thenedge);
- elseedge=constraintNegate(elseedge);
+ thenedge = constraintNegate(thenedge);
+ elseedge = constraintNegate(elseedge);
}
Edge result;
if (equalsEdge(cond, E_True)) {
- result=thenedge;
+ result = thenedge;
} else if (equalsEdge(thenedge, E_True) || equalsEdge(cond, thenedge)) {
- result=constraintOR(cnf, 2, (Edge[]) {cond, elseedge});
- } else if (equalsEdge(elseedge, E_True) || sameNodeOppSign(cond, elseedge)) {
- result=constraintIMPLIES(cnf, cond, thenedge);
+ result = constraintOR(cnf, 2, (Edge[]) {cond, elseedge});
+ } else if (equalsEdge(elseedge, E_True) || sameNodeOppSign(cond, elseedge)) {
+ result = constraintIMPLIES(cnf, cond, thenedge);
} else if (equalsEdge(thenedge, E_False) || equalsEdge(cond, elseedge)) {
- result=constraintAND(cnf, 2, (Edge[]) {cond, thenedge});
+ result = constraintAND(cnf, 2, (Edge[]) {cond, thenedge});
} else if (equalsEdge(thenedge, elseedge)) {
- result=thenedge;
+ result = thenedge;
} else if (sameNodeOppSign(thenedge, elseedge)) {
if (ltEdge(cond, thenedge)) {
- result=createNode(cnf, NodeType_IFF, 2, (Edge[]) {cond, thenedge});
+ result = createNode(cnf, NodeType_IFF, 2, (Edge[]) {cond, thenedge});
} else {
- result=createNode(cnf, NodeType_IFF, 2, (Edge[]) {thenedge, cond});
+ result = createNode(cnf, NodeType_IFF, 2, (Edge[]) {thenedge, cond});
}
} else {
- Edge edges[]={cond, thenedge, elseedge};
- result=createNode(cnf, NodeType_ITE, 3, edges);
+ Edge edges[] = {cond, thenedge, elseedge};
+ result = createNode(cnf, NodeType_ITE, 3, edges);
}
if (negate)
- result=constraintNegate(result);
+ result = constraintNegate(result);
return result;
}
}
Edge constraintNewVar(CNF *cnf) {
- uint varnum=cnf->varcount++;
- Edge e={(Node *) ((((uintptr_t)varnum) << VAR_SHIFT) | EDGE_IS_VAR_CONSTANT) };
+ uint varnum = cnf->varcount++;
+ Edge e = {(Node *) ((((uintptr_t)varnum) << VAR_SHIFT) | EDGE_IS_VAR_CONSTANT) };
return e;
}
}
bool getValueCNF(CNF *cnf, Edge var) {
- Literal l=getEdgeVar(var);
- bool isneg=(l<0);
- l=abs(l);
+ Literal l = getEdgeVar(var);
+ bool isneg = (l < 0);
+ l = abs(l);
return isneg ^ getValueSolver(cnf->solver, l);
}
void countPass(CNF *cnf) {
- uint numConstraints=getSizeVectorEdge(&cnf->constraints);
- VectorEdge *ve=allocDefVectorEdge();
- for(uint i=0; i<numConstraints;i++) {
+ uint numConstraints = getSizeVectorEdge(&cnf->constraints);
+ VectorEdge *ve = allocDefVectorEdge();
+ for (uint i = 0; i < numConstraints; i++) {
countConstraint(cnf, ve, getVectorEdge(&cnf->constraints, i));
}
deleteVectorEdge(ve);
clearVectorEdge(stack);pushVectorEdge(stack, eroot);
- bool isMatching=cnf->enableMatching;
-
- while(getSizeVectorEdge(stack) != 0) {
- Edge e=lastVectorEdge(stack); popVectorEdge(stack);
- bool polarity=isNegEdge(e);
- Node *n=getNodePtrFromEdge(e);
+ bool isMatching = cnf->enableMatching;
+
+ while (getSizeVectorEdge(stack) != 0) {
+ Edge e = lastVectorEdge(stack); popVectorEdge(stack);
+ bool polarity = isNegEdge(e);
+ Node *n = getNodePtrFromEdge(e);
if (getExpanded(n, polarity)) {
if (n->flags.type == NodeType_IFF ||
n->flags.type == NodeType_ITE) {
- Edge pExp={n->ptrAnnot[polarity]};
+ Edge pExp = {n->ptrAnnot[polarity]};
getNodePtrFromEdge(pExp)->intAnnot[0]++;
} else {
n->intAnnot[polarity]++;
} else {
setExpanded(n, polarity);
- if (n->flags.type == NodeType_ITE||
+ if (n->flags.type == NodeType_ITE ||
n->flags.type == NodeType_IFF) {
- n->intAnnot[polarity]=0;
- Edge cond=n->edges[0];
- Edge thenedge=n->edges[1];
- Edge elseedge=n->flags.type == NodeType_IFF? constraintNegate(thenedge): n->edges[2];
- thenedge=constraintNegateIf(thenedge, !polarity);
- elseedge=constraintNegateIf(elseedge, !polarity);
- thenedge=constraintAND2(cnf, cond, thenedge);
- cond=constraintNegate(cond);
- elseedge=constraintAND2(cnf, cond, elseedge);
- thenedge=constraintNegate(thenedge);
- elseedge=constraintNegate(elseedge);
- cnf->enableMatching=false;
- Edge succ1=constraintAND2(cnf, thenedge, elseedge);
- n->ptrAnnot[polarity]=succ1.node_ptr;
- cnf->enableMatching=isMatching;
+ n->intAnnot[polarity] = 0;
+ Edge cond = n->edges[0];
+ Edge thenedge = n->edges[1];
+ Edge elseedge = n->flags.type == NodeType_IFF ? constraintNegate(thenedge) : n->edges[2];
+ thenedge = constraintNegateIf(thenedge, !polarity);
+ elseedge = constraintNegateIf(elseedge, !polarity);
+ thenedge = constraintAND2(cnf, cond, thenedge);
+ cond = constraintNegate(cond);
+ elseedge = constraintAND2(cnf, cond, elseedge);
+ thenedge = constraintNegate(thenedge);
+ elseedge = constraintNegate(elseedge);
+ cnf->enableMatching = false;
+ Edge succ1 = constraintAND2(cnf, thenedge, elseedge);
+ n->ptrAnnot[polarity] = succ1.node_ptr;
+ cnf->enableMatching = isMatching;
pushVectorEdge(stack, succ1);
if (getExpanded(n, !polarity)) {
- Edge succ2={(Node *)n->ptrAnnot[!polarity]};
- Node *n1=getNodePtrFromEdge(succ1);
- Node *n2=getNodePtrFromEdge(succ2);
- n1->ptrAnnot[0]=succ2.node_ptr;
- n2->ptrAnnot[0]=succ1.node_ptr;
- n1->ptrAnnot[1]=succ2.node_ptr;
- n2->ptrAnnot[1]=succ1.node_ptr;
- }
+ Edge succ2 = {(Node *)n->ptrAnnot[!polarity]};
+ Node *n1 = getNodePtrFromEdge(succ1);
+ Node *n2 = getNodePtrFromEdge(succ2);
+ n1->ptrAnnot[0] = succ2.node_ptr;
+ n2->ptrAnnot[0] = succ1.node_ptr;
+ n1->ptrAnnot[1] = succ2.node_ptr;
+ n2->ptrAnnot[1] = succ1.node_ptr;
+ }
} else {
- n->intAnnot[polarity]=1;
- for (uint i=0;i<n->numEdges;i++) {
- Edge succ=n->edges[i];
- if(!edgeIsVarConst(succ)) {
- succ=constraintNegateIf(succ, polarity);
+ n->intAnnot[polarity] = 1;
+ for (uint i = 0; i < n->numEdges; i++) {
+ Edge succ = n->edges[i];
+ if (!edgeIsVarConst(succ)) {
+ succ = constraintNegateIf(succ, polarity);
pushVectorEdge(stack, succ);
}
}
}
void convertPass(CNF *cnf, bool backtrackLit) {
- uint numConstraints=getSizeVectorEdge(&cnf->constraints);
- VectorEdge *ve=allocDefVectorEdge();
- for(uint i=0; i<numConstraints;i++) {
+ uint numConstraints = getSizeVectorEdge(&cnf->constraints);
+ VectorEdge *ve = allocDefVectorEdge();
+ for (uint i = 0; i < numConstraints; i++) {
convertConstraint(cnf, ve, getVectorEdge(&cnf->constraints, i), backtrackLit);
}
deleteVectorEdge(ve);
}
void convertConstraint(CNF *cnf, VectorEdge *stack, Edge root, bool backtrackLit) {
- Node *nroot=getNodePtrFromEdge(root);
-
+ Node *nroot = getNodePtrFromEdge(root);
+
if (isNodeEdge(root) && (nroot->flags.type == NodeType_ITE || nroot->flags.type == NodeType_IFF)) {
nroot = (Node *) nroot->ptrAnnot[isNegEdge(root)];
root = (Edge) { nroot };
if (edgeIsConst(root)) {
if (isNegEdge(root)) {
//trivally unsat
- Edge newvar=constraintNewVar(cnf);
- Literal var=getEdgeVar(newvar);
+ Edge newvar = constraintNewVar(cnf);
+ Literal var = getEdgeVar(newvar);
Literal clause[] = {var};
addArrayClauseLiteral(cnf->solver, 1, clause);
- clause[0]=-var;
+ clause[0] = -var;
addArrayClauseLiteral(cnf->solver, 1, clause);
return;
} else {
addArrayClauseLiteral(cnf->solver, 1, clause);
return;
}
-
+
clearVectorEdge(stack);pushVectorEdge(stack, root);
- while(getSizeVectorEdge(stack)!=0) {
- Edge e=lastVectorEdge(stack);
- Node *n=getNodePtrFromEdge(e);
+ while (getSizeVectorEdge(stack) != 0) {
+ Edge e = lastVectorEdge(stack);
+ Node *n = getNodePtrFromEdge(e);
if (edgeIsVarConst(e)) {
popVectorEdge(stack);
continue;
- } else if (n->flags.type==NodeType_ITE ||
- n->flags.type==NodeType_IFF) {
+ } else if (n->flags.type == NodeType_ITE ||
+ n->flags.type == NodeType_IFF) {
popVectorEdge(stack);
- if (n->ptrAnnot[0]!=NULL)
+ if (n->ptrAnnot[0] != NULL)
pushVectorEdge(stack, (Edge) {(Node *)n->ptrAnnot[0]});
- if (n->ptrAnnot[1]!=NULL)
+ if (n->ptrAnnot[1] != NULL)
pushVectorEdge(stack, (Edge) {(Node *)n->ptrAnnot[1]});
continue;
}
} else if ((needPos && !(n->flags.cnfVisitedDown & 1)) ||
(needNeg && !(n->flags.cnfVisitedDown & 2))) {
if (needPos)
- n->flags.cnfVisitedDown|=1;
+ n->flags.cnfVisitedDown |= 1;
if (needNeg)
- n->flags.cnfVisitedDown|=2;
- for(uint i=0; i<n->numEdges; i++) {
- Edge arg=n->edges[i];
- arg=constraintNegateIf(arg, isNegEdge(e));
- pushVectorEdge(stack, arg); //WARNING, THIS LOOKS LIKE A BUG IN THE ORIGINAL CODE
+ n->flags.cnfVisitedDown |= 2;
+ for (uint i = 0; i < n->numEdges; i++) {
+ Edge arg = n->edges[i];
+ arg = constraintNegateIf(arg, isNegEdge(e));
+ pushVectorEdge(stack, arg); //WARNING, THIS LOOKS LIKE A BUG IN THE ORIGINAL CODE
}
} else {
popVectorEdge(stack);
produceCNF(cnf, e);
}
}
- CNFExpr * cnfExp = (CNFExpr *) nroot->ptrAnnot[isNegEdge(root)];
- ASSERT(cnfExp!=NULL);
+ CNFExpr *cnfExp = (CNFExpr *) nroot->ptrAnnot[isNegEdge(root)];
+ ASSERT(cnfExp != NULL);
if (isProxy(cnfExp)) {
- Literal l=getProxy(cnfExp);
+ Literal l = getProxy(cnfExp);
Literal clause[] = {l};
addArrayClauseLiteral(cnf->solver, 1, clause);
} else if (backtrackLit) {
- Literal l=introProxy(cnf, root, cnfExp, isNegEdge(root));
+ Literal l = introProxy(cnf, root, cnfExp, isNegEdge(root));
Literal clause[] = {l};
addArrayClauseLiteral(cnf->solver, 1, clause);
} else {
}
-Literal introProxy(CNF * cnf, Edge e, CNFExpr* exp, bool isNeg) {
+Literal introProxy(CNF *cnf, Edge e, CNFExpr *exp, bool isNeg) {
Literal l = 0;
- Node * n = getNodePtrFromEdge(e);
-
- if (n->flags.cnfVisitedUp & (1<<!isNeg)) {
- CNFExpr* otherExp = (CNFExpr*) n->ptrAnnot[!isNeg];
+ Node *n = getNodePtrFromEdge(e);
+
+ if (n->flags.cnfVisitedUp & (1 << !isNeg)) {
+ CNFExpr *otherExp = (CNFExpr *) n->ptrAnnot[!isNeg];
if (isProxy(otherExp))
l = -getProxy(otherExp);
} else {
- Edge semNeg={(Node *) n->ptrAnnot[isNeg]};
- Node * nsemNeg=getNodePtrFromEdge(semNeg);
+ Edge semNeg = {(Node *) n->ptrAnnot[isNeg]};
+ Node *nsemNeg = getNodePtrFromEdge(semNeg);
if (nsemNeg != NULL) {
if (nsemNeg->flags.cnfVisitedUp & (1 << isNeg)) {
- CNFExpr* otherExp = (CNFExpr*) nsemNeg->ptrAnnot[isNeg];
+ CNFExpr *otherExp = (CNFExpr *) nsemNeg->ptrAnnot[isNeg];
if (isProxy(otherExp))
l = -getProxy(otherExp);
- } else if (nsemNeg->flags.cnfVisitedUp & (1<< !isNeg)) {
- CNFExpr* otherExp = (CNFExpr*) nsemNeg->ptrAnnot[!isNeg];
+ } else if (nsemNeg->flags.cnfVisitedUp & (1 << !isNeg)) {
+ CNFExpr *otherExp = (CNFExpr *) nsemNeg->ptrAnnot[!isNeg];
if (isProxy(otherExp))
l = getProxy(otherExp);
}
}
}
-
+
if (l == 0) {
Edge newvar = constraintNewVar(cnf);
l = getEdgeVar(newvar);
// Output the constraints on the auxiliary variable
constrainCNF(cnf, l, exp);
deleteCNFExpr(exp);
-
- n->ptrAnnot[isNeg] = (void*) ((intptr_t) (l << 1) | 1);
-
+
+ n->ptrAnnot[isNeg] = (void *) ((intptr_t) (l << 1) | 1);
+
return l;
}
-void produceCNF(CNF * cnf, Edge e) {
- CNFExpr* expPos = NULL;
- CNFExpr* expNeg = NULL;
+void produceCNF(CNF *cnf, Edge e) {
+ CNFExpr *expPos = NULL;
+ CNFExpr *expNeg = NULL;
Node *n = getNodePtrFromEdge(e);
-
+
if (n->intAnnot[0] > 0) {
expPos = produceConjunction(cnf, e);
}
/// produced for them at the right point
///
/// propagate(solver, expPos, snPos, false) || propagate(solver, expNeg, snNeg, false)
-
+
// propagate from positive to negative, negative to positive
- if (!propagate(cnf, & expPos, expNeg, true))
- propagate(cnf, & expNeg, expPos, true);
-
+ if (!propagate(cnf, &expPos, expNeg, true))
+ propagate(cnf, &expNeg, expPos, true);
+
// The polarity heuristic entails visiting the discovery polarity first
if (isPosEdge(e)) {
saveCNF(cnf, expPos, e, false);
}
}
-bool propagate(CNF *cnf, CNFExpr ** dest, CNFExpr * src, bool negate) {
+bool propagate(CNF *cnf, CNFExpr **dest, CNFExpr *src, bool negate) {
if (src != NULL && !isProxy(src) && getLitSizeCNF(src) == 0) {
if (*dest == NULL) {
*dest = allocCNFExprBool(negate ? alwaysFalseCNF(src) : alwaysTrueCNF(src));
Literal clause[] = {-getProxy(*dest)};
addArrayClauseLiteral(cnf->solver, 1, clause);
}
-
+
*dest = allocCNFExprBool(negate ? alwaysFalseCNF(src) : alwaysTrueCNF(src));
} else {
clearCNFExpr(*dest, negate ? alwaysFalseCNF(src) : alwaysTrueCNF(src));
return false;
}
-void saveCNF(CNF *cnf, CNFExpr* exp, Edge e, bool sign) {
- Node *n=getNodePtrFromEdge(e);
+void saveCNF(CNF *cnf, CNFExpr *exp, Edge e, bool sign) {
+ Node *n = getNodePtrFromEdge(e);
n->flags.cnfVisitedUp |= (1 << sign);
if (exp == NULL || isProxy(exp)) return;
-
+
if (exp->litSize == 1) {
Literal l = getLiteralLitVector(&exp->singletons, 0);
deleteCNFExpr(exp);
- n->ptrAnnot[sign] = (void*) ((((intptr_t) l) << 1) | 1);
+ n->ptrAnnot[sign] = (void *) ((((intptr_t) l) << 1) | 1);
} else if (exp->litSize != 0 && (n->intAnnot[sign] > 1 || n->flags.varForced)) {
introProxy(cnf, e, exp, sign);
} else {
}
}
-void constrainCNF(CNF * cnf, Literal lcond, CNFExpr *expr) {
+void constrainCNF(CNF *cnf, Literal lcond, CNFExpr *expr) {
if (alwaysTrueCNF(expr)) {
return;
} else if (alwaysFalseCNF(expr)) {
addArrayClauseLiteral(cnf->solver, 1, clause);
return;
}
-
- for(uint i=0;i<getSizeLitVector(&expr->singletons);i++) {
- Literal l=getLiteralLitVector(&expr->singletons,i);
+
+ for (uint i = 0; i < getSizeLitVector(&expr->singletons); i++) {
+ Literal l = getLiteralLitVector(&expr->singletons,i);
Literal clause[] = {-lcond, l};
addArrayClauseLiteral(cnf->solver, 2, clause);
}
- for(uint i=0;i<getSizeVectorLitVector(&expr->clauses);i++) {
- LitVector *lv=getVectorLitVector(&expr->clauses,i);
- addClauseLiteral(cnf->solver, -lcond); //Add first literal
- addArrayClauseLiteral(cnf->solver, getSizeLitVector(lv), lv->literals); //Add rest
+ for (uint i = 0; i < getSizeVectorLitVector(&expr->clauses); i++) {
+ LitVector *lv = getVectorLitVector(&expr->clauses,i);
+ addClauseLiteral(cnf->solver, -lcond);//Add first literal
+ addArrayClauseLiteral(cnf->solver, getSizeLitVector(lv), lv->literals); //Add rest
}
}
void outputCNF(CNF *cnf, CNFExpr *expr) {
- for(uint i=0;i<getSizeLitVector(&expr->singletons);i++) {
- Literal l=getLiteralLitVector(&expr->singletons,i);
+ for (uint i = 0; i < getSizeLitVector(&expr->singletons); i++) {
+ Literal l = getLiteralLitVector(&expr->singletons,i);
Literal clause[] = {l};
addArrayClauseLiteral(cnf->solver, 1, clause);
}
- for(uint i=0;i<getSizeVectorLitVector(&expr->clauses);i++) {
- LitVector *lv=getVectorLitVector(&expr->clauses,i);
+ for (uint i = 0; i < getSizeVectorLitVector(&expr->clauses); i++) {
+ LitVector *lv = getVectorLitVector(&expr->clauses,i);
addArrayClauseLiteral(cnf->solver, getSizeLitVector(lv), lv->literals);
}
}
-CNFExpr* fillArgs(CNF *cnf, Edge e, bool isNeg, Edge * largestEdge) {
+CNFExpr *fillArgs(CNF *cnf, Edge e, bool isNeg, Edge *largestEdge) {
clearVectorEdge(&cnf->args);
- *largestEdge = (Edge) {(Node*) NULL};
- CNFExpr* largest = NULL;
- Node *n=getNodePtrFromEdge(e);
+ *largestEdge = (Edge) {(Node *) NULL};
+ CNFExpr *largest = NULL;
+ Node *n = getNodePtrFromEdge(e);
int i = n->numEdges;
while (i != 0) {
Edge arg = n->edges[--i];
- arg=constraintNegateIf(arg, isNeg);
- Node * narg = getNodePtrFromEdge(arg);
-
+ arg = constraintNegateIf(arg, isNeg);
+ Node *narg = getNodePtrFromEdge(arg);
+
if (edgeIsVarConst(arg)) {
pushVectorEdge(&cnf->args, arg);
continue;
}
-
+
if (narg->flags.type == NodeType_ITE || narg->flags.type == NodeType_IFF) {
arg = (Edge) {(Node *) narg->ptrAnnot[isNegEdge(arg)]};
}
-
+
if (narg->intAnnot[isNegEdge(arg)] == 1) {
- CNFExpr* argExp = (CNFExpr*) narg->ptrAnnot[isNegEdge(arg)];
+ CNFExpr *argExp = (CNFExpr *) narg->ptrAnnot[isNegEdge(arg)];
if (!isProxy(argExp)) {
if (largest == NULL) {
largest = argExp;
- * largestEdge = arg;
+ *largestEdge = arg;
continue;
} else if (argExp->litSize > largest->litSize) {
pushVectorEdge(&cnf->args, *largestEdge);
largest = argExp;
- * largestEdge = arg;
+ *largestEdge = arg;
continue;
}
}
}
pushVectorEdge(&cnf->args, arg);
}
-
+
if (largest != NULL) {
- Node *nlargestEdge=getNodePtrFromEdge(*largestEdge);
+ Node *nlargestEdge = getNodePtrFromEdge(*largestEdge);
nlargestEdge->ptrAnnot[isNegEdge(*largestEdge)] = NULL;
}
-
+
return largest;
}
void printCNF(Edge e) {
if (edgeIsVarConst(e)) {
- Literal l=getEdgeVar(e);
+ Literal l = getEdgeVar(e);
model_print ("%d", l);
return;
}
- bool isNeg=isNegEdge(e);
+ bool isNeg = isNegEdge(e);
if (edgeIsConst(e)) {
if (isNeg)
model_print("T");
model_print("F");
return;
}
- Node *n=getNodePtrFromEdge(e);
+ Node *n = getNodePtrFromEdge(e);
if (isNeg) {
//Pretty print things that are equivalent to OR's
- if (getNodeType(e)==NodeType_AND) {
+ if (getNodeType(e) == NodeType_AND) {
model_print("or(");
- for(uint i=0;i<n->numEdges;i++) {
- Edge e=n->edges[i];
- if (i!=0)
+ for (uint i = 0; i < n->numEdges; i++) {
+ Edge e = n->edges[i];
+ if (i != 0)
model_print(" ");
printCNF(constraintNegate(e));
}
model_print("!");
}
- switch(getNodeType(e)) {
+ switch (getNodeType(e)) {
case NodeType_AND:
model_print("and");
break;
break;
}
model_print("(");
- for(uint i=0;i<n->numEdges;i++) {
- Edge e=n->edges[i];
- if (i!=0)
+ for (uint i = 0; i < n->numEdges; i++) {
+ Edge e = n->edges[i];
+ if (i != 0)
model_print(" ");
printCNF(e);
}
model_print(")");
}
-CNFExpr * produceConjunction(CNF * cnf, Edge e) {
+CNFExpr *produceConjunction(CNF *cnf, Edge e) {
Edge largestEdge;
-
- CNFExpr* accum = fillArgs(cnf, e, false, &largestEdge);
+
+ CNFExpr *accum = fillArgs(cnf, e, false, &largestEdge);
if (accum == NULL)
accum = allocCNFExprBool(true);
-
+
int i = getSizeVectorEdge(&cnf->args);
while (i != 0) {
Edge arg = getVectorEdge(&cnf->args, --i);
if (edgeIsVarConst(arg)) {
conjoinCNFLit(accum, getEdgeVar(arg));
} else {
- Node *narg=getNodePtrFromEdge(arg);
- CNFExpr* argExp = (CNFExpr*) narg->ptrAnnot[isNegEdge(arg)];
-
+ Node *narg = getNodePtrFromEdge(arg);
+ CNFExpr *argExp = (CNFExpr *) narg->ptrAnnot[isNegEdge(arg)];
+
bool destroy = (--narg->intAnnot[isNegEdge(arg)] == 0);
- if (isProxy(argExp)) { // variable has been introduced
+ if (isProxy(argExp)) {// variable has been introduced
conjoinCNFLit(accum, getProxy(argExp));
} else {
conjoinCNFExpr(accum, argExp, destroy);
}
}
}
-
+
return accum;
}
#define CLAUSE_MAX 3
-CNFExpr* produceDisjunction(CNF *cnf, Edge e) {
+CNFExpr *produceDisjunction(CNF *cnf, Edge e) {
Edge largestEdge;
- CNFExpr* accum = fillArgs(cnf, e, true, &largestEdge);
+ CNFExpr *accum = fillArgs(cnf, e, true, &largestEdge);
if (accum == NULL)
accum = allocCNFExprBool(false);
-
+
// This is necessary to check to make sure that we don't start out
// with an accumulator that is "too large".
-
+
/// @todo Strictly speaking, introProxy doesn't *need* to free
/// memory, then this wouldn't have to reallocate CNFExpr
-
+
/// @todo When this call to introProxy is made, the semantic
/// negation pointer will have been destroyed. Thus, it will not
/// be possible to use the correct proxy. That should be fixed.
-
+
// at this point, we will either have NULL, or a destructible expression
if (getClauseSizeCNF(accum) > CLAUSE_MAX)
accum = allocCNFExprLiteral(introProxy(cnf, largestEdge, accum, isNegEdge(largestEdge)));
-
+
int i = getSizeVectorEdge(&cnf->args);
while (i != 0) {
- Edge arg=getVectorEdge(&cnf->args, --i);
- Node *narg=getNodePtrFromEdge(arg);
+ Edge arg = getVectorEdge(&cnf->args, --i);
+ Node *narg = getNodePtrFromEdge(arg);
if (edgeIsVarConst(arg)) {
disjoinCNFLit(accum, getEdgeVar(arg));
} else {
- CNFExpr* argExp = (CNFExpr*) narg->ptrAnnot[isNegEdge(arg)];
-
+ CNFExpr *argExp = (CNFExpr *) narg->ptrAnnot[isNegEdge(arg)];
+
bool destroy = (--narg->intAnnot[isNegEdge(arg)] == 0);
- if (isProxy(argExp)) { // variable has been introduced
+ if (isProxy(argExp)) {// variable has been introduced
disjoinCNFLit(accum, getProxy(argExp));
} else if (argExp->litSize == 0) {
disjoinCNFExpr(accum, argExp, destroy);
} else {
// check to see if we should introduce a proxy
- int aL = accum->litSize; // lits in accum
- int eL = argExp->litSize; // lits in argument
- int aC = getClauseSizeCNF(accum); // clauses in accum
- int eC = getClauseSizeCNF(argExp); // clauses in argument
-
+ int aL = accum->litSize; // lits in accum
+ int eL = argExp->litSize; // lits in argument
+ int aC = getClauseSizeCNF(accum); // clauses in accum
+ int eC = getClauseSizeCNF(argExp); // clauses in argument
+
if (eC > CLAUSE_MAX || (eL * aC + aL * eC > eL + aC + aL + aC)) {
disjoinCNFLit(accum, introProxy(cnf, arg, argExp, isNegEdge(arg)));
} else {
}
}
}
-
+
return accum;
}
-Edge generateBinaryConstraint(CNF *cnf, uint numvars, Edge * vars, uint value) {
+Edge generateBinaryConstraint(CNF *cnf, uint numvars, Edge *vars, uint value) {
Edge carray[numvars];
- for(uint j=0;j<numvars;j++) {
- carray[j]=((value&1)==1) ? vars[j] : constraintNegate(vars[j]);
- value=value>>1;
+ for (uint j = 0; j < numvars; j++) {
+ carray[j] = ((value & 1) == 1) ? vars[j] : constraintNegate(vars[j]);
+ value = value >> 1;
}
-
+
return constraintAND(cnf, numvars, carray);
}
-
+
/** Generates a constraint to ensure that all encodings are less than value */
-Edge generateLTConstraint(CNF *cnf, uint numvars, Edge * vars, uint value) {
+Edge generateLTConstraint(CNF *cnf, uint numvars, Edge *vars, uint value) {
Edge orarray[numvars];
Edge andarray[numvars];
- uint andi=0;
-
- while(true) {
- uint val=value;
- uint ori=0;
- for(uint j=0;j<numvars;j++) {
- if ((val&1)==1)
- orarray[ori++]=constraintNegate(vars[j]);
- val=val>>1;
+ uint andi = 0;
+
+ while (true) {
+ uint val = value;
+ uint ori = 0;
+ for (uint j = 0; j < numvars; j++) {
+ if ((val & 1) == 1)
+ orarray[ori++] = constraintNegate(vars[j]);
+ val = val >> 1;
}
//no ones to flip, so bail now...
- if (ori==0) {
+ if (ori == 0) {
return constraintAND(cnf, andi, andarray);
}
- andarray[andi++]=constraintOR(cnf, ori, orarray);
-
- value=value+(1<<(__builtin_ctz(value)));
+ andarray[andi++] = constraintOR(cnf, ori, orarray);
+
+ value = value + (1 << (__builtin_ctz(value)));
//flip the last one
}
}
-
+
Edge generateEquivNVConstraint(CNF *cnf, uint numvars, Edge *var1, Edge *var2) {
- if (numvars==0)
+ if (numvars == 0)
return E_True;
Edge array[numvars];
- for(uint i=0;i<numvars;i++) {
- array[i]=constraintIFF(cnf, var1[i], var2[i]);
+ for (uint i = 0; i < numvars; i++) {
+ array[i] = constraintIFF(cnf, var1[i], var2[i]);
}
return constraintAND(cnf, numvars, array);
}
typedef struct Node Node;
struct Edge {
- Node * node_ptr;
+ Node *node_ptr;
};
VectorDef(Edge, Edge)
typedef enum NodeType NodeType;
struct NodeFlags {
- NodeType type:2;
- int varForced:1;
- int wasExpanded:2;
- int cnfVisitedDown:2;
- int cnfVisitedUp:2;
+ NodeType type : 2;
+ int varForced : 1;
+ int wasExpanded : 2;
+ int cnfVisitedDown : 2;
+ int cnfVisitedUp : 2;
};
typedef struct NodeFlags NodeFlags;
uint numEdges;
uint hashCode;
uint intAnnot[2];
- void * ptrAnnot[2];
+ void *ptrAnnot[2];
Edge edges[];
};
uint mask;
uint maxsize;
bool enableMatching;
- Node ** node_array;
- IncrementalSolver * solver;
+ Node **node_array;
+ IncrementalSolver *solver;
VectorEdge constraints;
VectorEdge args;
};
typedef struct CNFExpr CNFExpr;
static inline bool getExpanded(Node *n, int isNegated) {
- return n->flags.wasExpanded & (1<<isNegated);
+ return n->flags.wasExpanded & (1 << isNegated);
}
static inline void setExpanded(Node *n, int isNegated) {
- n->flags.wasExpanded |= (1<<isNegated);
+ n->flags.wasExpanded |= (1 << isNegated);
}
static inline Edge constraintNegate(Edge e) {
}
static inline bool sameNodeVarEdge(Edge e1, Edge e2) {
- return ! (((uintptr_t) e1.node_ptr ^ (uintptr_t) e2.node_ptr) & (~ (uintptr_t) NEGATE_EDGE));
+ return !(((uintptr_t) e1.node_ptr ^ (uintptr_t) e2.node_ptr) & (~(uintptr_t) NEGATE_EDGE));
}
static inline bool sameSignEdge(Edge e1, Edge e2) {
return (((uintptr_t) e.node_ptr) & (NEGATE_EDGE | EDGE_IS_VAR_CONSTANT)) == NEGATE_EDGE;
}
-static inline Node * getNodePtrFromEdge(Edge e) {
+static inline Node *getNodePtrFromEdge(Edge e) {
return (Node *) (((uintptr_t) e.node_ptr) & ~((uintptr_t) EDGE_MASK));
}
static inline NodeType getNodeType(Edge e) {
- Node * n=getNodePtrFromEdge(e);
+ Node *n = getNodePtrFromEdge(e);
return n->flags.type;
}
}
static inline uint getNodeSize(Edge e) {
- Node * n=getNodePtrFromEdge(e);
+ Node *n = getNodePtrFromEdge(e);
return n->numEdges;
}
-static inline Edge * getEdgeArray(Edge e) {
- Node * n=getNodePtrFromEdge(e);
+static inline Edge *getEdgeArray(Edge e) {
+ Node *n = getNodePtrFromEdge(e);
return n->edges;
}
static inline Edge getNonNeg(Edge e) {
- Edge enew={(Node *)(((uintptr_t)e.node_ptr)&(~((uintptr_t)NEGATE_EDGE)))};
+ Edge enew = {(Node *)(((uintptr_t)e.node_ptr) & (~((uintptr_t)NEGATE_EDGE)))};
return enew;
}
}
static inline Edge constraintNegateIf(Edge e, bool negate) {
- Edge eret={(Node *)(((uintptr_t)e.node_ptr) ^ negate)};
+ Edge eret = {(Node *)(((uintptr_t)e.node_ptr) ^ negate)};
return eret;
}
return (Literal) (((intptr_t) expr) >> 1);
}
-CNF * createCNF();
-void deleteCNF(CNF * cnf);
+CNF *createCNF();
+void deleteCNF(CNF *cnf);
-uint hashNode(NodeType type, uint numEdges, Edge * edges);
-Node * allocNode(NodeType type, uint numEdges, Edge * edges, uint hashCode);
-bool compareNodes(Node * node, NodeType type, uint numEdges, Edge *edges);
-Edge create(CNF *cnf, NodeType type, uint numEdges, Edge * edges);
-Edge constraintOR(CNF * cnf, uint numEdges, Edge *edges);
-Edge constraintAND(CNF * cnf, uint numEdges, Edge * edges);
-Edge constraintOR2(CNF * cnf, Edge left, Edge right);
-Edge constraintAND2(CNF * cnf, Edge left, Edge right);
-Edge constraintIMPLIES(CNF * cnf, Edge left, Edge right);
-Edge constraintIFF(CNF * cnf, Edge left, Edge right);
+uint hashNode(NodeType type, uint numEdges, Edge *edges);
+Node *allocNode(NodeType type, uint numEdges, Edge *edges, uint hashCode);
+bool compareNodes(Node *node, NodeType type, uint numEdges, Edge *edges);
+Edge create(CNF *cnf, NodeType type, uint numEdges, Edge *edges);
+Edge constraintOR(CNF *cnf, uint numEdges, Edge *edges);
+Edge constraintAND(CNF *cnf, uint numEdges, Edge *edges);
+Edge constraintOR2(CNF *cnf, Edge left, Edge right);
+Edge constraintAND2(CNF *cnf, Edge left, Edge right);
+Edge constraintIMPLIES(CNF *cnf, Edge left, Edge right);
+Edge constraintIFF(CNF *cnf, Edge left, Edge right);
static inline Edge constraintXOR(CNF *cnf, Edge left, Edge right) {return constraintNegate(constraintIFF(cnf, left,right));}
-Edge constraintITE(CNF * cnf, Edge cond, Edge thenedge, Edge elseedge);
+Edge constraintITE(CNF *cnf, Edge cond, Edge thenedge, Edge elseedge);
Edge constraintNewVar(CNF *cnf);
void countPass(CNF *cnf);
-void countConstraint(CNF *cnf, VectorEdge * stack, Edge e);
+void countConstraint(CNF *cnf, VectorEdge *stack, Edge e);
void addConstraintCNF(CNF *cnf, Edge constraint);
int solveCNF(CNF *cnf);
bool getValueCNF(CNF *cnf, Edge var);
void convertPass(CNF *cnf, bool backtrackLit);
void convertConstraint(CNF *cnf, VectorEdge *stack, Edge e, bool backtrackLit);
-void constrainCNF(CNF * cnf, Literal l, CNFExpr *exp);
-void produceCNF(CNF * cnf, Edge e);
-CNFExpr * produceConjunction(CNF * cnf, Edge e);
-CNFExpr* produceDisjunction(CNF *cnf, Edge e);
-bool propagate(CNF *cnf, CNFExpr ** dest, CNFExpr * src, bool negate);
-void saveCNF(CNF *cnf, CNFExpr* exp, Edge e, bool sign);
-CNFExpr* fillArgs(CNF * cnf, Edge e, bool isNeg, Edge * largestEdge);
-Literal introProxy(CNF * cnf, Edge e, CNFExpr* exp, bool isNeg);
+void constrainCNF(CNF *cnf, Literal l, CNFExpr *exp);
+void produceCNF(CNF *cnf, Edge e);
+CNFExpr *produceConjunction(CNF *cnf, Edge e);
+CNFExpr *produceDisjunction(CNF *cnf, Edge e);
+bool propagate(CNF *cnf, CNFExpr **dest, CNFExpr *src, bool negate);
+void saveCNF(CNF *cnf, CNFExpr *exp, Edge e, bool sign);
+CNFExpr *fillArgs(CNF *cnf, Edge e, bool isNeg, Edge *largestEdge);
+Literal introProxy(CNF *cnf, Edge e, CNFExpr *exp, bool isNeg);
void outputCNF(CNF *cnf, CNFExpr *expr);
-Edge generateBinaryConstraint(CNF *cnf, uint numvars, Edge * vars, uint value);
-Edge generateLTConstraint(CNF *cnf, uint numvars, Edge * vars, uint value);
+Edge generateBinaryConstraint(CNF *cnf, uint numvars, Edge *vars, uint value);
+Edge generateLTConstraint(CNF *cnf, uint numvars, Edge *vars, uint value);
Edge generateEquivNVConstraint(CNF *cnf, uint numvars, Edge *var1, Edge *var2);
extern Edge E_True;
#include "common.h"
#include <string.h>
-IncrementalSolver * allocIncrementalSolver() {
- IncrementalSolver *This=(IncrementalSolver *)ourmalloc(sizeof(IncrementalSolver));
- This->buffer=((int *)ourmalloc(sizeof(int)*IS_BUFFERSIZE));
- This->solution=NULL;
- This->solutionsize=0;
- This->offset=0;
+IncrementalSolver *allocIncrementalSolver() {
+ IncrementalSolver *This = (IncrementalSolver *)ourmalloc(sizeof(IncrementalSolver));
+ This->buffer = ((int *)ourmalloc(sizeof(int) * IS_BUFFERSIZE));
+ This->solution = NULL;
+ This->solutionsize = 0;
+ This->offset = 0;
createSolver(This);
return This;
}
-void deleteIncrementalSolver(IncrementalSolver * This) {
+void deleteIncrementalSolver(IncrementalSolver *This) {
killSolver(This);
ourfree(This->buffer);
if (This->solution != NULL)
ourfree(This);
}
-void resetSolver(IncrementalSolver * This) {
+void resetSolver(IncrementalSolver *This) {
killSolver(This);
This->offset = 0;
createSolver(This);
}
-void addClauseLiteral(IncrementalSolver * This, int literal) {
- This->buffer[This->offset++]=literal;
- if (This->offset==IS_BUFFERSIZE) {
+void addClauseLiteral(IncrementalSolver *This, int literal) {
+ This->buffer[This->offset++] = literal;
+ if (This->offset == IS_BUFFERSIZE) {
flushBufferSolver(This);
}
}
-void addArrayClauseLiteral(IncrementalSolver * This, uint numliterals, int * literals) {
- uint index=0;
- while(true) {
- uint bufferspace=IS_BUFFERSIZE-This->offset;
- uint numtowrite=numliterals-index;
+void addArrayClauseLiteral(IncrementalSolver *This, uint numliterals, int *literals) {
+ 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
+ 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;
+ memcpy(&This->buffer[This->offset], &literals[index], bufferspace * sizeof(int));
+ This->offset += bufferspace;
+ index += bufferspace;
flushBufferSolver(This);
}
}
}
-void finishedClauses(IncrementalSolver * This) {
+void finishedClauses(IncrementalSolver *This) {
addClauseLiteral(This, 0);
}
-void freeze(IncrementalSolver * This, int variable) {
+void freeze(IncrementalSolver *This, int variable) {
addClauseLiteral(This, IS_FREEZE);
addClauseLiteral(This, variable);
}
-int solve(IncrementalSolver * This) {
+int solve(IncrementalSolver *This) {
//add an empty clause
startSolve(This);
return getSolution(This);
flushBufferSolver(This);
}
-int getSolution(IncrementalSolver * This) {
- int result=readIntSolver(This);
+int getSolution(IncrementalSolver *This) {
+ int result = readIntSolver(This);
if (result == IS_SAT) {
- int numVars=readIntSolver(This);
+ int numVars = readIntSolver(This);
if (numVars > This->solutionsize) {
if (This->solution != NULL)
ourfree(This->solution);
- This->solution = (int *) ourmalloc((numVars+1)*sizeof(int));
+ This->solution = (int *) ourmalloc((numVars + 1) * sizeof(int));
This->solution[0] = 0;
}
readSolver(This, &This->solution[1], numVars * sizeof(int));
return result;
}
-int readIntSolver(IncrementalSolver * This) {
+int readIntSolver(IncrementalSolver *This) {
int value;
readSolver(This, &value, 4);
return value;
}
-void readSolver(IncrementalSolver * This, void * tmp, ssize_t size) {
+void readSolver(IncrementalSolver *This, void *tmp, ssize_t size) {
char *result = (char *) tmp;
- ssize_t bytestoread=size;
- ssize_t bytesread=0;
+ ssize_t bytestoread = size;
+ ssize_t bytesread = 0;
do {
- ssize_t n=read(This->from_solver_fd, &((char *)result)[bytesread], bytestoread);
+ ssize_t n = read(This->from_solver_fd, &((char *)result)[bytesread], bytestoread);
if (n == -1) {
model_print("Read failure\n");
exit(-1);
}
bytestoread -= n;
bytesread += n;
- } while(bytestoread != 0);
+ } while (bytestoread != 0);
}
-bool getValueSolver(IncrementalSolver * This, int variable) {
+bool getValueSolver(IncrementalSolver *This, int variable) {
return This->solution[variable];
}
-void createSolver(IncrementalSolver * This) {
+void createSolver(IncrementalSolver *This) {
int to_pipe[2];
int from_pipe[2];
if (pipe(to_pipe) || pipe(from_pipe)) {
//Solver process
close(to_pipe[1]);
close(from_pipe[0]);
- int fd=open("log_file", O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
+ int fd = open("log_file", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
if ((dup2(to_pipe[0], 0) == -1) ||
(dup2(from_pipe[1], IS_OUT_FD) == -1) ||
}
}
-void killSolver(IncrementalSolver * This) {
+void killSolver(IncrementalSolver *This) {
close(This->to_solver_fd);
close(This->from_solver_fd);
//Stop the solver
}
//DEBUGGING CODE STARTS
-bool first=true;
+bool first = true;
//DEBUGGING CODE ENDS
-void flushBufferSolver(IncrementalSolver * This) {
- ssize_t bytestowrite=sizeof(int)*This->offset;
- ssize_t byteswritten=0;
+void flushBufferSolver(IncrementalSolver *This) {
+ ssize_t bytestowrite = sizeof(int) * This->offset;
+ ssize_t byteswritten = 0;
//DEBUGGING CODE STARTS
- for(uint i=0;i<This->offset;i++) {
+ for (uint i = 0; i < This->offset; i++) {
if (first)
printf("(");
- if (This->buffer[i]==0) {
+ if (This->buffer[i] == 0) {
printf(")\n");
- first=true;
+ first = true;
} else {
if (!first)
printf(" + ");
- first=false;
+ first = false;
printf("%d", This->buffer[i]);
}
}
//DEBUGGING CODE ENDS
do {
- ssize_t n=write(This->to_solver_fd, &((char *)This->buffer)[byteswritten], bytestowrite);
+ ssize_t n = write(This->to_solver_fd, &((char *)This->buffer)[byteswritten], bytestowrite);
if (n == -1) {
perror("Write failure\n");
model_print("to_solver_fd=%d\n",This->to_solver_fd);
}
bytestowrite -= n;
byteswritten += n;
- } while(bytestowrite != 0);
+ } while (bytestowrite != 0);
This->offset = 0;
}
#include "classlist.h"
struct IncrementalSolver {
- int * buffer;
- int * solution;
+ int *buffer;
+ int *solution;
int solutionsize;
int offset;
pid_t solver_pid;
int from_solver_fd;
};
-IncrementalSolver * allocIncrementalSolver();
-void deleteIncrementalSolver(IncrementalSolver * This);
-void addClauseLiteral(IncrementalSolver * This, int literal);
-void addArrayClauseLiteral(IncrementalSolver * This, uint numliterals, int * literals);
-void finishedClauses(IncrementalSolver * This);
-void freeze(IncrementalSolver * This, int variable);
-int solve(IncrementalSolver * This);
-void startSolve(IncrementalSolver * This);
-int getSolution(IncrementalSolver * This);
-bool getValueSolver(IncrementalSolver * This, int variable);
-void resetSolver(IncrementalSolver * This);
-void createSolver(IncrementalSolver * This);
-void killSolver(IncrementalSolver * This);
-void flushBufferSolver(IncrementalSolver * This);
-int readIntSolver(IncrementalSolver * This);
-void readSolver(IncrementalSolver * This, void * buffer, ssize_t size);
+IncrementalSolver *allocIncrementalSolver();
+void deleteIncrementalSolver(IncrementalSolver *This);
+void addClauseLiteral(IncrementalSolver *This, int literal);
+void addArrayClauseLiteral(IncrementalSolver *This, uint numliterals, int *literals);
+void finishedClauses(IncrementalSolver *This);
+void freeze(IncrementalSolver *This, int variable);
+int solve(IncrementalSolver *This);
+void startSolve(IncrementalSolver *This);
+int getSolution(IncrementalSolver *This);
+bool getValueSolver(IncrementalSolver *This, int variable);
+void resetSolver(IncrementalSolver *This);
+void createSolver(IncrementalSolver *This);
+void killSolver(IncrementalSolver *This);
+void flushBufferSolver(IncrementalSolver *This);
+int readIntSolver(IncrementalSolver *This);
+void readSolver(IncrementalSolver *This, void *buffer, ssize_t size);
#endif
#include "orderpair.h"
-OrderPair* allocOrderPair(uint64_t first, uint64_t second, Edge constraint){
- OrderPair* pair = (OrderPair*) ourmalloc(sizeof(OrderPair));
+OrderPair *allocOrderPair(uint64_t first, uint64_t second, Edge constraint) {
+ OrderPair *pair = (OrderPair *) ourmalloc(sizeof(OrderPair));
pair->first = first;
pair->second = second;
pair->constraint = constraint;
return pair;
}
-void deleteOrderPair(OrderPair* pair){
+void deleteOrderPair(OrderPair *pair) {
ourfree(pair);
}
-/*
+/*
* File: orderpair.h
* Author: hamed
*
#include "mymemory.h"
#include "constraint.h"
-struct OrderPair{
+struct OrderPair {
uint64_t first;
uint64_t second;
Edge constraint;
-};
+};
-OrderPair* allocOrderPair(uint64_t first, uint64_t second, Edge constraint);
-void deleteOrderPair(OrderPair* pair);
+OrderPair *allocOrderPair(uint64_t first, uint64_t second, Edge constraint);
+void deleteOrderPair(OrderPair *pair);
-#endif /* ORDERPAIR_H */
+#endif/* ORDERPAIR_H */
#include "element.h"
#include "set.h"
-Edge getElementValueConstraint(SATEncoder* This, Element* elem, uint64_t value) {
- switch(getElementEncoding(elem)->type){
- case ONEHOT:
- return getElementValueOneHotConstraint(This, elem, value);
- case UNARY:
- return getElementValueUnaryConstraint(This, elem, value);
- case BINARYINDEX:
- return getElementValueBinaryIndexConstraint(This, elem, value);
- case ONEHOTBINARY:
- ASSERT(0);
- break;
- case BINARYVAL:
- return getElementValueBinaryValueConstraint(This, elem, value);
- break;
- default:
- ASSERT(0);
- break;
+Edge getElementValueConstraint(SATEncoder *This, Element *elem, uint64_t value) {
+ switch (getElementEncoding(elem)->type) {
+ case ONEHOT:
+ return getElementValueOneHotConstraint(This, elem, value);
+ case UNARY:
+ return getElementValueUnaryConstraint(This, elem, value);
+ case BINARYINDEX:
+ return getElementValueBinaryIndexConstraint(This, elem, value);
+ case ONEHOTBINARY:
+ ASSERT(0);
+ break;
+ case BINARYVAL:
+ return getElementValueBinaryValueConstraint(This, elem, value);
+ break;
+ default:
+ ASSERT(0);
+ break;
}
return E_BOGUS;
}
-Edge getElementValueBinaryIndexConstraint(SATEncoder * This, Element* elem, uint64_t value) {
+Edge getElementValueBinaryIndexConstraint(SATEncoder *This, Element *elem, uint64_t value) {
ASTNodeType type = GETELEMENTTYPE(elem);
ASSERT(type == ELEMSET || type == ELEMFUNCRETURN || type == ELEMCONST);
- ElementEncoding* elemEnc = getElementEncoding(elem);
- for(uint i=0; i<elemEnc->encArraySize; i++){
- if(isinUseElement(elemEnc, i) && elemEnc->encodingArray[i]==value) {
- return (elemEnc->numVars == 0) ? E_True: generateBinaryConstraint(This->cnf, elemEnc->numVars, elemEnc->variables, i);
+ ElementEncoding *elemEnc = getElementEncoding(elem);
+ for (uint i = 0; i < elemEnc->encArraySize; i++) {
+ if (isinUseElement(elemEnc, i) && elemEnc->encodingArray[i] == value) {
+ return (elemEnc->numVars == 0) ? E_True : generateBinaryConstraint(This->cnf, elemEnc->numVars, elemEnc->variables, i);
}
}
return E_False;
}
-Edge getElementValueOneHotConstraint(SATEncoder * This, Element* elem, uint64_t value) {
+Edge getElementValueOneHotConstraint(SATEncoder *This, Element *elem, uint64_t value) {
ASTNodeType type = GETELEMENTTYPE(elem);
ASSERT(type == ELEMSET || type == ELEMFUNCRETURN || type == ELEMCONST);
- ElementEncoding* elemEnc = getElementEncoding(elem);
- for(uint i=0; i<elemEnc->encArraySize; i++){
- if (isinUseElement(elemEnc, i) && elemEnc->encodingArray[i]==value) {
- return (elemEnc->numVars == 0) ? E_True: elemEnc->variables[i];
+ ElementEncoding *elemEnc = getElementEncoding(elem);
+ for (uint i = 0; i < elemEnc->encArraySize; i++) {
+ if (isinUseElement(elemEnc, i) && elemEnc->encodingArray[i] == value) {
+ return (elemEnc->numVars == 0) ? E_True : elemEnc->variables[i];
}
}
return E_False;
}
-Edge getElementValueUnaryConstraint(SATEncoder * This, Element* elem, uint64_t value) {
+Edge getElementValueUnaryConstraint(SATEncoder *This, Element *elem, uint64_t value) {
ASTNodeType type = GETELEMENTTYPE(elem);
ASSERT(type == ELEMSET || type == ELEMFUNCRETURN || type == ELEMCONST);
- ElementEncoding* elemEnc = getElementEncoding(elem);
- for(uint i=0; i<elemEnc->encArraySize; i++){
- if (isinUseElement(elemEnc, i) && elemEnc->encodingArray[i]==value) {
- if(elemEnc->numVars == 0)
+ ElementEncoding *elemEnc = getElementEncoding(elem);
+ for (uint i = 0; i < elemEnc->encArraySize; i++) {
+ if (isinUseElement(elemEnc, i) && elemEnc->encodingArray[i] == value) {
+ if (elemEnc->numVars == 0)
return E_True;
- if (i==0)
+ if (i == 0)
return constraintNegate(elemEnc->variables[0]);
- else if ((i+1)==elemEnc->encArraySize)
- return elemEnc->variables[i-1];
+ else if ((i + 1) == elemEnc->encArraySize)
+ return elemEnc->variables[i - 1];
else
- return constraintAND2(This->cnf, elemEnc->variables[i-1], constraintNegate(elemEnc->variables[i]));
+ return constraintAND2(This->cnf, elemEnc->variables[i - 1], constraintNegate(elemEnc->variables[i]));
}
}
return E_False;
}
-Edge getElementValueBinaryValueConstraint(SATEncoder * This, Element* element, uint64_t value){
+Edge getElementValueBinaryValueConstraint(SATEncoder *This, Element *element, uint64_t value) {
ASTNodeType type = GETELEMENTTYPE(element);
ASSERT(type == ELEMSET || type == ELEMFUNCRETURN);
- ElementEncoding* elemEnc = getElementEncoding(element);
+ ElementEncoding *elemEnc = getElementEncoding(element);
if (elemEnc->low <= elemEnc->high) {
if (value < elemEnc->low || value > elemEnc->high)
return E_False;
if (value < elemEnc->low && value > elemEnc->high)
return E_False;
}
-
- uint64_t valueminusoffset=value-elemEnc->offset;
+
+ uint64_t valueminusoffset = value - elemEnc->offset;
return generateBinaryConstraint(This->cnf, elemEnc->numVars, elemEnc->variables, valueminusoffset);
}
-void allocElementConstraintVariables(ElementEncoding* This, uint numVars) {
+void allocElementConstraintVariables(ElementEncoding *This, uint numVars) {
This->numVars = numVars;
This->variables = ourmalloc(sizeof(Edge) * numVars);
}
-void generateBinaryValueEncodingVars(SATEncoder* This, ElementEncoding* encoding){
- ASSERT(encoding->type==BINARYVAL);
+void generateBinaryValueEncodingVars(SATEncoder *This, ElementEncoding *encoding) {
+ ASSERT(encoding->type == BINARYVAL);
allocElementConstraintVariables(encoding, encoding->numBits);
getArrayNewVarsSATEncoder(This, encoding->numVars, encoding->variables);
}
void generateBinaryIndexEncodingVars(SATEncoder *This, ElementEncoding *encoding) {
- ASSERT(encoding->type==BINARYINDEX);
- allocElementConstraintVariables(encoding, NUMBITS(encoding->encArraySize-1));
+ ASSERT(encoding->type == BINARYINDEX);
+ allocElementConstraintVariables(encoding, NUMBITS(encoding->encArraySize - 1));
getArrayNewVarsSATEncoder(This, encoding->numVars, encoding->variables);
}
void generateOneHotEncodingVars(SATEncoder *This, ElementEncoding *encoding) {
allocElementConstraintVariables(encoding, encoding->encArraySize);
- getArrayNewVarsSATEncoder(This, encoding->numVars, encoding->variables);
- for(uint i=0;i<encoding->numVars;i++) {
- for(uint j=i+1;j<encoding->numVars;j++) {
+ getArrayNewVarsSATEncoder(This, encoding->numVars, encoding->variables);
+ for (uint i = 0; i < encoding->numVars; i++) {
+ for (uint j = i + 1; j < encoding->numVars; j++) {
addConstraintCNF(This->cnf, constraintNegate(constraintAND2(This->cnf, encoding->variables[i], encoding->variables[j])));
}
}
}
void generateUnaryEncodingVars(SATEncoder *This, ElementEncoding *encoding) {
- allocElementConstraintVariables(encoding, encoding->encArraySize-1);
- getArrayNewVarsSATEncoder(This, encoding->numVars, encoding->variables);
+ allocElementConstraintVariables(encoding, encoding->encArraySize - 1);
+ getArrayNewVarsSATEncoder(This, encoding->numVars, encoding->variables);
//Add unary constraint
- for(uint i=1;i<encoding->numVars;i++) {
- addConstraintCNF(This->cnf, constraintOR2(This->cnf, encoding->variables[i-1], constraintNegate(encoding->variables[i])));
+ for (uint i = 1; i < encoding->numVars; i++) {
+ addConstraintCNF(This->cnf, constraintOR2(This->cnf, encoding->variables[i - 1], constraintNegate(encoding->variables[i])));
}
}
-void generateElementEncoding(SATEncoder* This, Element * element) {
- ElementEncoding* encoding = getElementEncoding(element);
- ASSERT(encoding->type!=ELEM_UNASSIGNED);
- if(encoding->variables!=NULL)
+void generateElementEncoding(SATEncoder *This, Element *element) {
+ ElementEncoding *encoding = getElementEncoding(element);
+ ASSERT(encoding->type != ELEM_UNASSIGNED);
+ if (encoding->variables != NULL)
return;
- switch(encoding->type) {
+ switch (encoding->type) {
case ONEHOT:
generateOneHotEncodingVars(This, encoding);
return;
#ifndef SATELEMENTENCODER_H
#define SATELEMENTENCODER_H
-Edge getElementValueOneHotConstraint(SATEncoder * This, Element* elem, uint64_t value);
-Edge getElementValueUnaryConstraint(SATEncoder * This, Element* elem, uint64_t value);
-Edge getElementValueBinaryIndexConstraint(SATEncoder * This, Element* element, uint64_t value);
-Edge getElementValueBinaryValueConstraint(SATEncoder * This, Element* element, uint64_t value);
-Edge getElementValueConstraint(SATEncoder* encoder, Element* This, uint64_t value);
-void allocElementConstraintVariables(ElementEncoding* This, uint numVars);
+Edge getElementValueOneHotConstraint(SATEncoder *This, Element *elem, uint64_t value);
+Edge getElementValueUnaryConstraint(SATEncoder *This, Element *elem, uint64_t value);
+Edge getElementValueBinaryIndexConstraint(SATEncoder *This, Element *element, uint64_t value);
+Edge getElementValueBinaryValueConstraint(SATEncoder *This, Element *element, uint64_t value);
+Edge getElementValueConstraint(SATEncoder *encoder, Element *This, uint64_t value);
+void allocElementConstraintVariables(ElementEncoding *This, uint numVars);
void generateOneHotEncodingVars(SATEncoder *This, ElementEncoding *encoding);
void generateUnaryEncodingVars(SATEncoder *This, ElementEncoding *encoding);
-void generateBinaryIndexEncodingVars(SATEncoder* This, ElementEncoding* encoding);
-void generateBinaryValueEncodingVars(SATEncoder* This, ElementEncoding* encoding);
-void generateElementEncoding(SATEncoder* This, Element* element);
+void generateBinaryIndexEncodingVars(SATEncoder *This, ElementEncoding *encoding);
+void generateBinaryValueEncodingVars(SATEncoder *This, ElementEncoding *encoding);
+void generateElementEncoding(SATEncoder *This, Element *element);
#endif
//TODO: Should handle sharing of AST Nodes without recoding them a second time
-SATEncoder * allocSATEncoder() {
- SATEncoder *This=ourmalloc(sizeof (SATEncoder));
- This->varcount=1;
- This->cnf=createCNF();
+SATEncoder *allocSATEncoder() {
+ SATEncoder *This = ourmalloc(sizeof (SATEncoder));
+ This->varcount = 1;
+ This->cnf = createCNF();
return This;
}
ourfree(This);
}
-void encodeAllSATEncoder(CSolver *csolver, SATEncoder * This) {
- VectorBoolean *constraints=csolver->constraints;
- uint size=getSizeVectorBoolean(constraints);
- for(uint i=0;i<size;i++) {
+void encodeAllSATEncoder(CSolver *csolver, SATEncoder *This) {
+ VectorBoolean *constraints = csolver->constraints;
+ uint size = getSizeVectorBoolean(constraints);
+ for (uint i = 0; i < size; i++) {
model_print("Encoding All ...\n\n");
- Boolean *constraint=getVectorBoolean(constraints, i);
- Edge c= encodeConstraintSATEncoder(This, constraint);
+ Boolean *constraint = getVectorBoolean(constraints, i);
+ Edge c = encodeConstraintSATEncoder(This, constraint);
model_print("Returned Constraint in EncodingAll:\n");
addConstraintCNF(This->cnf, c);
}
}
Edge encodeConstraintSATEncoder(SATEncoder *This, Boolean *constraint) {
- switch(GETBOOLEANTYPE(constraint)) {
+ switch (GETBOOLEANTYPE(constraint)) {
case ORDERCONST:
return encodeOrderSATEncoder(This, (BooleanOrder *) constraint);
case BOOLEANVAR:
}
}
-void getArrayNewVarsSATEncoder(SATEncoder* encoder, uint num, Edge * carray) {
- for(uint i=0;i<num;i++)
- carray[i]=getNewVarSATEncoder(encoder);
+void getArrayNewVarsSATEncoder(SATEncoder *encoder, uint num, Edge *carray) {
+ for (uint i = 0; i < num; i++)
+ carray[i] = getNewVarSATEncoder(encoder);
}
Edge getNewVarSATEncoder(SATEncoder *This) {
return constraintNewVar(This->cnf);
}
-Edge encodeVarSATEncoder(SATEncoder *This, BooleanVar * constraint) {
+Edge encodeVarSATEncoder(SATEncoder *This, BooleanVar *constraint) {
if (edgeIsNull(constraint->var)) {
- constraint->var=getNewVarSATEncoder(This);
+ constraint->var = getNewVarSATEncoder(This);
}
return constraint->var;
}
-Edge encodeLogicSATEncoder(SATEncoder *This, BooleanLogic * constraint) {
+Edge encodeLogicSATEncoder(SATEncoder *This, BooleanLogic *constraint) {
Edge array[getSizeArrayBoolean(&constraint->inputs)];
- for(uint i=0;i<getSizeArrayBoolean(&constraint->inputs);i++)
- array[i]=encodeConstraintSATEncoder(This, getArrayBoolean(&constraint->inputs, i));
+ for (uint i = 0; i < getSizeArrayBoolean(&constraint->inputs); i++)
+ array[i] = encodeConstraintSATEncoder(This, getArrayBoolean(&constraint->inputs, i));
- switch(constraint->op) {
+ switch (constraint->op) {
case L_AND:
return constraintAND(This->cnf, getSizeArrayBoolean(&constraint->inputs), array);
case L_OR:
return constraintOR(This->cnf, getSizeArrayBoolean(&constraint->inputs), array);
case L_NOT:
- ASSERT( getSizeArrayBoolean(&constraint->inputs)==1);
+ ASSERT( getSizeArrayBoolean(&constraint->inputs) == 1);
return constraintNegate(array[0]);
case L_XOR:
- ASSERT( getSizeArrayBoolean(&constraint->inputs)==2);
+ ASSERT( getSizeArrayBoolean(&constraint->inputs) == 2);
return constraintXOR(This->cnf, array[0], array[1]);
case L_IMPLIES:
- ASSERT( getSizeArrayBoolean( &constraint->inputs)==2);
+ ASSERT( getSizeArrayBoolean( &constraint->inputs) == 2);
return constraintIMPLIES(This->cnf, array[0], array[1]);
default:
model_print("Unhandled case in encodeLogicSATEncoder %u", constraint->op);
}
}
-Edge encodePredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint) {
- switch(GETPREDICATETYPE(constraint->predicate) ){
- case TABLEPRED:
- return encodeTablePredicateSATEncoder(This, constraint);
- case OPERATORPRED:
- return encodeOperatorPredicateSATEncoder(This, constraint);
- default:
- ASSERT(0);
+Edge encodePredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint) {
+ switch (GETPREDICATETYPE(constraint->predicate) ) {
+ case TABLEPRED:
+ return encodeTablePredicateSATEncoder(This, constraint);
+ case OPERATORPRED:
+ return encodeOperatorPredicateSATEncoder(This, constraint);
+ default:
+ ASSERT(0);
}
return E_BOGUS;
}
-Edge encodeTablePredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint){
- switch(constraint->encoding.type){
- case ENUMERATEIMPLICATIONS:
- case ENUMERATEIMPLICATIONSNEGATE:
- return encodeEnumTablePredicateSATEncoder(This, constraint);
- case CIRCUIT:
- ASSERT(0);
- break;
- default:
- ASSERT(0);
+Edge encodeTablePredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint) {
+ switch (constraint->encoding.type) {
+ case ENUMERATEIMPLICATIONS:
+ case ENUMERATEIMPLICATIONSNEGATE:
+ return encodeEnumTablePredicateSATEncoder(This, constraint);
+ case CIRCUIT:
+ ASSERT(0);
+ break;
+ default:
+ ASSERT(0);
}
return E_BOGUS;
}
-void encodeElementSATEncoder(SATEncoder* encoder, Element *This){
- switch( GETELEMENTTYPE(This) ){
- case ELEMFUNCRETURN:
- generateElementEncoding(encoder, This);
- encodeElementFunctionSATEncoder(encoder, (ElementFunction*) This);
- break;
- case ELEMSET:
- generateElementEncoding(encoder, This);
- return;
- case ELEMCONST:
- return;
- default:
- ASSERT(0);
+void encodeElementSATEncoder(SATEncoder *encoder, Element *This) {
+ switch ( GETELEMENTTYPE(This) ) {
+ case ELEMFUNCRETURN:
+ generateElementEncoding(encoder, This);
+ encodeElementFunctionSATEncoder(encoder, (ElementFunction *) This);
+ break;
+ case ELEMSET:
+ generateElementEncoding(encoder, This);
+ return;
+ case ELEMCONST:
+ return;
+ default:
+ ASSERT(0);
}
}
-void encodeElementFunctionSATEncoder(SATEncoder* encoder, ElementFunction *This){
- switch(GETFUNCTIONTYPE(This->function)){
- case TABLEFUNC:
- encodeTableElementFunctionSATEncoder(encoder, This);
- break;
- case OPERATORFUNC:
- encodeOperatorElementFunctionSATEncoder(encoder, This);
- break;
- default:
- ASSERT(0);
+void encodeElementFunctionSATEncoder(SATEncoder *encoder, ElementFunction *This) {
+ switch (GETFUNCTIONTYPE(This->function)) {
+ case TABLEFUNC:
+ encodeTableElementFunctionSATEncoder(encoder, This);
+ break;
+ case OPERATORFUNC:
+ encodeOperatorElementFunctionSATEncoder(encoder, This);
+ break;
+ default:
+ ASSERT(0);
}
}
-void encodeTableElementFunctionSATEncoder(SATEncoder* encoder, ElementFunction* This){
- switch(getElementFunctionEncoding(This)->type){
- case ENUMERATEIMPLICATIONS:
- encodeEnumTableElemFunctionSATEncoder(encoder, This);
- break;
- case CIRCUIT:
- ASSERT(0);
- break;
- default:
- ASSERT(0);
+void encodeTableElementFunctionSATEncoder(SATEncoder *encoder, ElementFunction *This) {
+ switch (getElementFunctionEncoding(This)->type) {
+ case ENUMERATEIMPLICATIONS:
+ encodeEnumTableElemFunctionSATEncoder(encoder, This);
+ break;
+ case CIRCUIT:
+ ASSERT(0);
+ break;
+ default:
+ ASSERT(0);
}
}
struct SATEncoder {
uint varcount;
- CNF * cnf;
+ CNF *cnf;
};
#include "satelemencoder.h"
#include "satorderencoder.h"
#include "satfunctableencoder.h"
-SATEncoder * allocSATEncoder();
+SATEncoder *allocSATEncoder();
void deleteSATEncoder(SATEncoder *This);
void encodeAllSATEncoder(CSolver *csolver, SATEncoder *This);
Edge getNewVarSATEncoder(SATEncoder *This);
-void getArrayNewVarsSATEncoder(SATEncoder* encoder, uint num, Edge*carray);
+void getArrayNewVarsSATEncoder(SATEncoder *encoder, uint num, Edge *carray);
Edge encodeConstraintSATEncoder(SATEncoder *This, Boolean *constraint);
-Edge encodeVarSATEncoder(SATEncoder *This, BooleanVar * constraint);
-Edge encodeLogicSATEncoder(SATEncoder *This, BooleanLogic * constraint);
-Edge encodePredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint);
-Edge encodeTablePredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint);
+Edge encodeVarSATEncoder(SATEncoder *This, BooleanVar *constraint);
+Edge encodeLogicSATEncoder(SATEncoder *This, BooleanLogic *constraint);
+Edge encodePredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint);
+Edge encodeTablePredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint);
-void encodeElementSATEncoder(SATEncoder* encoder, Element *This);
-void encodeElementFunctionSATEncoder(SATEncoder* encoder, ElementFunction *This);
-void encodeTableElementFunctionSATEncoder(SATEncoder* encoder, ElementFunction* This);
+void encodeElementSATEncoder(SATEncoder *encoder, Element *This);
+void encodeElementFunctionSATEncoder(SATEncoder *encoder, ElementFunction *This);
+void encodeTableElementFunctionSATEncoder(SATEncoder *encoder, ElementFunction *This);
#endif
#include "common.h"
#include "satfuncopencoder.h"
-Edge encodeOperatorPredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint) {
- switch(constraint->encoding.type){
- case ENUMERATEIMPLICATIONS:
- return encodeEnumOperatorPredicateSATEncoder(This, constraint);
- case CIRCUIT:
- return encodeCircuitOperatorPredicateEncoder(This, constraint);
- default:
- ASSERT(0);
+Edge encodeOperatorPredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint) {
+ switch (constraint->encoding.type) {
+ case ENUMERATEIMPLICATIONS:
+ return encodeEnumOperatorPredicateSATEncoder(This, constraint);
+ case CIRCUIT:
+ return encodeCircuitOperatorPredicateEncoder(This, constraint);
+ default:
+ ASSERT(0);
}
exit(-1);
}
-Edge encodeEnumOperatorPredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint) {
- PredicateOperator* predicate = (PredicateOperator*)constraint->predicate;
- uint numDomains=getSizeArraySet(&predicate->domains);
+Edge encodeEnumOperatorPredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint) {
+ PredicateOperator *predicate = (PredicateOperator *)constraint->predicate;
+ uint numDomains = getSizeArraySet(&predicate->domains);
FunctionEncodingType encType = constraint->encoding.type;
bool generateNegation = encType == ENUMERATEIMPLICATIONSNEGATE;
/* Call base encoders for children */
- for(uint i=0;i<numDomains;i++) {
+ for (uint i = 0; i < numDomains; i++) {
Element *elem = getArrayElement( &constraint->inputs, i);
encodeElementSATEncoder(This, elem);
}
- VectorEdge * clauses=allocDefVectorEdge(); // Setup array of clauses
-
- uint indices[numDomains]; //setup indices
- bzero(indices, sizeof(uint)*numDomains);
-
- uint64_t vals[numDomains]; //setup value array
- for(uint i=0;i<numDomains; i++) {
- Set * set=getArraySet(&predicate->domains, i);
- vals[i]=getSetElement(set, indices[i]);
+ VectorEdge *clauses = allocDefVectorEdge(); // Setup array of clauses
+
+ uint indices[numDomains]; //setup indices
+ bzero(indices, sizeof(uint) * numDomains);
+
+ uint64_t vals[numDomains];//setup value array
+ for (uint i = 0; i < numDomains; i++) {
+ Set *set = getArraySet(&predicate->domains, i);
+ vals[i] = getSetElement(set, indices[i]);
}
-
- bool notfinished=true;
- while(notfinished) {
+
+ bool notfinished = true;
+ while (notfinished) {
Edge carray[numDomains];
if (evalPredicateOperator(predicate, vals) ^ generateNegation) {
//Include this in the set of terms
- for(uint i=0;i<numDomains;i++) {
- Element * elem = getArrayElement(&constraint->inputs, i);
+ for (uint i = 0; i < numDomains; i++) {
+ Element *elem = getArrayElement(&constraint->inputs, i);
carray[i] = getElementValueConstraint(This, elem, vals[i]);
}
- Edge term=constraintAND(This->cnf, numDomains, carray);
+ Edge term = constraintAND(This->cnf, numDomains, carray);
pushVectorEdge(clauses, term);
}
-
- notfinished=false;
- for(uint i=0;i<numDomains; i++) {
- uint index=++indices[i];
- Set * set=getArraySet(&predicate->domains, i);
+
+ notfinished = false;
+ for (uint i = 0; i < numDomains; i++) {
+ uint index = ++indices[i];
+ Set *set = getArraySet(&predicate->domains, i);
if (index < getSetSize(set)) {
- vals[i]=getSetElement(set, index);
- notfinished=true;
+ vals[i] = getSetElement(set, index);
+ notfinished = true;
break;
} else {
- indices[i]=0;
- vals[i]=getSetElement(set, 0);
+ indices[i] = 0;
+ vals[i] = getSetElement(set, 0);
}
}
}
- if(getSizeVectorEdge(clauses) == 0) {
+ if (getSizeVectorEdge(clauses) == 0) {
deleteVectorEdge(clauses);
return E_False;
}
- Edge cor=constraintOR(This->cnf, getSizeVectorEdge(clauses), exposeArrayEdge(clauses));
+ Edge cor = constraintOR(This->cnf, getSizeVectorEdge(clauses), exposeArrayEdge(clauses));
deleteVectorEdge(clauses);
return generateNegation ? constraintNegate(cor) : cor;
}
-void encodeOperatorElementFunctionSATEncoder(SATEncoder* This, ElementFunction* func) {
+void encodeOperatorElementFunctionSATEncoder(SATEncoder *This, ElementFunction *func) {
#ifdef TRACE_DEBUG
model_print("Operator Function ...\n");
#endif
- FunctionOperator * function = (FunctionOperator *) func->function;
- uint numDomains=getSizeArrayElement(&func->inputs);
+ FunctionOperator *function = (FunctionOperator *) func->function;
+ uint numDomains = getSizeArrayElement(&func->inputs);
/* Call base encoders for children */
- for(uint i=0;i<numDomains;i++) {
+ for (uint i = 0; i < numDomains; i++) {
Element *elem = getArrayElement( &func->inputs, i);
encodeElementSATEncoder(This, elem);
}
- VectorEdge * clauses=allocDefVectorEdge(); // Setup array of clauses
-
- uint indices[numDomains]; //setup indices
- bzero(indices, sizeof(uint)*numDomains);
-
- uint64_t vals[numDomains]; //setup value array
- for(uint i=0;i<numDomains; i++) {
- Set * set=getElementSet(getArrayElement(&func->inputs, i));
- vals[i]=getSetElement(set, indices[i]);
+ VectorEdge *clauses = allocDefVectorEdge(); // Setup array of clauses
+
+ uint indices[numDomains]; //setup indices
+ bzero(indices, sizeof(uint) * numDomains);
+
+ uint64_t vals[numDomains];//setup value array
+ for (uint i = 0; i < numDomains; i++) {
+ Set *set = getElementSet(getArrayElement(&func->inputs, i));
+ vals[i] = getSetElement(set, indices[i]);
}
- Edge overFlowConstraint = ((BooleanVar*) func->overflowstatus)->var;
-
- bool notfinished=true;
- while(notfinished) {
- Edge carray[numDomains+1];
+ Edge overFlowConstraint = ((BooleanVar *) func->overflowstatus)->var;
+
+ bool notfinished = true;
+ while (notfinished) {
+ Edge carray[numDomains + 1];
- uint64_t result=applyFunctionOperator(function, numDomains, vals);
- bool isInRange = isInRangeFunction((FunctionOperator*)func->function, result);
+ uint64_t result = applyFunctionOperator(function, numDomains, vals);
+ bool isInRange = isInRangeFunction((FunctionOperator *)func->function, result);
bool needClause = isInRange;
if (function->overflowbehavior == OVERFLOWSETSFLAG || function->overflowbehavior == FLAGIFFOVERFLOW) {
- needClause=true;
+ needClause = true;
}
-
+
if (needClause) {
//Include this in the set of terms
- for(uint i=0;i<numDomains;i++) {
- Element * elem = getArrayElement(&func->inputs, i);
+ for (uint i = 0; i < numDomains; i++) {
+ Element *elem = getArrayElement(&func->inputs, i);
carray[i] = getElementValueConstraint(This, elem, vals[i]);
}
if (isInRange) {
}
Edge clause;
- switch(function->overflowbehavior) {
+ switch (function->overflowbehavior) {
case IGNORE:
case NOOVERFLOW:
case WRAPAROUND: {
- clause=constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), carray[numDomains]);
+ clause = constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), carray[numDomains]);
break;
}
case FLAGFORCESOVERFLOW: {
- clause=constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), constraintAND2(This->cnf, carray[numDomains], constraintNegate(overFlowConstraint)));
+ clause = constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), constraintAND2(This->cnf, carray[numDomains], constraintNegate(overFlowConstraint)));
break;
}
case OVERFLOWSETSFLAG: {
if (isInRange) {
- clause=constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), carray[numDomains]);
+ clause = constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), carray[numDomains]);
} else {
- clause=constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), overFlowConstraint);
+ clause = constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), overFlowConstraint);
}
break;
}
case FLAGIFFOVERFLOW: {
if (isInRange) {
- clause=constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), constraintAND2(This->cnf, carray[numDomains], constraintNegate(overFlowConstraint)));
+ clause = constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), constraintAND2(This->cnf, carray[numDomains], constraintNegate(overFlowConstraint)));
} else {
- clause=constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), overFlowConstraint);
+ clause = constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), overFlowConstraint);
}
break;
}
#endif
pushVectorEdge(clauses, clause);
}
-
- notfinished=false;
- for(uint i=0;i<numDomains; i++) {
- uint index=++indices[i];
- Set * set=getElementSet(getArrayElement(&func->inputs, i));
+
+ notfinished = false;
+ for (uint i = 0; i < numDomains; i++) {
+ uint index = ++indices[i];
+ Set *set = getElementSet(getArrayElement(&func->inputs, i));
if (index < getSetSize(set)) {
- vals[i]=getSetElement(set, index);
- notfinished=true;
+ vals[i] = getSetElement(set, index);
+ notfinished = true;
break;
} else {
- indices[i]=0;
- vals[i]=getSetElement(set, 0);
+ indices[i] = 0;
+ vals[i] = getSetElement(set, 0);
}
}
}
- if(getSizeVectorEdge(clauses) == 0){
+ if (getSizeVectorEdge(clauses) == 0) {
deleteVectorEdge(clauses);
return;
}
- Edge cor=constraintAND(This->cnf, getSizeVectorEdge(clauses), exposeArrayEdge(clauses));
+ Edge cor = constraintAND(This->cnf, getSizeVectorEdge(clauses), exposeArrayEdge(clauses));
addConstraintCNF(This->cnf, cor);
deleteVectorEdge(clauses);
}
-Edge encodeCircuitOperatorPredicateEncoder(SATEncoder *This, BooleanPredicate * constraint) {
- PredicateOperator * predicate = (PredicateOperator*) constraint->predicate;
-
- switch(predicate->op) {
+Edge encodeCircuitOperatorPredicateEncoder(SATEncoder *This, BooleanPredicate *constraint) {
+ PredicateOperator *predicate = (PredicateOperator *) constraint->predicate;
+
+ switch (predicate->op) {
case EQUALS: {
return encodeCircuitEquals(This, constraint);
}
exit(-1);
}
-Edge encodeCircuitEquals(SATEncoder * This, BooleanPredicate * constraint) {
- PredicateOperator * predicate = (PredicateOperator*) constraint->predicate;
+Edge encodeCircuitEquals(SATEncoder *This, BooleanPredicate *constraint) {
+ PredicateOperator *predicate = (PredicateOperator *) constraint->predicate;
ASSERT(getSizeArraySet(&predicate->domains) == 2);
Element *elem0 = getArrayElement( &constraint->inputs, 0);
encodeElementSATEncoder(This, elem0);
Element *elem1 = getArrayElement( &constraint->inputs, 1);
encodeElementSATEncoder(This, elem1);
- ElementEncoding *ee0=getElementEncoding(elem0);
- ElementEncoding *ee1=getElementEncoding(elem1);
- ASSERT(ee0->numVars==ee1->numVars);
- uint numVars=ee0->numVars;
+ ElementEncoding *ee0 = getElementEncoding(elem0);
+ ElementEncoding *ee1 = getElementEncoding(elem1);
+ ASSERT(ee0->numVars == ee1->numVars);
+ uint numVars = ee0->numVars;
ASSERT(numVars != 0);
Edge carray[numVars];
- for (uint i=0; i<numVars; i++) {
- carray[i]=constraintIFF(This->cnf, ee0->variables[i], ee1->variables[i]);
+ for (uint i = 0; i < numVars; i++) {
+ carray[i] = constraintIFF(This->cnf, ee0->variables[i], ee1->variables[i]);
}
return constraintAND(This->cnf, numVars, carray);
}
#ifndef SATFUNCOPENCODER_H
#define SATFUNCOPENCODER_H
-Edge encodeOperatorPredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint);
-Edge encodeEnumOperatorPredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint);
-void encodeOperatorElementFunctionSATEncoder(SATEncoder* encoder,ElementFunction* This);
-Edge encodeCircuitOperatorPredicateEncoder(SATEncoder *This, BooleanPredicate * constraint);
-Edge encodeCircuitEquals(SATEncoder * This, BooleanPredicate * constraint);
+Edge encodeOperatorPredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint);
+Edge encodeEnumOperatorPredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint);
+void encodeOperatorElementFunctionSATEncoder(SATEncoder *encoder,ElementFunction *This);
+Edge encodeCircuitOperatorPredicateEncoder(SATEncoder *This, BooleanPredicate *constraint);
+Edge encodeCircuitEquals(SATEncoder *This, BooleanPredicate *constraint);
#endif
#include "element.h"
#include "common.h"
-Edge encodeEnumEntriesTablePredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint){
+Edge encodeEnumEntriesTablePredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint) {
ASSERT(GETPREDICATETYPE(constraint->predicate) == TABLEPRED);
- UndefinedBehavior undefStatus = ((PredicateTable*)constraint->predicate)->undefinedbehavior;
+ UndefinedBehavior undefStatus = ((PredicateTable *)constraint->predicate)->undefinedbehavior;
ASSERT(undefStatus == IGNOREBEHAVIOR || undefStatus == FLAGFORCEUNDEFINED);
- Table* table = ((PredicateTable*)constraint->predicate)->table;
+ Table *table = ((PredicateTable *)constraint->predicate)->table;
FunctionEncodingType encType = constraint->encoding.type;
- ArrayElement* inputs = &constraint->inputs;
- uint inputNum =getSizeArrayElement(inputs);
+ ArrayElement *inputs = &constraint->inputs;
+ uint inputNum = getSizeArrayElement(inputs);
uint size = getSizeHashSetTableEntry(table->entries);
bool generateNegation = encType == ENUMERATEIMPLICATIONSNEGATE;
Edge constraints[size];
Edge undefConst = encodeConstraintSATEncoder(This, constraint->undefStatus);
printCNF(undefConst);
model_print("**\n");
- HSIteratorTableEntry* iterator = iteratorTableEntry(table->entries);
- uint i=0;
- while(hasNextTableEntry(iterator)){
- TableEntry* entry = nextTableEntry(iterator);
- if(generateNegation == entry->output && undefStatus == IGNOREBEHAVIOR) {
+ HSIteratorTableEntry *iterator = iteratorTableEntry(table->entries);
+ uint i = 0;
+ while (hasNextTableEntry(iterator)) {
+ TableEntry *entry = nextTableEntry(iterator);
+ if (generateNegation == entry->output && undefStatus == IGNOREBEHAVIOR) {
//Skip the irrelevant entries
continue;
}
Edge carray[inputNum];
- for(uint j=0; j<inputNum; j++){
- Element* el = getArrayElement(inputs, j);
+ for (uint j = 0; j < inputNum; j++) {
+ Element *el = getArrayElement(inputs, j);
carray[j] = getElementValueConstraint(This, el, entry->inputs[j]);
printCNF(carray[j]);
model_print("\n");
}
Edge row;
- switch(undefStatus){
- case IGNOREBEHAVIOR:
- row=constraintAND(This->cnf, inputNum, carray);
- break;
- case FLAGFORCEUNDEFINED:{
- addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf,constraintAND(This->cnf, inputNum, carray), constraintNegate(undefConst)));
- if(generateNegation == entry->output){
- continue;
- }
- row=constraintAND(This->cnf, inputNum, carray);
- break;
+ switch (undefStatus) {
+ case IGNOREBEHAVIOR:
+ row = constraintAND(This->cnf, inputNum, carray);
+ break;
+ case FLAGFORCEUNDEFINED: {
+ addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf,constraintAND(This->cnf, inputNum, carray), constraintNegate(undefConst)));
+ if (generateNegation == entry->output) {
+ continue;
}
- default:
- ASSERT(0);
+ row = constraintAND(This->cnf, inputNum, carray);
+ break;
+ }
+ default:
+ ASSERT(0);
}
constraints[i++] = row;
printCNF(row);
-
+
model_print("\n\n");
}
deleteIterTableEntry(iterator);
- ASSERT(i!=0);
- Edge result= generateNegation?constraintNegate(constraintOR(This->cnf, i, constraints))
- :constraintOR(This->cnf, i, constraints);
+ ASSERT(i != 0);
+ Edge result = generateNegation ? constraintNegate(constraintOR(This->cnf, i, constraints))
+ : constraintOR(This->cnf, i, constraints);
printCNF(result);
return result;
}
-Edge encodeEnumTablePredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint){
+Edge encodeEnumTablePredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint) {
#ifdef TRACE_DEBUG
model_print("Enumeration Table Predicate ...\n");
#endif
ASSERT(GETPREDICATETYPE(constraint->predicate) == TABLEPRED);
//First encode children
- ArrayElement* inputs = &constraint->inputs;
- uint inputNum =getSizeArrayElement(inputs);
+ ArrayElement *inputs = &constraint->inputs;
+ uint inputNum = getSizeArrayElement(inputs);
//Encode all the inputs first ...
- for(uint i=0; i<inputNum; i++){
+ for (uint i = 0; i < inputNum; i++) {
encodeElementSATEncoder(This, getArrayElement(inputs, i));
}
- PredicateTable* predicate = (PredicateTable*)constraint->predicate;
- switch(predicate->undefinedbehavior){
- case IGNOREBEHAVIOR:
- case FLAGFORCEUNDEFINED:
- return encodeEnumEntriesTablePredicateSATEncoder(This, constraint);
- default:
- break;
+ PredicateTable *predicate = (PredicateTable *)constraint->predicate;
+ switch (predicate->undefinedbehavior) {
+ case IGNOREBEHAVIOR:
+ case FLAGFORCEUNDEFINED:
+ return encodeEnumEntriesTablePredicateSATEncoder(This, constraint);
+ default:
+ break;
}
bool generateNegation = constraint->encoding.type == ENUMERATEIMPLICATIONSNEGATE;
- uint numDomains=getSizeArraySet(&predicate->table->domains);
+ uint numDomains = getSizeArraySet(&predicate->table->domains);
- VectorEdge * clauses=allocDefVectorEdge();
-
- uint indices[numDomains]; //setup indices
- bzero(indices, sizeof(uint)*numDomains);
-
- uint64_t vals[numDomains]; //setup value array
- for(uint i=0;i<numDomains; i++) {
- Set * set=getArraySet(&predicate->table->domains, i);
- vals[i]=getSetElement(set, indices[i]);
+ VectorEdge *clauses = allocDefVectorEdge();
+
+ uint indices[numDomains]; //setup indices
+ bzero(indices, sizeof(uint) * numDomains);
+
+ uint64_t vals[numDomains];//setup value array
+ for (uint i = 0; i < numDomains; i++) {
+ Set *set = getArraySet(&predicate->table->domains, i);
+ vals[i] = getSetElement(set, indices[i]);
}
bool hasOverflow = false;
Edge undefConstraint = encodeConstraintSATEncoder (This, constraint->undefStatus);
printCNF(undefConstraint);
- bool notfinished=true;
- while(notfinished) {
+ bool notfinished = true;
+ while (notfinished) {
Edge carray[numDomains];
- TableEntry* tableEntry = getTableEntryFromTable(predicate->table, vals, numDomains);
- bool isInRange = tableEntry!=NULL;
- if(!isInRange && !hasOverflow){
- hasOverflow=true;
+ TableEntry *tableEntry = getTableEntryFromTable(predicate->table, vals, numDomains);
+ bool isInRange = tableEntry != NULL;
+ if (!isInRange && !hasOverflow) {
+ hasOverflow = true;
}
Edge clause;
- for(uint i=0;i<numDomains;i++) {
- Element * elem = getArrayElement(&constraint->inputs, i);
- carray[i] = getElementValueConstraint(This, elem, vals[i]);
+ for (uint i = 0; i < numDomains; i++) {
+ Element *elem = getArrayElement(&constraint->inputs, i);
+ carray[i] = getElementValueConstraint(This, elem, vals[i]);
}
-
- switch(predicate->undefinedbehavior) {
- case UNDEFINEDSETSFLAG:
- if(isInRange){
- clause=constraintAND(This->cnf, numDomains, carray);
- }else{
- addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), undefConstraint) );
- }
- break;
- case FLAGIFFUNDEFINED:
- if(isInRange){
- clause=constraintAND(This->cnf, numDomains, carray);
- addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), constraintNegate(undefConstraint)));
- }else{
- addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), undefConstraint) );
- }
- break;
- default:
- ASSERT(0);
+ switch (predicate->undefinedbehavior) {
+ case UNDEFINEDSETSFLAG:
+ if (isInRange) {
+ clause = constraintAND(This->cnf, numDomains, carray);
+ } else {
+ addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), undefConstraint) );
+ }
+ break;
+ case FLAGIFFUNDEFINED:
+ if (isInRange) {
+ clause = constraintAND(This->cnf, numDomains, carray);
+ addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), constraintNegate(undefConstraint)));
+ } else {
+ addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), undefConstraint) );
+ }
+ break;
+
+ default:
+ ASSERT(0);
}
-
- if(isInRange){
+
+ if (isInRange) {
#ifdef TRACE_DEBUG
model_print("added clause in predicate table enumeration ...\n");
printCNF(clause);
#endif
pushVectorEdge(clauses, clause);
}
-
- notfinished=false;
- for(uint i=0;i<numDomains; i++) {
- uint index=++indices[i];
- Set * set=getArraySet(&predicate->table->domains, i);
+
+ notfinished = false;
+ for (uint i = 0; i < numDomains; i++) {
+ uint index = ++indices[i];
+ Set *set = getArraySet(&predicate->table->domains, i);
if (index < getSetSize(set)) {
- vals[i]=getSetElement(set, index);
- notfinished=true;
+ vals[i] = getSetElement(set, index);
+ notfinished = true;
break;
} else {
- indices[i]=0;
- vals[i]=getSetElement(set, 0);
+ indices[i] = 0;
+ vals[i] = getSetElement(set, 0);
}
}
}
Edge result = E_NULL;
ASSERT(getSizeVectorEdge(clauses) != 0);
- result=constraintOR(This->cnf, getSizeVectorEdge(clauses), exposeArrayEdge(clauses));
- if(hasOverflow){
+ result = constraintOR(This->cnf, getSizeVectorEdge(clauses), exposeArrayEdge(clauses));
+ if (hasOverflow) {
result = constraintOR2(This->cnf, result, undefConstraint);
}
- if(generateNegation){
+ if (generateNegation) {
ASSERT(!hasOverflow);
result = constraintNegate(result);
}
return result;
}
-void encodeEnumEntriesTableElemFuncSATEncoder(SATEncoder* This, ElementFunction* func){
- UndefinedBehavior undefStatus = ((FunctionTable*) func->function)->undefBehavior;
+void encodeEnumEntriesTableElemFuncSATEncoder(SATEncoder *This, ElementFunction *func) {
+ UndefinedBehavior undefStatus = ((FunctionTable *) func->function)->undefBehavior;
ASSERT(undefStatus == IGNOREBEHAVIOR || undefStatus == FLAGFORCEUNDEFINED);
- ArrayElement* elements= &func->inputs;
- Table* table = ((FunctionTable*) (func->function))->table;
+ ArrayElement *elements = &func->inputs;
+ Table *table = ((FunctionTable *) (func->function))->table;
uint size = getSizeHashSetTableEntry(table->entries);
Edge constraints[size];
- HSIteratorTableEntry* iterator = iteratorTableEntry(table->entries);
- uint i=0;
- while(hasNextTableEntry(iterator)) {
- TableEntry* entry = nextTableEntry(iterator);
- ASSERT(entry!=NULL);
+ HSIteratorTableEntry *iterator = iteratorTableEntry(table->entries);
+ uint i = 0;
+ while (hasNextTableEntry(iterator)) {
+ TableEntry *entry = nextTableEntry(iterator);
+ ASSERT(entry != NULL);
uint inputNum = getSizeArrayElement(elements);
Edge carray[inputNum];
- for(uint j=0; j<inputNum; j++){
- Element* el= getArrayElement(elements, j);
+ for (uint j = 0; j < inputNum; j++) {
+ Element *el = getArrayElement(elements, j);
carray[j] = getElementValueConstraint(This, el, entry->inputs[j]);
}
- Edge output = getElementValueConstraint(This, (Element*)func, entry->output);
+ Edge output = getElementValueConstraint(This, (Element *)func, entry->output);
Edge row;
- switch(undefStatus ){
- case IGNOREBEHAVIOR: {
- row=constraintIMPLIES(This->cnf,constraintAND(This->cnf, inputNum, carray), output);
- break;
- }
- case FLAGFORCEUNDEFINED: {
- Edge undefConst = encodeConstraintSATEncoder(This, func->overflowstatus);
- row=constraintIMPLIES(This->cnf,constraintAND(This->cnf, inputNum, carray), constraintAND2(This->cnf, output, constraintNegate(undefConst)));
- break;
- }
- default:
- ASSERT(0);
-
+ switch (undefStatus ) {
+ case IGNOREBEHAVIOR: {
+ row = constraintIMPLIES(This->cnf,constraintAND(This->cnf, inputNum, carray), output);
+ break;
+ }
+ case FLAGFORCEUNDEFINED: {
+ Edge undefConst = encodeConstraintSATEncoder(This, func->overflowstatus);
+ row = constraintIMPLIES(This->cnf,constraintAND(This->cnf, inputNum, carray), constraintAND2(This->cnf, output, constraintNegate(undefConst)));
+ break;
+ }
+ default:
+ ASSERT(0);
+
}
- constraints[i++]=row;
+ constraints[i++] = row;
}
deleteIterTableEntry(iterator);
addConstraintCNF(This->cnf, constraintAND(This->cnf, size, constraints));
}
-void encodeEnumTableElemFunctionSATEncoder(SATEncoder* This, ElementFunction* elemFunc){
+void encodeEnumTableElemFunctionSATEncoder(SATEncoder *This, ElementFunction *elemFunc) {
#ifdef TRACE_DEBUG
model_print("Enumeration Table functions ...\n");
#endif
- ASSERT(GETFUNCTIONTYPE(elemFunc->function)==TABLEFUNC);
+ ASSERT(GETFUNCTIONTYPE(elemFunc->function) == TABLEFUNC);
//First encode children
- ArrayElement* elements= &elemFunc->inputs;
- for(uint i=0; i<getSizeArrayElement(elements); i++){
+ ArrayElement *elements = &elemFunc->inputs;
+ for (uint i = 0; i < getSizeArrayElement(elements); i++) {
Element *elem = getArrayElement( elements, i);
encodeElementSATEncoder(This, elem);
}
- FunctionTable* function =(FunctionTable*)elemFunc->function;
- switch(function->undefBehavior){
- case IGNOREBEHAVIOR:
- case FLAGFORCEUNDEFINED:
- return encodeEnumEntriesTableElemFuncSATEncoder(This, elemFunc);
- default:
- break;
+ FunctionTable *function = (FunctionTable *)elemFunc->function;
+ switch (function->undefBehavior) {
+ case IGNOREBEHAVIOR:
+ case FLAGFORCEUNDEFINED:
+ return encodeEnumEntriesTableElemFuncSATEncoder(This, elemFunc);
+ default:
+ break;
}
-
- uint numDomains=getSizeArraySet(&function->table->domains);
- VectorEdge * clauses=allocDefVectorEdge(); // Setup array of clauses
-
- uint indices[numDomains]; //setup indices
- bzero(indices, sizeof(uint)*numDomains);
-
- uint64_t vals[numDomains]; //setup value array
- for(uint i=0;i<numDomains; i++) {
- Set * set=getArraySet(&function->table->domains, i);
- vals[i]=getSetElement(set, indices[i]);
+ uint numDomains = getSizeArraySet(&function->table->domains);
+
+ VectorEdge *clauses = allocDefVectorEdge(); // Setup array of clauses
+
+ uint indices[numDomains]; //setup indices
+ bzero(indices, sizeof(uint) * numDomains);
+
+ uint64_t vals[numDomains];//setup value array
+ for (uint i = 0; i < numDomains; i++) {
+ Set *set = getArraySet(&function->table->domains, i);
+ vals[i] = getSetElement(set, indices[i]);
}
Edge undefConstraint = encodeConstraintSATEncoder(This, elemFunc->overflowstatus);
- bool notfinished=true;
- while(notfinished) {
- Edge carray[numDomains+1];
- TableEntry* tableEntry = getTableEntryFromTable(function->table, vals, numDomains);
- bool isInRange = tableEntry!=NULL;
+ bool notfinished = true;
+ while (notfinished) {
+ Edge carray[numDomains + 1];
+ TableEntry *tableEntry = getTableEntryFromTable(function->table, vals, numDomains);
+ bool isInRange = tableEntry != NULL;
ASSERT(function->undefBehavior == UNDEFINEDSETSFLAG || function->undefBehavior == FLAGIFFUNDEFINED);
- for(uint i=0;i<numDomains;i++) {
- Element * elem = getArrayElement(&elemFunc->inputs, i);
+ for (uint i = 0; i < numDomains; i++) {
+ Element *elem = getArrayElement(&elemFunc->inputs, i);
carray[i] = getElementValueConstraint(This, elem, vals[i]);
}
if (isInRange) {
- carray[numDomains] = getElementValueConstraint(This, (Element*)elemFunc, tableEntry->output);
+ carray[numDomains] = getElementValueConstraint(This, (Element *)elemFunc, tableEntry->output);
}
Edge clause;
- switch(function->undefBehavior) {
- case UNDEFINEDSETSFLAG: {
- if (isInRange) {
- //FIXME: Talk to Brian, It should be IFF not only IMPLY. --HG
- clause=constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), carray[numDomains]);
- } else {
- addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), undefConstraint));
- }
- break;
+ switch (function->undefBehavior) {
+ case UNDEFINEDSETSFLAG: {
+ if (isInRange) {
+ //FIXME: Talk to Brian, It should be IFF not only IMPLY. --HG
+ clause = constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), carray[numDomains]);
+ } else {
+ addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), undefConstraint));
}
- case FLAGIFFUNDEFINED: {
- if (isInRange) {
- clause=constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), carray[numDomains]);
- addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf, constraintAND(This->cnf, numDomains, carray), constraintNegate(undefConstraint) ));
- } else {
- addConstraintCNF(This->cnf,constraintIMPLIES(This->cnf, constraintAND(This->cnf, numDomains, carray), undefConstraint));
- }
- break;
+ break;
+ }
+ case FLAGIFFUNDEFINED: {
+ if (isInRange) {
+ clause = constraintIMPLIES(This->cnf,constraintAND(This->cnf, numDomains, carray), carray[numDomains]);
+ addConstraintCNF(This->cnf, constraintIMPLIES(This->cnf, constraintAND(This->cnf, numDomains, carray), constraintNegate(undefConstraint) ));
+ } else {
+ addConstraintCNF(This->cnf,constraintIMPLIES(This->cnf, constraintAND(This->cnf, numDomains, carray), undefConstraint));
}
- default:
- ASSERT(0);
+ break;
+ }
+ default:
+ ASSERT(0);
}
- if(isInRange){
+ if (isInRange) {
#ifdef TRACE_DEBUG
model_print("added clause in function table enumeration ...\n");
printCNF(clause);
#endif
pushVectorEdge(clauses, clause);
}
-
- notfinished=false;
- for(uint i=0;i<numDomains; i++) {
- uint index=++indices[i];
- Set * set=getArraySet(&function->table->domains, i);
+
+ notfinished = false;
+ for (uint i = 0; i < numDomains; i++) {
+ uint index = ++indices[i];
+ Set *set = getArraySet(&function->table->domains, i);
if (index < getSetSize(set)) {
- vals[i]=getSetElement(set, index);
- notfinished=true;
+ vals[i] = getSetElement(set, index);
+ notfinished = true;
break;
} else {
- indices[i]=0;
- vals[i]=getSetElement(set, 0);
+ indices[i] = 0;
+ vals[i] = getSetElement(set, 0);
}
}
}
- if(getSizeVectorEdge(clauses) == 0){
+ if (getSizeVectorEdge(clauses) == 0) {
deleteVectorEdge(clauses);
return;
}
- Edge cor=constraintAND(This->cnf, getSizeVectorEdge(clauses), exposeArrayEdge(clauses));
+ Edge cor = constraintAND(This->cnf, getSizeVectorEdge(clauses), exposeArrayEdge(clauses));
addConstraintCNF(This->cnf, cor);
deleteVectorEdge(clauses);
-
+
}
#ifndef SATFUNCTABLEENCODER_H
#define SATFUNCTABLEENCODER_H
-Edge encodeEnumEntriesTablePredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint);
-Edge encodeEnumTablePredicateSATEncoder(SATEncoder * This, BooleanPredicate * constraint);
-void encodeEnumTableElemFunctionSATEncoder(SATEncoder* encoder, ElementFunction* This);
-void encodeEnumEntriesTableElemFuncSATEncoder(SATEncoder* encoder, ElementFunction* This);
+Edge encodeEnumEntriesTablePredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint);
+Edge encodeEnumTablePredicateSATEncoder(SATEncoder *This, BooleanPredicate *constraint);
+void encodeEnumTableElemFunctionSATEncoder(SATEncoder *encoder, ElementFunction *This);
+void encodeEnumEntriesTableElemFuncSATEncoder(SATEncoder *encoder, ElementFunction *This);
#endif
#include "orderpair.h"
#include "set.h"
-Edge encodeOrderSATEncoder(SATEncoder *This, BooleanOrder * constraint) {
- switch( constraint->order->type){
- case PARTIAL:
- return encodePartialOrderSATEncoder(This, constraint);
- case TOTAL:
- return encodeTotalOrderSATEncoder(This, constraint);
- default:
- ASSERT(0);
+Edge encodeOrderSATEncoder(SATEncoder *This, BooleanOrder *constraint) {
+ switch ( constraint->order->type) {
+ case PARTIAL:
+ return encodePartialOrderSATEncoder(This, constraint);
+ case TOTAL:
+ return encodeTotalOrderSATEncoder(This, constraint);
+ default:
+ ASSERT(0);
}
return E_BOGUS;
}
-Edge getPairConstraint(SATEncoder *This, HashTableOrderPair * table, OrderPair * pair) {
+Edge getPairConstraint(SATEncoder *This, HashTableOrderPair *table, OrderPair *pair) {
bool negate = false;
OrderPair flipped;
if (pair->first < pair->second) {
- negate=true;
- flipped.first=pair->second;
- flipped.second=pair->first;
+ negate = true;
+ flipped.first = pair->second;
+ flipped.second = pair->first;
pair = &flipped;
}
Edge constraint;
if (!containsOrderPair(table, pair)) {
constraint = getNewVarSATEncoder(This);
- OrderPair * paircopy = allocOrderPair(pair->first, pair->second, constraint);
+ OrderPair *paircopy = allocOrderPair(pair->first, pair->second, constraint);
putOrderPair(table, paircopy, paircopy);
} else
constraint = getOrderPair(table, pair)->constraint;
return negate ? constraintNegate(constraint) : constraint;
}
-Edge encodeTotalOrderSATEncoder(SATEncoder *This, BooleanOrder * boolOrder) {
+Edge encodeTotalOrderSATEncoder(SATEncoder *This, BooleanOrder *boolOrder) {
ASSERT(boolOrder->order->type == TOTAL);
- if(boolOrder->order->orderPairTable == NULL) {
+ if (boolOrder->order->orderPairTable == NULL) {
initializeOrderHashTable(boolOrder->order);
createAllTotalOrderConstraintsSATEncoder(This, boolOrder->order);
}
- HashTableOrderPair* orderPairTable = boolOrder->order->orderPairTable;
- OrderPair pair={boolOrder->first, boolOrder->second, E_NULL};
- Edge constraint = getPairConstraint(This, orderPairTable, & pair);
+ HashTableOrderPair *orderPairTable = boolOrder->order->orderPairTable;
+ OrderPair pair = {boolOrder->first, boolOrder->second, E_NULL};
+ Edge constraint = getPairConstraint(This, orderPairTable, &pair);
return constraint;
}
-void createAllTotalOrderConstraintsSATEncoder(SATEncoder* This, Order* order){
+void createAllTotalOrderConstraintsSATEncoder(SATEncoder *This, Order *order) {
#ifdef TRACE_DEBUG
model_print("in total order ...\n");
-#endif
+#endif
ASSERT(order->type == TOTAL);
- VectorInt* mems = order->set->members;
- HashTableOrderPair* table = order->orderPairTable;
+ VectorInt *mems = order->set->members;
+ HashTableOrderPair *table = order->orderPairTable;
uint size = getSizeVectorInt(mems);
- for(uint i=0; i<size; i++){
+ for (uint i = 0; i < size; i++) {
uint64_t valueI = getVectorInt(mems, i);
- for(uint j=i+1; j<size;j++){
+ for (uint j = i + 1; j < size; j++) {
uint64_t valueJ = getVectorInt(mems, j);
OrderPair pairIJ = {valueI, valueJ};
- Edge constIJ=getPairConstraint(This, table, & pairIJ);
- for(uint k=j+1; k<size; k++){
+ Edge constIJ = getPairConstraint(This, table, &pairIJ);
+ for (uint k = j + 1; k < size; k++) {
uint64_t valueK = getVectorInt(mems, k);
OrderPair pairJK = {valueJ, valueK};
OrderPair pairIK = {valueI, valueK};
- Edge constIK = getPairConstraint(This, table, & pairIK);
- Edge constJK = getPairConstraint(This, table, & pairJK);
- addConstraintCNF(This->cnf, generateTransOrderConstraintSATEncoder(This, constIJ, constJK, constIK));
+ Edge constIK = getPairConstraint(This, table, &pairIK);
+ Edge constJK = getPairConstraint(This, table, &pairJK);
+ addConstraintCNF(This->cnf, generateTransOrderConstraintSATEncoder(This, constIJ, constJK, constIK));
}
}
}
}
-Edge getOrderConstraint(HashTableOrderPair *table, OrderPair *pair){
- ASSERT(pair->first!= pair->second);
+Edge getOrderConstraint(HashTableOrderPair *table, OrderPair *pair) {
+ ASSERT(pair->first != pair->second);
bool negate = false;
OrderPair flipped;
if (pair->first < pair->second) {
- negate=true;
- flipped.first=pair->second;
- flipped.second=pair->first;
+ negate = true;
+ flipped.first = pair->second;
+ flipped.second = pair->first;
pair = &flipped;
}
if (!containsOrderPair(table, pair)) {
return E_NULL;
}
- Edge constraint= getOrderPair(table, pair)->constraint;
+ Edge constraint = getOrderPair(table, pair)->constraint;
ASSERT(!edgeIsNull(constraint));
return negate ? constraintNegate(constraint) : constraint;
}
-Edge generateTransOrderConstraintSATEncoder(SATEncoder *This, Edge constIJ,Edge constJK,Edge constIK){
+Edge generateTransOrderConstraintSATEncoder(SATEncoder *This, Edge constIJ,Edge constJK,Edge constIK) {
Edge carray[] = {constIJ, constJK, constraintNegate(constIK)};
- Edge loop1= constraintOR(This->cnf, 3, carray);
+ Edge loop1 = constraintOR(This->cnf, 3, carray);
Edge carray2[] = {constraintNegate(constIJ), constraintNegate(constJK), constIK};
- Edge loop2= constraintOR(This->cnf, 3, carray2 );
+ Edge loop2 = constraintOR(This->cnf, 3, carray2 );
return constraintAND2(This->cnf, loop1, loop2);
}
-Edge encodePartialOrderSATEncoder(SATEncoder *This, BooleanOrder * constraint){
+Edge encodePartialOrderSATEncoder(SATEncoder *This, BooleanOrder *constraint) {
ASSERT(constraint->order->type == PARTIAL);
return E_BOGUS;
}
#ifndef SATORDERENCODER_H
#define SATORDERENCODER_H
-Edge encodeOrderSATEncoder(SATEncoder *This, BooleanOrder * constraint);
+Edge encodeOrderSATEncoder(SATEncoder *This, BooleanOrder *constraint);
Edge getPairConstraint(SATEncoder *This, HashTableOrderPair *table, OrderPair *pair);
-Edge encodeTotalOrderSATEncoder(SATEncoder *This, BooleanOrder * constraint);
-Edge encodePartialOrderSATEncoder(SATEncoder *This, BooleanOrder * constraint);
-void createAllTotalOrderConstraintsSATEncoder(SATEncoder* This, Order* order);
+Edge encodeTotalOrderSATEncoder(SATEncoder *This, BooleanOrder *constraint);
+Edge encodePartialOrderSATEncoder(SATEncoder *This, BooleanOrder *constraint);
+void createAllTotalOrderConstraintsSATEncoder(SATEncoder *This, Order *order);
Edge getOrderConstraint(HashTableOrderPair *table, OrderPair *pair);
Edge generateTransOrderConstraintSATEncoder(SATEncoder *This, Edge constIJ, Edge constJK, Edge constIK);
#endif
#include "order.h"
#include "orderpair.h"
-uint64_t getElementValueBinaryIndexSATTranslator(CSolver* This, ElementEncoding* elemEnc){
- uint index=0;
- for(int i=elemEnc->numVars-1;i>=0;i--) {
- index=index<<1;
+uint64_t getElementValueBinaryIndexSATTranslator(CSolver *This, ElementEncoding *elemEnc) {
+ uint index = 0;
+ for (int i = elemEnc->numVars - 1; i >= 0; i--) {
+ index = index << 1;
if (getValueSolver(This->satEncoder->cnf->solver, getEdgeVar( elemEnc->variables[i] )))
index |= 1;
}
model_print("index:%u\tencArraySize:%u\tisInUseElement:%u\n", index, elemEnc->encArraySize, isinUseElement(elemEnc, index));
- ASSERT(elemEnc->encArraySize >index && isinUseElement(elemEnc, index));
+ ASSERT(elemEnc->encArraySize > index && isinUseElement(elemEnc, index));
return elemEnc->encodingArray[index];
}
-uint64_t getElementValueBinaryValueSATTranslator(CSolver* This, ElementEncoding* elemEnc){
- uint64_t value=0;
- for(int i=elemEnc->numVars-1;i>=0;i--) {
- value=value<<1;
+uint64_t getElementValueBinaryValueSATTranslator(CSolver *This, ElementEncoding *elemEnc) {
+ uint64_t value = 0;
+ for (int i = elemEnc->numVars - 1; i >= 0; i--) {
+ value = value << 1;
if (getValueSolver(This->satEncoder->cnf->solver, getEdgeVar( elemEnc->variables[i] )) )
value |= 1;
}
if (elemEnc->isBinaryValSigned &&
- This->satEncoder->cnf->solver->solution[ getEdgeVar( elemEnc->variables[elemEnc->numVars-1])]) {
+ This->satEncoder->cnf->solver->solution[ getEdgeVar( elemEnc->variables[elemEnc->numVars - 1])]) {
//Do sign extension of negative number
- uint64_t highbits=0xffffffffffffffff - ((1 << (elemEnc->numVars)) - 1);
- value+=highbits;
+ uint64_t highbits = 0xffffffffffffffff - ((1 << (elemEnc->numVars)) - 1);
+ value += highbits;
}
- value+=elemEnc->offset;
+ value += elemEnc->offset;
return value;
}
-uint64_t getElementValueOneHotSATTranslator(CSolver* This, ElementEncoding* elemEnc){
- uint index=0;
- for(uint i=0; i< elemEnc->numVars; i++) {
+uint64_t getElementValueOneHotSATTranslator(CSolver *This, ElementEncoding *elemEnc) {
+ uint index = 0;
+ for (uint i = 0; i < elemEnc->numVars; i++) {
if (getValueSolver(This->satEncoder->cnf->solver, getEdgeVar( elemEnc->variables[i] )))
index = i;
}
- ASSERT(elemEnc->encArraySize >index && isinUseElement(elemEnc, index));
+ ASSERT(elemEnc->encArraySize > index && isinUseElement(elemEnc, index));
return elemEnc->encodingArray[index];
}
-uint64_t getElementValueUnarySATTranslator(CSolver* This, ElementEncoding* elemEnc){
+uint64_t getElementValueUnarySATTranslator(CSolver *This, ElementEncoding *elemEnc) {
uint i;
- for(i=0;i<elemEnc->numVars;i++) {
- if (! getValueSolver(This->satEncoder->cnf->solver, getEdgeVar( elemEnc->variables[i] )) ) {
+ for (i = 0; i < elemEnc->numVars; i++) {
+ if (!getValueSolver(This->satEncoder->cnf->solver, getEdgeVar( elemEnc->variables[i] )) ) {
break;
}
}
return elemEnc->encodingArray[i];
}
-uint64_t getElementValueSATTranslator(CSolver* This, Element* element){
- ElementEncoding* elemEnc = getElementEncoding(element);
- if(elemEnc->numVars == 0) //case when the set has only one item
+uint64_t getElementValueSATTranslator(CSolver *This, Element *element) {
+ ElementEncoding *elemEnc = getElementEncoding(element);
+ if (elemEnc->numVars == 0)//case when the set has only one item
return getSetElement(getElementSet(element), 0);
- switch(elemEnc->type){
- case ONEHOT:
- return getElementValueOneHotSATTranslator(This, elemEnc);
- case UNARY:
- return getElementValueUnarySATTranslator(This, elemEnc);
- case BINARYINDEX:
- return getElementValueBinaryIndexSATTranslator(This, elemEnc);
- case ONEHOTBINARY:
- ASSERT(0);
- break;
- case BINARYVAL:
- ASSERT(0);
- break;
- default:
- ASSERT(0);
- break;
+ switch (elemEnc->type) {
+ case ONEHOT:
+ return getElementValueOneHotSATTranslator(This, elemEnc);
+ case UNARY:
+ return getElementValueUnarySATTranslator(This, elemEnc);
+ case BINARYINDEX:
+ return getElementValueBinaryIndexSATTranslator(This, elemEnc);
+ case ONEHOTBINARY:
+ ASSERT(0);
+ break;
+ case BINARYVAL:
+ ASSERT(0);
+ break;
+ default:
+ ASSERT(0);
+ break;
}
return -1;
}
-bool getBooleanVariableValueSATTranslator( CSolver* This , Boolean* boolean){
- int index = getEdgeVar( ((BooleanVar*) boolean)->var );
+bool getBooleanVariableValueSATTranslator( CSolver *This, Boolean *boolean) {
+ int index = getEdgeVar( ((BooleanVar *) boolean)->var );
return getValueSolver(This->satEncoder->cnf->solver, index);
}
-HappenedBefore getOrderConstraintValueSATTranslator(CSolver* This, Order * order, uint64_t first, uint64_t second){
- ASSERT(order->orderPairTable!= NULL);
- OrderPair pair={first, second, E_NULL};
- Edge var = getOrderConstraint(order->orderPairTable, &pair);
- if(edgeIsNull(var))
+HappenedBefore getOrderConstraintValueSATTranslator(CSolver *This, Order *order, uint64_t first, uint64_t second) {
+ ASSERT(order->orderPairTable != NULL);
+ OrderPair pair = {first, second, E_NULL};
+ Edge var = getOrderConstraint(order->orderPairTable, &pair);
+ if (edgeIsNull(var))
return UNORDERED;
- return getValueCNF(This->satEncoder->cnf, var)? FIRST: SECOND;
+ return getValueCNF(This->satEncoder->cnf, var) ? FIRST : SECOND;
}
-/*
+/*
* File: sattranslator.h
* Author: hamed
*
#include "ops.h"
-bool getBooleanVariableValueSATTranslator( CSolver* This , Boolean* boolean);
-HappenedBefore getOrderConstraintValueSATTranslator(CSolver* This, Order * order, uint64_t first, uint64_t second);
-uint64_t getElementValueBinaryIndexSATTranslator(CSolver* This, ElementEncoding* elemEnc);
-uint64_t getElementValueBinaryValueSATTranslator(CSolver* This, ElementEncoding* elemEnc);
-uint64_t getElementValueOneHotSATTranslator(CSolver* This, ElementEncoding* elemEnc);
-uint64_t getElementValueUnarySATTranslator(CSolver* This, ElementEncoding* elemEnc);
-uint64_t getElementValueSATTranslator(CSolver* This, Element* element);
+bool getBooleanVariableValueSATTranslator( CSolver *This, Boolean *boolean);
+HappenedBefore getOrderConstraintValueSATTranslator(CSolver *This, Order *order, uint64_t first, uint64_t second);
+uint64_t getElementValueBinaryIndexSATTranslator(CSolver *This, ElementEncoding *elemEnc);
+uint64_t getElementValueBinaryValueSATTranslator(CSolver *This, ElementEncoding *elemEnc);
+uint64_t getElementValueOneHotSATTranslator(CSolver *This, ElementEncoding *elemEnc);
+uint64_t getElementValueUnarySATTranslator(CSolver *This, ElementEncoding *elemEnc);
+uint64_t getElementValueSATTranslator(CSolver *This, Element *element);
-#endif /* SATTRANSLATOR_H */
+#endif/* SATTRANSLATOR_H */
#ifndef ARRAY_H
#define ARRAY_H
-#define ArrayDef(name, type) \
- struct Array ## name { \
- type * array; \
- uint size; \
+#define ArrayDef(name, type) \
+ struct Array ## name { \
+ type *array; \
+ uint size; \
}; \
- typedef struct Array ## name Array ## name; \
- static inline Array ## name * allocArray ## name(uint size) { \
- Array ## name * tmp = (Array ## name *)ourmalloc(sizeof(type)); \
- tmp->size = size; \
- tmp->array = (type *) ourcalloc(1, sizeof(type) * size); \
+ typedef struct Array ## name Array ## name; \
+ static inline Array ## name *allocArray ## name(uint size) { \
+ Array ## name * tmp = (Array ## name *)ourmalloc(sizeof(type)); \
+ tmp->size = size; \
+ tmp->array = (type *) ourcalloc(1, sizeof(type) * size); \
return tmp; \
} \
- static inline Array ## name * allocArrayInit ## name(type * array, uint size) { \
- Array ## name * tmp = allocArray ## name(size); \
- memcpy(tmp->array, array, size * sizeof(type)); \
+ static inline Array ## name *allocArrayInit ## name(type * array, uint size) { \
+ Array ## name * tmp = allocArray ## name(size); \
+ memcpy(tmp->array, array, size * sizeof(type)); \
return tmp; \
} \
static inline void removeElementArray ## name(Array ## name * This, uint index) { \
- This->size--; \
- for(;index<This->size;index++) { \
- This->array[index]=This->array[index+1]; \
- } \
- } \
- static inline type getArray ## name(Array ## name * This, uint index) { \
- return This->array[index]; \
- } \
- static inline void setArray ## name(Array ## name * This, uint index, type item) { \
- This->array[index]=item; \
- } \
- static inline uint getSizeArray ## name(Array ## name *This) { \
- return This->size; \
- } \
- static inline void deleteArray ## name(Array ## name *This) { \
- ourfree(This->array); \
- ourfree(This); \
- } \
- static inline type * exposeCArray ## name(Array ## name * This) { \
- return This->array; \
- } \
- static inline void deleteInlineArray ## name(Array ## name *This) { \
- ourfree(This->array); \
- } \
- static inline void initArray ## name(Array ## name * This, uint size) { \
- This->size = size; \
- This->array = (type *) ourcalloc(1, sizeof(type) * size); \
- } \
- static inline void initArrayInit ## name(Array ## name * This, type *array, uint size) { \
- initArray ##name(This, size); \
- memcpy(This->array, array, size * sizeof(type)); \
+ This->size--; \
+ for (; index < This->size; index++) { \
+ This->array[index] = This->array[index + 1]; \
+ } \
+ } \
+ static inline type getArray ## name(Array ## name * This, uint index) { \
+ return This->array[index]; \
+ } \
+ static inline void setArray ## name(Array ## name * This, uint index, type item) { \
+ This->array[index] = item; \
+ } \
+ static inline uint getSizeArray ## name(Array ## name * This) { \
+ return This->size; \
+ } \
+ static inline void deleteArray ## name(Array ## name * This) { \
+ ourfree(This->array); \
+ ourfree(This); \
+ } \
+ static inline type *exposeCArray ## name(Array ## name * This) { \
+ return This->array; \
+ } \
+ static inline void deleteInlineArray ## name(Array ## name * This) { \
+ ourfree(This->array); \
+ } \
+ static inline void initArray ## name(Array ## name * This, uint size) { \
+ This->size = size; \
+ This->array = (type *) ourcalloc(1, sizeof(type) * size); \
+ } \
+ static inline void initArrayInit ## name(Array ## name * This, type * array, uint size) { \
+ initArray ## name(This, size); \
+ memcpy(This->array, array, size * sizeof(type)); \
}
#endif
#define HASH_SET_H
#include "hashtable.h"
-#define HashSetDef(Name, _Key) \
+#define HashSetDef(Name, _Key) \
struct LinkNode ## Name { \
_Key key; \
struct LinkNode ## Name *prev; \
struct HashSet ## Name; \
typedef struct HashSet ## Name HashSet ## Name; \
struct HSIterator ## Name { \
- LinkNode ## Name *curr; \
- LinkNode ## Name *last; \
+ LinkNode ## Name * curr; \
+ LinkNode ## Name * last; \
HashSet ## Name * set; \
}; \
typedef struct HSIterator ## Name HSIterator ## Name; \
- HashTableDef(Name ## Set, _Key, LinkNode ## Name *); \
- HSIterator ## Name * allocHSIterator ## Name(LinkNode ## Name *_curr, HashSet ## Name * _set); \
- void deleteIter ## Name(HSIterator ## Name *hsit); \
- bool hasNext ## Name(HSIterator ## Name *hsit); \
- _Key next ## Name(HSIterator ## Name *hsit); \
- _Key currKey ## Name(HSIterator ## Name *hsit); \
- void removeIter ## Name(HSIterator ## Name *hsit); \
+ HashTableDef(Name ## Set, _Key, LinkNode ## Name *); \
+ HSIterator ## Name * allocHSIterator ## Name(LinkNode ## Name * _curr, HashSet ## Name * _set); \
+ void deleteIter ## Name(HSIterator ## Name * hsit); \
+ bool hasNext ## Name(HSIterator ## Name * hsit); \
+ _Key next ## Name(HSIterator ## Name * hsit); \
+ _Key currKey ## Name(HSIterator ## Name * hsit); \
+ void removeIter ## Name(HSIterator ## Name * hsit); \
struct HashSet ## Name { \
HashTable ## Name ## Set * table; \
- LinkNode ## Name *list; \
- LinkNode ## Name *tail; \
+ LinkNode ## Name * list; \
+ LinkNode ## Name * tail; \
}; \
typedef struct HashSet ## Name HashSet ## Name; \
\
HashSet ## Name * allocHashSet ## Name (unsigned int initialcapacity, double factor); \
- void deleteHashSet ## Name(struct HashSet ## Name * set); \
+ void deleteHashSet ## Name(struct HashSet ## Name *set); \
HashSet ## Name * copyHashSet ## Name(HashSet ## Name * set); \
void resetHashSet ## Name(HashSet ## Name * set); \
bool addHashSet ## Name(HashSet ## Name * set,_Key key); \
#define HashSetImpl(Name, _Key, hash_function, equals) \
HashTableImpl(Name ## Set, _Key, LinkNode ## Name *, hash_function, equals, ourfree); \
- HSIterator ## Name * allocHSIterator ## Name(LinkNode ## Name *_curr, HashSet ## Name * _set) { \
+ HSIterator ## Name * allocHSIterator ## Name(LinkNode ## Name * _curr, HashSet ## Name * _set) { \
HSIterator ## Name * hsit = (HSIterator ## Name *)ourmalloc(sizeof(HSIterator ## Name)); \
- hsit->curr=_curr; \
- hsit->set=_set; \
+ hsit->curr = _curr; \
+ hsit->set = _set; \
return hsit; \
} \
\
- void deleteIter ## Name(HSIterator ## Name *hsit) { \
+ void deleteIter ## Name(HSIterator ## Name * hsit) { \
ourfree(hsit); \
} \
\
- bool hasNext ## Name(HSIterator ## Name *hsit) { \
- return hsit->curr!=NULL; \
+ bool hasNext ## Name(HSIterator ## Name * hsit) { \
+ return hsit->curr != NULL; \
} \
\
- _Key next ## Name(HSIterator ## Name *hsit) { \
- _Key k=hsit->curr->key; \
- hsit->last=hsit->curr; \
- hsit->curr=hsit->curr->next; \
+ _Key next ## Name(HSIterator ## Name * hsit) { \
+ _Key k = hsit->curr->key; \
+ hsit->last = hsit->curr; \
+ hsit->curr = hsit->curr->next; \
return k; \
} \
\
- _Key currKey ## Name(HSIterator ## Name *hsit) { \
+ _Key currKey ## Name(HSIterator ## Name * hsit) { \
return hsit->last->key; \
} \
\
- void removeIter ## Name(HSIterator ## Name *hsit) { \
- _Key k=hsit->last->key; \
+ void removeIter ## Name(HSIterator ## Name * hsit) { \
+ _Key k = hsit->last->key; \
removeHashSet ## Name(hsit->set, k); \
} \
\
HashSet ## Name * allocHashSet ## Name (unsigned int initialcapacity, double factor) { \
HashSet ## Name * set = (HashSet ## Name *)ourmalloc(sizeof(struct HashSet ## Name)); \
- set->table=allocHashTable ## Name ## Set(initialcapacity, factor); \
- set->list=NULL; \
- set->tail=NULL; \
+ set->table = allocHashTable ## Name ## Set(initialcapacity, factor); \
+ set->list = NULL; \
+ set->tail = NULL; \
return set; \
} \
\
- void deleteHashSet ## Name(struct HashSet ## Name * set) { \
- LinkNode ## Name *tmp=set->list; \
- while(tmp!=NULL) { \
- LinkNode ## Name *tmpnext=tmp->next; \
+ void deleteHashSet ## Name(struct HashSet ## Name *set) { \
+ LinkNode ## Name *tmp = set->list; \
+ while (tmp != NULL) { \
+ LinkNode ## Name * tmpnext = tmp->next; \
ourfree(tmp); \
- tmp=tmpnext; \
+ tmp = tmpnext; \
} \
deleteHashTable ## Name ## Set(set->table); \
ourfree(set); \
} \
\
HashSet ## Name * copyHashSet ## Name(HashSet ## Name * set) { \
- HashSet ## Name *copy=allocHashSet ## Name(getCapacity ## Name ## Set(set->table), getLoadFactor ## Name ## Set(set->table)); \
- HSIterator ## Name * it=iterator ## Name(set); \
- while(hasNext ## Name(it)) \
+ HashSet ## Name * copy = allocHashSet ## Name(getCapacity ## Name ## Set(set->table), getLoadFactor ## Name ## Set(set->table)); \
+ HSIterator ## Name * it = iterator ## Name(set); \
+ while (hasNext ## Name(it)) \
addHashSet ## Name(copy, next ## Name(it)); \
deleteIter ## Name(it); \
return copy; \
} \
\
void resetHashSet ## Name(HashSet ## Name * set) { \
- LinkNode ## Name *tmp=set->list; \
- while(tmp!=NULL) { \
- LinkNode ## Name *tmpnext=tmp->next; \
+ LinkNode ## Name * tmp = set->list; \
+ while (tmp != NULL) { \
+ LinkNode ## Name * tmpnext = tmp->next; \
ourfree(tmp); \
- tmp=tmpnext; \
+ tmp = tmpnext; \
} \
- set->list=set->tail=NULL; \
+ set->list = set->tail = NULL; \
reset ## Name ## Set(set->table); \
} \
\
bool addHashSet ## Name(HashSet ## Name * set,_Key key) { \
- LinkNode ## Name * val=get ## Name ## Set(set->table, key); \
- if (val==NULL) { \
- LinkNode ## Name * newnode=(LinkNode ## Name *)ourmalloc(sizeof(struct LinkNode ## Name)); \
- newnode->prev=set->tail; \
- newnode->next=NULL; \
- newnode->key=key; \
- if (set->tail!=NULL) \
- set->tail->next=newnode; \
+ LinkNode ## Name * val = get ## Name ## Set(set->table, key); \
+ if (val == NULL) { \
+ LinkNode ## Name * newnode = (LinkNode ## Name *)ourmalloc(sizeof(struct LinkNode ## Name)); \
+ newnode->prev = set->tail; \
+ newnode->next = NULL; \
+ newnode->key = key; \
+ if (set->tail != NULL) \
+ set->tail->next = newnode; \
else \
- set->list=newnode; \
- set->tail=newnode; \
+ set->list = newnode; \
+ set->tail = newnode; \
put ## Name ## Set(set->table, key, newnode); \
return true; \
} else \
} \
\
_Key getHashSet ## Name(HashSet ## Name * set,_Key key) { \
- LinkNode ## Name * val=get ## Name ## Set(set->table, key); \
- if (val!=NULL) \
+ LinkNode ## Name * val = get ## Name ## Set(set->table, key); \
+ if (val != NULL) \
return val->key; \
else \
return NULL; \
} \
\
bool containsHashSet ## Name(HashSet ## Name * set,_Key key) { \
- return get ## Name ## Set(set->table, key)!=NULL; \
+ return get ## Name ## Set(set->table, key) != NULL; \
} \
\
bool removeHashSet ## Name(HashSet ## Name * set,_Key key) { \
LinkNode ## Name * oldlinknode; \
- oldlinknode=get ## Name ## Set(set->table, key); \
- if (oldlinknode==NULL) { \
+ oldlinknode = get ## Name ## Set(set->table, key); \
+ if (oldlinknode == NULL) { \
return false; \
} \
remove ## Name ## Set(set->table, key); \
\
- if (oldlinknode->prev==NULL) \
- set->list=oldlinknode->next; \
+ if (oldlinknode->prev == NULL) \
+ set->list = oldlinknode->next; \
else \
- oldlinknode->prev->next=oldlinknode->next; \
- if (oldlinknode->next!=NULL) \
- oldlinknode->next->prev=oldlinknode->prev; \
+ oldlinknode->prev->next = oldlinknode->next; \
+ if (oldlinknode->next != NULL) \
+ oldlinknode->next->prev = oldlinknode->prev; \
else \
- set->tail=oldlinknode->prev; \
+ set->tail = oldlinknode->prev; \
ourfree(oldlinknode); \
return true; \
} \
} \
\
bool isEmptyHashSet ## Name(HashSet ## Name * set) { \
- return getSizeHashSet ## Name(set)==0; \
+ return getSizeHashSet ## Name(set) == 0; \
} \
\
HSIterator ## Name * iterator ## Name(HashSet ## Name * set) { \
bool contains ## Name(const HashTable ## Name * tab, _Key key); \
void resize ## Name(HashTable ## Name * tab, unsigned int newsize); \
double getLoadFactor ## Name(HashTable ## Name * tab); \
- unsigned int getCapacity ## Name(HashTable ## Name * tab); \
+ unsigned int getCapacity ## Name(HashTable ## Name * tab); \
void resetAndDeleteHashTable ## Name(HashTable ## Name * tab);
#define HashTableImpl(Name, _Key, _Val, hash_function, equals, freefunction) \
tab->size = 0; \
return tab; &n