enum BooleanValue {BV_UNDEFINED=0, BV_MUSTBETRUE=1, BV_MUSTBEFALSE=2, BV_UNSAT=3};
typedef enum BooleanValue BooleanValue;
+enum ElementEncodingType {
+ ELEM_UNASSIGNED, ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
+};
+
+typedef enum ElementEncodingType ElementEncodingType;
+
+
#endif
#include "function.h"
#include "predicate.h"
#include "set.h"
+#include "csolver.h"
+#include "tunable.h"
EncodingGraph::EncodingGraph(CSolver * _solver) :
solver(_solver) {
return s->getSize();
}
+VarType EncodingNode::getType() {
+ return s->getType();
+}
+
+//ELEM_UNASSIGNED, ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
+
+static TunableDesc NodeEncodingType(ELEM_UNASSIGNED, BINARYVAL, ELEM_UNASSIGNED);
+
EncodingNode * EncodingGraph::createNode(Element *e) {
if (e->type == ELEMCONST)
return NULL;
EncodingNode *n = encodingMap.get(s);
if (n == NULL) {
n = new EncodingNode(s);
+ n->setEncoding((ElementEncodingType)solver->getTuner()->getVarTunable(n->getType(), NODEENCODING, &NodeEncodingType));
encodingMap.put(s, n);
}
n->addElement(e);
EncodingNode(Set *_s);
void addElement(Element *e);
uint getSize();
+ VarType getType();
+ void setEncoding(ElementEncodingType e) {encoding=e;}
+
CMEMALLOC;
private:
Set *s;
HashsetElement elements;
uint numElements;
+ ElementEncodingType encoding;
friend class EncodingGraph;
};
#include "naiveencoder.h"
#include "constraint.h"
-enum ElementEncodingType {
- ELEM_UNASSIGNED, ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
-};
-
-typedef enum ElementEncodingType ElementEncodingType;
-
class ElementEncoding {
public:
ElementEncoding(Element *element);
TunableSetting::TunableSetting(VarType _type, TunableParam _param) :
hasVar(true),
- type(_type),
+ type1(_type),
+ type2(0),
+ param(_param) {
+}
+
+TunableSetting::TunableSetting(VarType _type1, VarType _type2, TunableParam _param) :
+ hasVar(true),
+ type1(_type1),
+ type2(_type2),
param(_param) {
}
TunableSetting::TunableSetting(TunableParam _param) :
hasVar(false),
- type(0),
+ type1(0),
+ type2(0),
param(_param) {
}
TunableSetting::TunableSetting(TunableSetting *ts) :
hasVar(ts->hasVar),
- type(ts->type),
+ type1(ts->type1),
+ type2(ts->type2),
param(ts->param),
lowValue(ts->lowValue),
highValue(ts->highValue),
void TunableSetting::print() {
if (hasVar) {
- model_print("Type %" PRIu64 ", ", type);
+ model_print("Type1 %" PRIu64 ", ", type1);
+ model_print("Type2 %" PRIu64 ", ", type2);
}
model_print("Param %u = %u\n", param, selectedValue);
}
unsigned int tunableSettingHash(TunableSetting *setting) {
- return setting->hasVar ^ setting->type ^ setting->param;
+ return setting->hasVar ^ setting->type1 ^ setting->type2 ^ setting->param;
}
bool tunableSettingEquals(TunableSetting *setting1, TunableSetting *setting2) {
return setting1->hasVar == setting2->hasVar &&
- setting1->type == setting2->type &&
- setting1->param == setting2->param;
+ setting1->type1 == setting2->type1 &&
+ setting1->type2 == setting2->type2 &&
+ setting1->param == setting2->param;
}
SearchTuner::SearchTuner() {
}
int SearchTuner::getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor) {
- TunableSetting setting(vartype, param);
+ return getVarTunable(vartype, 0, param, descriptor);
+}
+
+int SearchTuner::getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor) {
+ TunableSetting setting(vartype1, vartype2, param);
TunableSetting *result = usedSettings.get(&setting);
if (result == NULL) {
result = settings.get(&setting);
if ( result == NULL) {
- result = new TunableSetting(vartype, param);
+ result = new
+ TunableSetting(vartype1, vartype2, param);
uint value = descriptor->lowValue + (random() % (1 + descriptor->highValue - descriptor->lowValue));
result->setDecision(descriptor->lowValue, descriptor->highValue, descriptor->defaultValue, value);
settings.add(result);
class TunableSetting {
public:
TunableSetting(VarType type, TunableParam param);
+ TunableSetting(VarType type1, VarType type2, TunableParam param);
TunableSetting(TunableParam param);
TunableSetting(TunableSetting *ts);
void setDecision(int _low, int _high, int _default, int _selection);
CMEMALLOC;
private:
bool hasVar;
- VarType type;
+ VarType type1;
+ VarType type2;
TunableParam param;
int lowValue;
int highValue;
~SearchTuner();
int getTunable(TunableParam param, TunableDesc *descriptor);
int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor);
+ int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
SearchTuner *copyUsed();
void randomMutate();
uint getSize() { return usedSettings.getSize();}
int DefaultTuner::getTunable(TunableParam param, TunableDesc *descriptor) {
return descriptor->defaultValue;
}
+
int DefaultTuner::getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor) {
return descriptor->defaultValue;
}
+
+int DefaultTuner::getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor) {
+ return descriptor->defaultValue;
+}
public:
virtual int getTunable(TunableParam param, TunableDesc *descriptor) {ASSERT(0); return 0;}
virtual int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor) {ASSERT(0); return 0;}
+ virtual int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor) {ASSERT(0); return 0;}
virtual ~Tuner() {}
CMEMALLOC;
};
DefaultTuner();
int getTunable(TunableParam param, TunableDesc *descriptor);
int getVarTunable(VarType vartype, TunableParam param, TunableDesc *descriptor);
+ int getVarTunable(VarType vartype1, VarType vartype2, TunableParam param, TunableDesc *descriptor);
CMEMALLOC;
};
static TunableDesc onoff(0, 1, 1);
static TunableDesc offon(0, 1, 0);
-enum Tunables {DECOMPOSEORDER, MUSTREACHGLOBAL, MUSTREACHLOCAL, MUSTREACHPRUNE, OPTIMIZEORDERSTRUCTURE, ORDERINTEGERENCODING, PREPROCESS};
+enum Tunables {DECOMPOSEORDER, MUSTREACHGLOBAL, MUSTREACHLOCAL, MUSTREACHPRUNE, OPTIMIZEORDERSTRUCTURE, ORDERINTEGERENCODING, PREPROCESS, NODEENCODING};
typedef enum Tunables Tunables;
#endif