1 #include "naiveencoder.h"
2 #include "elementencoding.h"
4 #include "functionencoding.h"
12 #include "tableentry.h"
16 void naiveEncodingDecision(CSolver* This) {
17 for (uint i=0; i < getSizeVectorBoolean(This->constraints); i++) {
18 Boolean* boolean = getVectorBoolean(This->constraints, i);
19 naiveEncodingConstraint(boolean);
23 void naiveEncodingConstraint(Boolean * This) {
24 switch(GETBOOLEANTYPE(This)) {
29 setOrderEncodingType( ((BooleanOrder*)This)->order, PAIRWISE );
33 naiveEncodingLogicOp((BooleanLogic *) This);
37 naiveEncodingPredicate((BooleanPredicate *) This);
45 void naiveEncodingLogicOp(BooleanLogic * This) {
46 for(uint i=0; i < getSizeArrayBoolean(&This->inputs); i++) {
47 naiveEncodingConstraint(getArrayBoolean(&This->inputs, i));
51 void naiveEncodingPredicate(BooleanPredicate * This) {
52 FunctionEncoding *encoding = getPredicateFunctionEncoding(This);
53 if (getFunctionEncodingType(encoding) == FUNC_UNASSIGNED)
54 setFunctionEncodingType(getPredicateFunctionEncoding(This), ENUMERATEIMPLICATIONS);
56 for(uint i=0; i < getSizeArrayElement(&This->inputs); i++) {
57 Element *element=getArrayElement(&This->inputs, i);
58 naiveEncodingElement(element);
62 void naiveEncodingElement(Element * This) {
63 ElementEncoding * encoding = getElementEncoding(This);
64 if (getElementEncodingType(encoding) == ELEM_UNASSIGNED) {
65 setElementEncodingType(encoding, BINARYINDEX);
66 encodingArrayInitialization(encoding);
69 if(GETELEMENTTYPE(This) == ELEMFUNCRETURN) {
70 ElementFunction *function=(ElementFunction *) This;
71 for(uint i=0; i < getSizeArrayElement(&function->inputs); i++) {
72 Element * element=getArrayElement(&function->inputs, i);
73 naiveEncodingElement(element);
75 FunctionEncoding *encoding = getElementFunctionEncoding(function);
76 if (getFunctionEncodingType(encoding) == FUNC_UNASSIGNED)
77 setFunctionEncodingType(getElementFunctionEncoding(function), ENUMERATEIMPLICATIONS);
81 uint getSizeEncodingArray(ElementEncoding *This, uint setSize){
84 return NEXTPOW2(setSize);
94 void encodingArrayInitialization(ElementEncoding *This) {
95 Element * element=This->element;
96 Set * set= getElementSet(element);
97 ASSERT(set->isRange==false);
98 uint size=getSizeVectorInt(set->members);
99 uint encSize=getSizeEncodingArray(This, size);
100 allocEncodingArrayElement(This, encSize);
101 allocInUseArrayElement(This, encSize);
102 for(uint i=0;i<size;i++) {
103 This->encodingArray[i]=getVectorInt(set->members, i);
104 setInUseElement(This, i);