return CCSOLVER(solver)->applyExactlyOneConstraint( constr, (uint) asize).getRaw();
}
+void *applyAtMostOneConstraint(void *solver, void **array, unsigned int asize) {
+ BooleanEdge constr [asize];
+ for (uint i = 0; i < asize; i++) {
+ constr[i] = BooleanEdge((Boolean *)array[i]);
+ }
+ return CCSOLVER(solver)->applyAtMostOneConstraint( constr, (uint) asize).getRaw();
+}
+
void *applyLogicalOperationTwo(void *solver,unsigned int op, void *arg1, void *arg2) {
return CCSOLVER(solver)->applyLogicalOperation((LogicOp) op, BooleanEdge((Boolean *) arg1), BooleanEdge((Boolean *) arg2)).getRaw();
}
void *applyPredicate(void *solver,void *predicate, void **inputs, unsigned int numInputs);
void *applyLogicalOperation(void *solver,unsigned int op, void **array, unsigned int asize);
void *applyExactlyOneConstraint(void *solver,void **array, unsigned int asize);
+void *applyAtMostOneConstraint(void *solver,void **array, unsigned int asize);
void *applyLogicalOperationTwo(void *solver,unsigned int op, void *arg1, void *arg2);
void *applyLogicalOperationOne(void *solver,unsigned int op, void *arg);
void addConstraint(void *solver,void *constraint);
return applyLogicalOperation(op, newarray, asize);
}
-BooleanEdge CSolver::applyExactlyOneConstraint (BooleanEdge *array, uint asize) {
- BooleanEdge newarray[asize + 1];
-
- newarray[asize] = applyLogicalOperation(SATC_OR, array, asize);
- for (uint i = 0; i < asize; i++) {
- BooleanEdge oprand1 = array[i];
- BooleanEdge carray [asize - 1];
- uint index = 0;
- for ( uint j = 0; j < asize; j++) {
- if (i != j) {
- BooleanEdge oprand2 = applyLogicalOperation(SATC_NOT, array[j]);
- carray[index++] = applyLogicalOperation(SATC_IMPLIES, oprand1, oprand2);
- }
+BooleanEdge CSolver::applyAtMostOneConstraint (BooleanEdge *array, uint asize) {
+ if(asize == 0 || asize == 1){
+ return getBooleanTrue();
+ }
+ BooleanEdge newarray[asize*(asize-1)];
+ uint newsize = 0;
+ for (uint i = 0; i < asize -1; i++) {
+ for(uint j = i +1; j < asize; j++){
+ BooleanEdge oprand1 = array[i];
+ BooleanEdge oprand2 = applyLogicalOperation(SATC_NOT, array[j]);
+ newarray[newsize++] = applyLogicalOperation(SATC_IMPLIES, oprand1, oprand2);
}
- ASSERT(index == asize - 1);
- newarray[i] = applyLogicalOperation(SATC_AND, carray, asize - 1);
}
- return applyLogicalOperation(SATC_AND, newarray, asize + 1);
+ return applyLogicalOperation(SATC_AND, newarray, newsize);
+}
+
+BooleanEdge CSolver::applyExactlyOneConstraint (BooleanEdge *array, uint asize) {
+ BooleanEdge atleastOne = applyLogicalOperation(SATC_OR, array, asize);
+ BooleanEdge atmostOne = applyAtMostOneConstraint (array, asize);
+ return applyLogicalOperation(SATC_AND, atleastOne, atmostOne);
}
BooleanEdge CSolver::applyLogicalOperation(LogicOp op, BooleanEdge *array, uint asize) {
- if (!useInterpreter()) {
+ if (!useInterpreter() && !optimizationsOff) {
BooleanEdge newarray[asize];
switch (op) {
case SATC_NOT: {
}
}
Boolean *constraint = new BooleanOrder(order, first, second);
- if (!useInterpreter() ) {
+ if (!useInterpreter() && !optimizationsOff ) {
Boolean *b = boolMap.get(constraint);
if (b == NULL) {
/** This exactly one element of array can be true! (i.e. a1 + a2 + a3 + ... + an = 1)*/
BooleanEdge applyExactlyOneConstraint (BooleanEdge *array, uint asize);
+
+ /** This exactly one element of array can be true! (i.e. a1 => !a2 & !a3 & ... & !an)*/
+ BooleanEdge applyAtMostOneConstraint (BooleanEdge *array, uint asize);
/** This function applies a logical operation to the Booleans in its input. */
csolverlb.getElementRange.restype = c_void_p
csolverlb.getBooleanVar.argtypes = [c_void_p, c_uint]
csolverlb.getBooleanVar.restype = c_void_p
+ csolverlb.getBooleanTrue.argtypes = [c_void_p]
+ csolverlb.getBooleanTrue.restype = c_void_p
+ csolverlb.getBooleanFalse.argtypes = [c_void_p]
+ csolverlb.getBooleanFalse.restype = c_void_p
csolverlb.createFunctionOperator.argtypes = [c_void_p, c_uint, c_void_p, c_uint]
csolverlb.createFunctionOperator.restype = c_void_p
csolverlb.createPredicateOperator.argtypes = [c_void_p, c_uint]
csolverlb.applyLogicalOperation.restype = c_void_p
csolverlb.applyExactlyOneConstraint.argtypes = [c_void_p, c_void_p, c_uint]
csolverlb.applyExactlyOneConstraint.restype = c_void_p
+ csolverlb.applyAtMostOneConstraint.argtypes = [c_void_p, c_void_p, c_uint]
+ csolverlb.applyAtMostOneConstraint.restype = c_void_p
csolverlb.applyLogicalOperationTwo.argtypes = [c_void_p, c_uint, c_void_p, c_void_p]
csolverlb.applyLogicalOperationTwo.restype = c_void_p
csolverlb.applyLogicalOperationOne.argtypes = [c_void_p, c_uint, c_void_p]