#include "common.h"
#include "ops.h"
#include "element.h"
+#include "set.h"
Edge getElementValueConstraint(SATEncoder* This, Element* elem, uint64_t value) {
switch(getElementEncoding(elem)->type){
Edge getElementValueOneHotConstraint(SATEncoder * This, Element* elem, uint64_t value) {
ASTNodeType type = GETELEMENTTYPE(elem);
- ASSERT(type == ELEMSET || type == ELEMFUNCRETURN);
+ 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->variables[i];
+ return (elemEnc->numVars == 0) ? E_True: elemEnc->variables[i];
}
}
- return E_BOGUS;
+ return E_False;
}
Edge getElementValueUnaryConstraint(SATEncoder * This, Element* elem, uint64_t value) {
getArrayNewVarsSATEncoder(This, encoding->numVars, encoding->variables);
}
-void generateOneHotEncodingVars(SATEncoder *This, ElementEncoding *encoding) {
- allocElementConstraintVariables(encoding, encoding->encArraySize);
+void generateOneHotEncodingVars(SATEncoder *This, ElementEncoding *encoding) {
+ allocElementConstraintVariables(encoding, getSetSize( getElementSet(encoding->element)));
getArrayNewVarsSATEncoder(This, encoding->numVars, encoding->variables);
for(uint i=0;i<encoding->numVars;i++) {
for(uint j=i+1;j<encoding->numVars;j++) {
uint64_t getElementValueBinaryIndexSATTranslator(CSolver* This, ElementEncoding* elemEnc){
uint index=0;
- for(int i=elemEnc->numVars-1;i>=0;i--) {
+ for(uint i=elemEnc->numVars-1;i>=0;i--) {
index=index<<1;
if (getValueSolver(This->satEncoder->cnf->solver, getEdgeVar( elemEnc->variables[i] )))
index |= 1;
uint64_t getElementValueBinaryValueSATTranslator(CSolver* This, ElementEncoding* elemEnc){
uint64_t value=0;
- for(int i=elemEnc->numVars-1;i>=0;i--) {
+ for(uint i=elemEnc->numVars-1;i>=0;i--) {
value=value<<1;
if (getValueSolver(This->satEncoder->cnf->solver, getEdgeVar( elemEnc->variables[i] )) )
value |= 1;
uint64_t getElementValueOneHotSATTranslator(CSolver* This, ElementEncoding* elemEnc){
uint index=0;
- for(int i=elemEnc->numVars-1;i>=0;i--) {
+ for(uint i=0; i< elemEnc->numVars; i++) {
if (getValueSolver(This->satEncoder->cnf->solver, getEdgeVar( elemEnc->variables[i] )))
index = i;
}
return getSetElement(getElementSet(element), 0);
switch(elemEnc->type){
case ONEHOT:
- getElementValueOneHotSATTranslator(This, elemEnc);
- break;
+ return getElementValueOneHotSATTranslator(This, elemEnc);
case UNARY:
- getElementValueUnarySATTranslator(This, elemEnc);
- break;
+ return getElementValueUnarySATTranslator(This, elemEnc);
case BINARYINDEX:
return getElementValueBinaryIndexSATTranslator(This, elemEnc);
case ONEHOTBINARY:
void naiveEncodingElement(Element * This) {
ElementEncoding * encoding = getElementEncoding(This);
if (getElementEncodingType(encoding) == ELEM_UNASSIGNED) {
- setElementEncodingType(encoding, BINARYINDEX);
- baseBinaryIndexElementAssign(encoding);
+ setElementEncodingType(encoding, ONEHOT);
+ encodingArrayInitialization(encoding);
}
if(GETELEMENTTYPE(This) == ELEMFUNCRETURN) {
}
}
-void baseBinaryIndexElementAssign(ElementEncoding *This) {
+void encodingArrayInitialization(ElementEncoding *This) {
Element * element=This->element;
Set * set= getElementSet(element);
ASSERT(set->isRange==false);
void naiveEncodingLogicOp(BooleanLogic * This);
void naiveEncodingPredicate(BooleanPredicate * This);
void naiveEncodingElement(Element * This);
-void baseBinaryIndexElementAssign(ElementEncoding *This);
+void encodingArrayInitialization(ElementEncoding *This);
#endif
* e3= f(e1, e2)
* 1 5 => 7
* 2 3 => 5
+ * 1 7 => 1
+ * 2 7 => 2
+ * 2 5 => 3
+ * 1 3 => 4
* e4 = {6, 10, 19}
* e4 <= e3
- * Result: e1=1, e2=5, e4=6, overflow=0
+ * Result: e1=1, e2=5, e3=7, e4=6, overflow=0
*/
int main(int numargs, char ** argv) {
CSolver * solver=allocCSolver();
Table* t1 = createTable(solver, d1, 2, s2);
uint64_t row1[] = {1, 5};
uint64_t row2[] = {2, 3};
+ uint64_t row3[] = {1, 7};
+ uint64_t row4[] = {2, 7};
+ uint64_t row5[] = {2, 5};
+ uint64_t row6[] = {1, 3};
addTableEntry(solver, t1, row1, 2, 7);
addTableEntry(solver, t1, row2, 2, 5);
+ addTableEntry(solver, t1, row3, 2, 1);
+ addTableEntry(solver, t1, row4, 2, 2);
+ addTableEntry(solver, t1, row5, 2, 3);
+ addTableEntry(solver, t1, row6, 2, 4);
Function * f1 = completeTable(solver, t1, FLAGIFFUNDEFINED);
Element * e3 = applyFunction(solver, f1, (Element* []){e1,e2}, 2, overflow);
addConstraint(solver, pred);
if (startEncoding(solver)==1)
- printf("e1=%llu e2=%llu e4=%llu overFlow:%d\n",
- getElementValue(solver,e1), getElementValue(solver, e2),
+ printf("e1=%llu e2=%llu e3=%llu e4=%llu overFlow:%d\n",
+ getElementValue(solver,e1), getElementValue(solver, e2), getElementValue(solver, e3),
getElementValue(solver, e4), getBooleanValue(solver, overflow));
else
printf("UNSAT\n");
switch(GETELEMENTTYPE(element)){
case ELEMSET:
case ELEMCONST:
+ case ELEMFUNCRETURN:
return getElementValueSATTranslator(This, element);
default:
ASSERT(0);