}
/** Generates a constraint to ensure that all encodings are less than value */
-Edge generateLTConstraint(CNF *cnf, uint numvars, Edge *vars, uint value) {
+Edge generateLTValueConstraint(CNF *cnf, uint numvars, Edge *vars, uint value) {
Edge orarray[numvars];
Edge andarray[numvars];
uint andi = 0;
}
return constraintAND(cnf, numvars, array);
}
+
+Edge generateLTConstraint(CNF *cnf, uint numvars, Edge *var1, Edge *var2){
+ if(numvars == 0 )
+ return E_True;
+ Edge result =constraintAND2(cnf, constraintNegate( var1[0]), var2[0]);
+ for (uint i = 1; i < numvars; i++) {
+ Edge lt = constraintAND2(cnf, constraintNegate( var1[i]), var2[i]);
+ Edge eq = constraintAND2(cnf, constraintIFF(cnf, var1[i], var2[i]), result);
+ result = constraintOR2(cnf, lt, eq);
+ }
+ return result;
+}
\ No newline at end of file
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 generateLTValueConstraint(CNF *cnf, uint numvars, Edge *vars, uint value);
Edge generateEquivNVConstraint(CNF *cnf, uint numvars, Edge *var1, Edge *var2);
+Edge generateLTConstraint(CNF *cnf, uint numvars, Edge *var1, Edge *var2);
extern Edge E_True;
extern Edge E_False;
Edge encodeCircuitOperatorPredicateEncoder(SATEncoder *This, BooleanPredicate *constraint) {
PredicateOperator *predicate = (PredicateOperator *) constraint->predicate;
-
- switch (predicate->op) {
- case EQUALS: {
- return encodeCircuitEquals(This, constraint);
- }
- default:
- ASSERT(0);
- }
- exit(-1);
-}
-
-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);
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]);
+ switch (predicate->op) {
+ case EQUALS:
+ return generateEquivNVConstraint(This->cnf, numVars, ee0->variables, ee1->variables);
+ case LT:
+ return generateLTConstraint(This->cnf, numVars, ee0->variables, ee1->variables);
+ case GT:
+ return generateLTConstraint(This->cnf, numVars, ee1->variables, ee0->variables);
+ default:
+ ASSERT(0);
}
- return constraintAND(This->cnf, numVars, carray);
+ exit(-1);
}
+
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