Merge branch 'master' into brian
[satune.git] / src / Encoders / naiveencoder.c
1 #include "naiveencoder.h"
2 #include "elementencoding.h"
3 #include "element.h"
4 #include "functionencoding.h"
5 #include "function.h"
6 #include "set.h"
7 #include "common.h"
8 #include "structs.h"
9 #include "csolver.h"
10 #include "boolean.h"
11 #include "table.h"
12 #include "tableentry.h"
13 #include "order.h"
14 #include <strings.h>
15
16
17 void naiveEncodingDecision(CSolver* csolver){
18         uint size = getSizeVectorElement(csolver->allElements);
19         for(uint i=0; i<size; i++){
20                 Element* element = getVectorElement(csolver->allElements, i);
21                 //Whether it's a ElementFunction or ElementSet we should do the followings:
22                 setElementEncodingType(getElementEncoding(element), BINARYINDEX);
23                 baseBinaryIndexElementAssign(getElementEncoding(element));
24                 if(GETELEMENTTYPE(element) == ELEMFUNCRETURN){
25                         setFunctionEncodingType(getElementFunctionEncoding((ElementFunction*)element),
26                                 ENUMERATEIMPLICATIONS);
27                 }
28         }
29         
30         size = getSizeVectorBoolean(csolver->allBooleans);
31         for(uint i=0; i<size; i++){
32                 Boolean* boolean = getVectorBoolean(csolver->allBooleans, i);
33                 switch(GETBOOLEANTYPE(boolean)){
34                         case PREDICATEOP:
35                                 setFunctionEncodingType(getPredicateFunctionEncoding((BooleanPredicate*)boolean),
36                                         ENUMERATEIMPLICATIONS);
37                                 break;
38                         case ORDERCONST:
39                                 setOrderEncodingType( ((BooleanOrder*)boolean)->order, PAIRWISE );
40                                 break;
41                         default:
42                                 continue;
43                 } 
44         }
45 }
46
47 void baseBinaryIndexElementAssign(ElementEncoding *This) {
48         Element * element=This->element;
49         Set * set= getElementSet(element);
50         ASSERT(set->isRange==false);
51         uint size=getSizeVectorInt(set->members);
52         uint encSize=NEXTPOW2(size);
53         allocEncodingArrayElement(This, encSize);
54         allocInUseArrayElement(This, encSize);
55         for(uint i=0;i<size;i++) {
56                 This->encodingArray[i]=getVectorInt(set->members, i);
57                 setInUseElement(This, i);
58         }
59 }
60
61