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) :
11 type(ELEM_UNASSIGNED),
19 encoding(EENC_UNKNOWN),
23 ElementEncoding::~ElementEncoding() {
24 if (variables != NULL)
26 if (encodingArray != NULL)
27 ourfree(encodingArray);
28 if (inUseArray != NULL)
30 if (edgeArray != NULL)
32 if (polarityArray != NULL)
33 ourfree(polarityArray);
36 void ElementEncoding::allocEncodingArrayElement(uint size) {
37 encodingArray = (uint64_t *) ourcalloc(1, sizeof(uint64_t) * size);
41 void ElementEncoding::allocInUseArrayElement(uint size) {
42 uint bytes = ((size + 63) >> 3) & ~7; //Depends on size of inUseArray
43 inUseArray = (uint64_t *) ourcalloc(1, bytes);
46 void ElementEncoding::setElementEncodingType(ElementEncodingType _type) {
50 void ElementEncoding::encodingArrayInitialization() {
51 Set *set = element->getRange();
52 uint size = set->getSize();
53 uint encSize = getSizeEncodingArray(size);
54 allocEncodingArrayElement(encSize);
55 allocInUseArrayElement(encSize);
56 for (uint i = 0; i < size; i++) {
57 encodingArray[i] = set->getElement(i);
62 void ElementEncoding::print() {
63 model_print("%s ", elemEncTypeNames[type]);
64 if (type == BINARYINDEX) {
65 for (uint i = 0; i < encArraySize; i++) {
68 if (isinUseElement(i))
69 model_print("%" PRIu64 "", encodingArray[i]);