Element::Element(ASTNodeType _type) :
ASTNode(_type),
encoding(this),
- anyValue(false){
+ anyValue(false) {
}
ElementSet::ElementSet(Set *s) :
}
Element *ElementConst::clone(CSolver *solver, CloneMap *map) {
- Element* e= solver->getElementConst(type, value);
+ Element *e = solver->getElementConst(type, value);
e->anyValue = anyValue;
return e;
}
virtual void updateParents() {}
virtual Set *getRange() = 0;
CMEMALLOC;
- bool anyValue;
+ bool anyValue;
};
class ElementSet : public Element {
void EncodingGraph::validate() {
- SetIteratorBooleanEdge* it= solver->getConstraints();
- while(it->hasNext()){
+ SetIteratorBooleanEdge *it = solver->getConstraints();
+ while (it->hasNext()) {
BooleanEdge be = it->next();
- if(be->type == PREDICATEOP){
+ if (be->type == PREDICATEOP) {
BooleanPredicate *b = (BooleanPredicate *)be.getBoolean();
- if(b->predicate->type == OPERATORPRED){
- PredicateOperator* predicate = (PredicateOperator*) b->predicate;
- if(predicate->getOp() == SATC_EQUALS){
+ if (b->predicate->type == OPERATORPRED) {
+ PredicateOperator *predicate = (PredicateOperator *) b->predicate;
+ if (predicate->getOp() == SATC_EQUALS) {
ASSERT(b->inputs.getSize() == 2);
- Element* e1= b->inputs.get(0);
- Element* e2= b->inputs.get(1);
- if(e1->type == ELEMCONST || e1->type == ELEMCONST)
+ Element *e1 = b->inputs.get(0);
+ Element *e2 = b->inputs.get(1);
+ if (e1->type == ELEMCONST || e1->type == ELEMCONST)
continue;
ElementEncoding *enc1 = e1->getElementEncoding();
ElementEncoding *enc2 = e2->getElementEncoding();
ASSERT(enc1->getElementEncodingType() != ELEM_UNASSIGNED);
ASSERT(enc2->getElementEncodingType() != ELEM_UNASSIGNED);
- if(enc1->getElementEncodingType() == enc2->getElementEncodingType() && enc1->getElementEncodingType() == BINARYINDEX && b->getFunctionEncoding()->type == CIRCUIT){
- for(uint i=0; i<enc1->encArraySize; i++){
- if(enc1->isinUseElement(i)){
+ if (enc1->getElementEncodingType() == enc2->getElementEncodingType() && enc1->getElementEncodingType() == BINARYINDEX && b->getFunctionEncoding()->type == CIRCUIT) {
+ for (uint i = 0; i < enc1->encArraySize; i++) {
+ if (enc1->isinUseElement(i)) {
uint64_t val1 = enc1->encodingArray[i];
- if(enc2->isinUseElement(i)){
+ if (enc2->isinUseElement(i)) {
ASSERT(val1 == enc2->encodingArray[i]);
- }else{
- for(uint j=0; j< enc2->encArraySize; j++){
- if(enc2->isinUseElement(j)){
+ } else {
+ for (uint j = 0; j < enc2->encArraySize; j++) {
+ if (enc2->isinUseElement(j)) {
ASSERT(val1 != enc2->encodingArray[j]);
}
}
}
}
//Now make sure that all the elements in the set are appeared in the encoding array!
- for(uint k=0; k< b->inputs.getSize(); k++){
+ for (uint k = 0; k < b->inputs.getSize(); k++) {
Element *e = b->inputs.get(k);
ElementEncoding *enc = e->getElementEncoding();
Set *s = e->getRange();
for (uint i = 0; i < s->getSize(); i++) {
uint64_t value = s->getElement(i);
- bool exist=false;
- for(uint j=0; j< enc->encArraySize; j++){
- if(enc->isinUseElement(j) && enc->encodingArray[j] == value){
+ bool exist = false;
+ for (uint j = 0; j < enc->encArraySize; j++) {
+ if (enc->isinUseElement(j) && enc->encodingArray[j] == value) {
exist = true;
break;
}
ASSERT(encoding->isinUseElement(encodingIndex));
encoding->encodingArray[encodingIndex] = value;
}
- } else{
+ } else {
model_print("DAMN in encode()\n");
e->print();
}
first->setEncoding(BINARYINDEX);
if (graph2 == NULL)
second->setEncoding(BINARYINDEX);
-
+
if (graph1 == NULL && graph2 == NULL) {
graph1 = new EncodingSubGraph();
subgraphs.add(graph1);
EncodingSubGraph *tmpsg = leftGraph; leftGraph = rightGraph; rightGraph = tmpsg;
}
//model_print("Right=%p RGraph=%p\tLeft=%p LGraph=%p\n", right, rightGraph, left, leftGraph);
- uint leftSize = 0, rightSize = 0, newSize = 0, max=0;
+ uint leftSize = 0, rightSize = 0, newSize = 0, max = 0;
uint64_t totalCost = 0;
bool merge = false;
// model_print("**************decideEdge*************\n");
// model_print("LeftNode Size = %u\n", left->getSize());
// model_print("rightNode Size = %u\n", right->getSize());
// model_print("UnionSize = %u\n", left->s->getUnionSize(right->s));
-
+
if (leftGraph == NULL && rightGraph == NULL) {
leftSize = convertSize(left->getSize());
rightSize = convertSize(right->getSize());
totalCost = (newSize - leftSize) * left->elements.getSize() +
(newSize - rightSize) * right->elements.getSize();
//model_print("leftSize=%u\trighSize=%u\tnewSize=%u\n", leftSize, rightSize, newSize);
- max = rightSize > leftSize? rightSize : leftSize;
- if(newSize == max){
+ max = rightSize > leftSize ? rightSize : leftSize;
+ if (newSize == max) {
merge = true;
}
} else if (leftGraph != NULL && rightGraph == NULL) {
totalCost = (newSize - leftSize) * leftGraph->numElements +
(newSize - rightSize) * right->elements.getSize();
//model_print("leftSize=%u\trighSize=%u\tnewSize=%u\n", leftSize, rightSize, newSize);
- max = rightSize > leftSize? rightSize : leftSize;
- if(newSize == max){
+ max = rightSize > leftSize ? rightSize : leftSize;
+ if (newSize == max) {
merge = true;
}
} else {
// model_print("LeftGraph size=%u\n", leftGraph->encodingSize);
// model_print("RightGraph size=%u\n", rightGraph->encodingSize);
// model_print("UnionGraph size = %u\n", leftGraph->estimateNewSize(rightGraph));
- if(rightSize < 64 && leftSize < 64){
+ if (rightSize < 64 && leftSize < 64) {
merge = true;
}
}
#include "structs.h"
#include "graphstructs.h"
-#define FUDGEFACTOR 1.2
+#define FUDGEFACTOR 1.2
#define CONVERSIONFACTOR 0.5
class EncodingGraph {
}
}
-void addClause(CNF *cnf, uint numliterals, int *literals){
+void addClause(CNF *cnf, uint numliterals, int *literals) {
cnf->clausecount++;
addArrayClauseLiteral(cnf->solver, numliterals, literals);
}
struct CNF {
uint varcount;
- uint clausecount;
+ uint clausecount;
uint asize;
IncrementalSolver *solver;
int *array;
};
};
uint numVars; /* Number of variables */
- CMEMALLOC;
+ CMEMALLOC;
};
void naiveEncodingElement(Element *This) {
ElementEncoding *encoding = This->getElementEncoding();
if (encoding->getElementEncodingType() == ELEM_UNASSIGNED) {
- if(This->type != ELEMCONST){
+ if (This->type != ELEMCONST) {
model_print("INFO: naive encoder is making the decision about element %p....\n", This);
}
encoding->setElementEncodingType(UNARY);
try{
return solver->solve();
}
- catch(std::runtime_error& e) {
+ catch (std::runtime_error &e) {
return UNSETVALUE;
}
}
int retValue;
std::thread t([&cv, &retValue, solver]()
- {
- retValue = solve(solver);
- cv.notify_one();
- });
+ {
+ retValue = solve(solver);
+ cv.notify_one();
+ });
t.detach();
{
std::unique_lock<std::mutex> l(m);
- if(cv.wait_for(l, TIMEOUT) == std::cv_status::timeout)
+ if (cv.wait_for(l, TIMEOUT) == std::cv_status::timeout)
throw std::runtime_error("Timeout");
}
}
metric = copy->getElapsedTime();
}
- catch(std::runtime_error& e) {
+ catch (std::runtime_error &e) {
metric = POSINFINITY;
model_print("TimeOut has hit\n");
}
-
+
delete copy;
return metric;
}
setting1->param == setting2->param;
}
-ostream& operator<<(ostream& os, const TunableSetting& ts)
-{
- os << ts.hasVar <<" " << ts.type1 <<" " << ts.type2 << " " << ts.param << " " << ts.lowValue <<" "
- << ts.highValue << " " << ts.defaultValue << " " << ts.selectedValue;
- return os;
-}
+ostream &operator<<(ostream &os, const TunableSetting &ts)
+{
+ os << ts.hasVar << " " << ts.type1 << " " << ts.type2 << " " << ts.param << " " << ts.lowValue << " "
+ << ts.highValue << " " << ts.defaultValue << " " << ts.selectedValue;
+ return os;
+}
SearchTuner::SearchTuner() {
ifstream myfile;
myfile.open (TUNEFILE, ios::in);
- if(myfile.is_open()){
+ if (myfile.is_open()) {
bool hasVar;
VarType type1;
VarType type2;
int highValue;
int defaultValue;
int selectedValue;
- while(myfile >> hasVar >> type1 >> type2 >> param >> lowValue >> highValue >> defaultValue >> selectedValue){
+ while (myfile >> hasVar >> type1 >> type2 >> param >> lowValue >> highValue >> defaultValue >> selectedValue) {
TunableSetting *setting;
-
- if(hasVar){
+
+ if (hasVar) {
setting = new TunableSetting(type1, type2, param);
- }else{
+ } else {
setting = new TunableSetting(param);
}
setting->setDecision(lowValue, highValue, defaultValue, selectedValue);
TunableSetting(TunableSetting *ts);
void setDecision(int _low, int _high, int _default, int _selection);
void print();
- friend std::ostream& operator<< (std::ostream& stream, const TunableSetting& matrix);
+ friend std ::ostream &operator<< (std::ostream &stream, const TunableSetting &matrix);
CMEMALLOC;
private:
bool hasVar;
uint getSize() { return usedSettings.getSize();}
void print();
void printUsed();
- void serialize();
-
+ void serialize();
+
CMEMALLOC;
private:
/** Used Settings keeps track of settings that were actually used by
return descriptor->defaultValue;
}
-const char* tunableParameterToString(Tunables tunable){
- switch(tunable){
- case DECOMPOSEORDER:
- return "DECOMPOSEORDER";
- case MUSTREACHGLOBAL:
- return "MUSTREACHGLOBAL";
- case MUSTREACHLOCAL:
- return "MUSTREACHLOCAL";
- case MUSTREACHPRUNE:
- return "MUSTREACHPRUNE";
- case OPTIMIZEORDERSTRUCTURE:
- return "OPTIMIZEORDERSTRUCTURE";
- case ORDERINTEGERENCODING:
- return "ORDERINTEGERENCODING";
- case PREPROCESS:
- return "PREPROCESS";
- case NODEENCODING:
- return "NODEENCODING";
- case EDGEENCODING:
- return "EDGEENCODING";
- case MUSTEDGEPRUNE:
- return "MUSTEDGEPRUNE";
- case ELEMENTOPT:
- return "ELEMENTOPT";
- case ELEMENTOPTSETS:
- return "ELEMENTOPTSETS";
- case PROXYVARIABLE:
- return "PROXYVARIABLE";
- default:
- ASSERT(0);
- }
+const char *tunableParameterToString(Tunables tunable) {
+ switch (tunable) {
+ case DECOMPOSEORDER:
+ return "DECOMPOSEORDER";
+ case MUSTREACHGLOBAL:
+ return "MUSTREACHGLOBAL";
+ case MUSTREACHLOCAL:
+ return "MUSTREACHLOCAL";
+ case MUSTREACHPRUNE:
+ return "MUSTREACHPRUNE";
+ case OPTIMIZEORDERSTRUCTURE:
+ return "OPTIMIZEORDERSTRUCTURE";
+ case ORDERINTEGERENCODING:
+ return "ORDERINTEGERENCODING";
+ case PREPROCESS:
+ return "PREPROCESS";
+ case NODEENCODING:
+ return "NODEENCODING";
+ case EDGEENCODING:
+ return "EDGEENCODING";
+ case MUSTEDGEPRUNE:
+ return "MUSTEDGEPRUNE";
+ case ELEMENTOPT:
+ return "ELEMENTOPT";
+ case ELEMENTOPTSETS:
+ return "ELEMENTOPTSETS";
+ case PROXYVARIABLE:
+ return "PROXYVARIABLE";
+ default:
+ ASSERT(0);
+ }
}
naiveEncodingDecision(this);
// eg.validate();
-
+
time2 = getTimeNano();
model_print("Encoding Graph Time: %f\n", (time2 - time1) / NANOSEC);
satEncoder->encodeAllSATEncoder(this);
time1 = getTimeNano();
- model_print("Elapse Encode time: %f\n", (time1- startTime) / NANOSEC);
-
+ model_print("Elapse Encode time: %f\n", (time1 - startTime) / NANOSEC);
+
model_print("Is problem UNSAT after encoding: %d\n", unsat);
int result = unsat ? IS_UNSAT : satEncoder->solve();
- model_print("Result Computed in SAT solver:\t%s\n", result == IS_SAT? "SAT" : " UNSAT");
+ model_print("Result Computed in SAT solver:\t%s\n", result == IS_SAT ? "SAT" : " UNSAT");
time2 = getTimeNano();
elapsedTime = time2 - startTime;
model_print("CSOLVER solve time: %f\n", elapsedTime / NANOSEC);