1 #include "elementencoding.h"
3 #include "naiveencoder.h"
5 #include "satencoder.h"
8 const char *elemEncTypeNames[] = {"UNASSIGNED", "ONEHOT", "UNARY", "BINARYINDEX", "BINARYVAL"};
10 ElementEncoding::ElementEncoding(Element *_element) :
12 type(ELEM_UNASSIGNED),
20 encoding(EENC_UNKNOWN),
24 ElementEncoding::~ElementEncoding() {
25 if (variables != NULL)
27 if (encodingArray != NULL)
28 ourfree(encodingArray);
29 if (inUseArray != NULL)
31 if (edgeArray != NULL)
33 if (polarityArray != NULL)
34 ourfree(polarityArray);
37 void ElementEncoding::allocEncodingArrayElement(uint size) {
38 encodingArray = (uint64_t *) ourcalloc(1, sizeof(uint64_t) * size);
42 void ElementEncoding::allocInUseArrayElement(uint size) {
43 uint bytes = ((size + 63) >> 3) & ~7; //Depends on size of inUseArray
44 inUseArray = (uint64_t *) ourcalloc(1, bytes);
47 void ElementEncoding::setElementEncodingType(ElementEncodingType _type) {
51 void ElementEncoding::encodingArrayInitialization() {
52 Set *set = element->getRange();
53 uint size = set->getSize();
54 uint encSize = getSizeEncodingArray(size);
55 allocEncodingArrayElement(encSize);
56 allocInUseArrayElement(encSize);
57 for (uint i = 0; i < size; i++) {
58 encodingArray[i] = set->getElement(i);
63 void ElementEncoding::print() {
64 model_print("%s ", elemEncTypeNames[type]);
65 if (type == BINARYINDEX) {
66 for (uint i = 0; i < encArraySize; i++) {
69 if (isinUseElement(i))
70 model_print("%" PRIu64 "", encodingArray[i]);