1 #include "naiveencoder.h"
2 #include "elementencoding.h"
4 #include "functionencoding.h"
12 #include "tableentry.h"
16 void naiveEncodingDecision(CSolver *This) {
17 HSIteratorBoolean *iterator=iteratorBoolean(This->constraints);
18 while(hasNextBoolean(iterator)) {
19 Boolean *boolean = nextBoolean(iterator);
20 naiveEncodingConstraint(boolean);
22 deleteIterBoolean(iterator);
25 void naiveEncodingConstraint(Boolean *This) {
26 switch (GETBOOLEANTYPE(This)) {
31 setOrderEncodingType( ((BooleanOrder *)This)->order, PAIRWISE );
35 naiveEncodingLogicOp((BooleanLogic *) This);
39 naiveEncodingPredicate((BooleanPredicate *) This);
47 void naiveEncodingLogicOp(BooleanLogic *This) {
48 for (uint i = 0; i < getSizeArrayBoolean(&This->inputs); i++) {
49 naiveEncodingConstraint(getArrayBoolean(&This->inputs, i));
53 void naiveEncodingPredicate(BooleanPredicate *This) {
54 FunctionEncoding *encoding = getPredicateFunctionEncoding(This);
55 if (getFunctionEncodingType(encoding) == FUNC_UNASSIGNED)
56 setFunctionEncodingType(getPredicateFunctionEncoding(This), ENUMERATEIMPLICATIONS);
58 for (uint i = 0; i < getSizeArrayElement(&This->inputs); i++) {
59 Element *element = getArrayElement(&This->inputs, i);
60 naiveEncodingElement(element);
64 void naiveEncodingElement(Element *This) {
65 ElementEncoding *encoding = getElementEncoding(This);
66 if (getElementEncodingType(encoding) == ELEM_UNASSIGNED) {
67 setElementEncodingType(encoding, BINARYINDEX);
68 encodingArrayInitialization(encoding);
71 if (GETELEMENTTYPE(This) == ELEMFUNCRETURN) {
72 ElementFunction *function = (ElementFunction *) This;
73 for (uint i = 0; i < getSizeArrayElement(&function->inputs); i++) {
74 Element *element = getArrayElement(&function->inputs, i);
75 naiveEncodingElement(element);
77 FunctionEncoding *encoding = getElementFunctionEncoding(function);
78 if (getFunctionEncodingType(encoding) == FUNC_UNASSIGNED)
79 setFunctionEncodingType(getElementFunctionEncoding(function), ENUMERATEIMPLICATIONS);
83 uint getSizeEncodingArray(ElementEncoding *This, uint setSize) {
86 return NEXTPOW2(setSize);
96 void encodingArrayInitialization(ElementEncoding *This) {
97 Element *element = This->element;
98 Set *set = getElementSet(element);
99 ASSERT(set->isRange == false);
100 uint size = getSizeVectorInt(set->members);
101 uint encSize = getSizeEncodingArray(This, size);
102 allocEncodingArrayElement(This, encSize);
103 allocInUseArrayElement(This, encSize);
104 for (uint i = 0; i < size; i++) {
105 This->encodingArray[i] = getVectorInt(set->members, i);
106 setInUseElement(This, i);