Element::Element(ASTNodeType _type) :
ASTNode(_type),
- encoding(this) {
+ encoding(this),
+ anyValue(false){
}
ElementSet::ElementSet(Set *s) :
}
Element *ElementConst::clone(CSolver *solver, CloneMap *map) {
- return solver->getElementConst(type, value);
+ Element* e= solver->getElementConst(type, value);
+ e->anyValue = anyValue;
+ return e;
}
Element *ElementSet::clone(CSolver *solver, CloneMap *map) {
return e;
e = solver->getElementVar(set->clone(solver, map));
map->put(this, e);
+ e->anyValue = anyValue;
return e;
}
}
BooleanEdge ofstatus = overflowstatus ? cloneEdge(solver, map, overflowstatus) : BooleanEdge();
Element *e = solver->applyFunction(function->clone(solver, map), array, inputs.getSize(), ofstatus);
+ e->anyValue = anyValue;
return e;
}
set->serialize(serializer);
serializer->mywrite(&type, sizeof(ASTNodeType));
+ serializer->mywrite(&anyValue, sizeof(bool));
ElementSet *This = this;
serializer->mywrite(&This, sizeof(ElementSet *));
serializer->mywrite(&set, sizeof(Set *));
set->serialize(serializer);
serializer->mywrite(&type, sizeof(ASTNodeType));
+ serializer->mywrite(&anyValue, sizeof(bool));
ElementSet *This = this;
serializer->mywrite(&This, sizeof(ElementSet *));
VarType type = set->getType();
serializeBooleanEdge(serializer, overflowstatus);
serializer->mywrite(&type, sizeof(ASTNodeType));
+ serializer->mywrite(&anyValue, sizeof(bool));
ElementFunction *This = this;
serializer->mywrite(&This, sizeof(ElementFunction *));
serializer->mywrite(&function, sizeof(Function *));
virtual void updateParents() {}
virtual Set *getRange() = 0;
CMEMALLOC;
+ bool anyValue;
};
class ElementSet : public Element {
ASSERT(encoding->type == BINARYVAL);
allocElementConstraintVariables(encoding, encoding->numBits);
getArrayNewVarsSATEncoder(encoding->numVars, encoding->variables);
- if (encoding->anyValue)
+ if (encoding->element->anyValue)
generateAnyValueBinaryValueEncoding(encoding);
}
ASSERT(encoding->type == BINARYINDEX);
allocElementConstraintVariables(encoding, NUMBITS(encoding->encArraySize - 1));
getArrayNewVarsSATEncoder(encoding->numVars, encoding->variables);
- if (encoding->anyValue)
+ if (encoding->element->anyValue)
generateAnyValueBinaryIndexEncoding(encoding);
}
addConstraintCNF(cnf, constraintNegate(constraintAND2(cnf, encoding->variables[i], encoding->variables[j])));
}
}
- if (encoding->anyValue)
+ if (encoding->element->anyValue)
addConstraintCNF(cnf, constraintOR(cnf, encoding->numVars, encoding->variables));
}
const char *elemEncTypeNames[] = {"UNASSIGNED", "ONEHOT", "UNARY", "BINARYINDEX", "BINARYVAL"};
ElementEncoding::ElementEncoding(Element *_element) :
- anyValue(false),
type(ELEM_UNASSIGNED),
element(_element),
variables(NULL),
}
void print();
- bool anyValue;
ElementEncodingType type;
Element *element;
Edge *variables;/* List Variables Used To Encode Element */
void Deserializer::deserializeElementSet() {
+ bool anyValue = false;
+ myread(&anyValue, sizeof(bool));
ElementSet *es_ptr;
myread(&es_ptr, sizeof(ElementSet *));
Set *set;
myread(&set, sizeof(Set *));
ASSERT(map.contains(set));
set = (Set *) map.get(set);
- map.put(es_ptr, solver->getElementVar(set));
+ Element *newEl = solver->getElementVar(set);
+ newEl->anyValue = anyValue;
+ map.put(es_ptr, newEl);
}
void Deserializer::deserializeElementConst() {
+ bool anyValue = false;
+ myread(&anyValue, sizeof(bool));
ElementSet *es_ptr;
myread(&es_ptr, sizeof(ElementSet *));
VarType type;
myread(&type, sizeof(VarType));
uint64_t value;
myread(&value, sizeof(uint64_t));
- map.put(es_ptr, solver->getElementConst(type, value));
+ Element *newEl = solver->getElementConst(type, value);
+ newEl->anyValue = anyValue;
+ map.put(es_ptr, newEl);
}
void Deserializer::deserializeElementFunction() {
+ bool anyValue = false;
+ myread(&anyValue, sizeof(bool));
ElementFunction *ef_ptr;
myread(&ef_ptr, sizeof(ElementFunction *));
Function *function;
overflowstatus = (Boolean *) map.get(tmp.getBoolean());
BooleanEdge res(overflowstatus);
BooleanEdge undefStatus = isNegated ? res.negate() : res;
- map.put(ef_ptr, solver->applyFunction(function, members.expose(), size, undefStatus));
+ Element *newEl = solver->applyFunction(function, members.expose(), size, undefStatus);
+ newEl->anyValue = anyValue;
+ map.put(ef_ptr, newEl);
}
}
void CSolver::mustHaveValue(Element *element) {
- element->getElementEncoding()->anyValue = true;
+ element->anyValue = true;
}
Set *CSolver::getElementRange (Element *element) {
#define NANOSEC 1000000000.0
int CSolver::solve() {
- long long starttime = getTimeNano();
+ long long startTime = getTimeNano();
bool deleteTuner = false;
if (tuner == NULL) {
tuner = new DefaultTuner();
delete orderit;
}
computePolarities(this);
- long long time2 = getTimeNano();
- model_print("Polarity time: %f\n", (time2 - starttime) / NANOSEC);
+ long long time1 = getTimeNano();
+ model_print("Polarity time: %f\n", (time1 - startTime) / NANOSEC);
Preprocess pp(this);
pp.doTransform();
- long long time3 = getTimeNano();
- model_print("Preprocess time: %f\n", (time3 - time2) / NANOSEC);
+ long long time2 = getTimeNano();
+ model_print("Preprocess time: %f\n", (time2 - time1) / NANOSEC);
DecomposeOrderTransform dot(this);
dot.doTransform();
- long long time4 = getTimeNano();
- model_print("Decompose Order: %f\n", (time4 - time3) / NANOSEC);
+ time1 = getTimeNano();
+ model_print("Decompose Order: %f\n", (time1 - time2) / NANOSEC);
IntegerEncodingTransform iet(this);
iet.doTransform();
ElementOpt eop(this);
eop.doTransform();
- EncodingGraph eg(this);
- eg.buildGraph();
- eg.encode();
+// EncodingGraph eg(this);
+// eg.buildGraph();
+// eg.encode();
naiveEncodingDecision(this);
// eg.validate();
- long long time5 = getTimeNano();
- model_print("Encoding Graph Time: %f\n", (time5 - time4) / NANOSEC);
+ time2 = getTimeNano();
+ model_print("Encoding Graph Time: %f\n", (time2 - time1) / NANOSEC);
- long long startTime = getTimeNano();
satEncoder->encodeAllSATEncoder(this);
- long long endTime = getTimeNano();
-
- elapsedTime = endTime - startTime;
- model_print("Elapse Encode time: %f\n", elapsedTime / NANOSEC);
+ time1 = getTimeNano();
+ 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: %d\n", result);
-
+ 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);
if (deleteTuner) {
delete tuner;
tuner = NULL;