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 naiveEncodingConstraint(getVectorBoolean(This->constraints, i));
22 void naiveEncodingConstraint(Boolean * This) {
23 switch(GETBOOLEANTYPE(This)) {
28 setOrderEncodingType( ((BooleanOrder*)This)->order, PAIRWISE );
32 naiveEncodingLogicOp((BooleanLogic *) This);
36 naiveEncodingPredicate((BooleanPredicate *) This);
44 void naiveEncodingLogicOp(BooleanLogic * This) {
45 for(uint i=0; i < getSizeArrayBoolean(&This->inputs); i++) {
46 naiveEncodingConstraint(getArrayBoolean(&This->inputs, i));
50 void naiveEncodingPredicate(BooleanPredicate * This) {
51 FunctionEncoding *encoding = getPredicateFunctionEncoding(This);
52 if (getFunctionEncodingType(encoding) == FUNC_UNASSIGNED)
53 setFunctionEncodingType(getPredicateFunctionEncoding(This), ENUMERATEIMPLICATIONS);
55 for(uint i=0; i < getSizeArrayElement(&This->inputs); i++) {
56 Element *element=getArrayElement(&This->inputs, i);
57 naiveEncodingElement(element);
61 void naiveEncodingElement(Element * This) {
62 ElementEncoding * encoding = getElementEncoding(This);
63 if (getElementEncodingType(encoding) == ELEM_UNASSIGNED) {
64 setElementEncodingType(encoding, BINARYINDEX);
65 baseBinaryIndexElementAssign(encoding);
68 if(GETELEMENTTYPE(This) == ELEMFUNCRETURN) {
69 ElementFunction *function=(ElementFunction *) This;
70 for(uint i=0; i < getSizeArrayElement(&function->inputs); i++) {
71 Element * element=getArrayElement(&function->inputs, i);
72 naiveEncodingElement(element);
74 FunctionEncoding *encoding = getElementFunctionEncoding(function);
75 if (getFunctionEncodingType(encoding) == FUNC_UNASSIGNED)
76 setFunctionEncodingType(getElementFunctionEncoding(function), ENUMERATEIMPLICATIONS);
80 void baseBinaryIndexElementAssign(ElementEncoding *This) {
81 Element * element=This->element;
82 Set * set= getElementSet(element);
83 ASSERT(set->isRange==false);
84 uint size=getSizeVectorInt(set->members);
85 uint encSize=NEXTPOW2(size);
86 allocEncodingArrayElement(This, encSize);
87 allocInUseArrayElement(This, encSize);
88 for(uint i=0;i<size;i++) {
89 This->encodingArray[i]=getVectorInt(set->members, i);
90 setInUseElement(This, i);