}
void BooleanVar::print(){
- model_println("BooleanVar:%lu", (uintptr_t)this);
+ model_print("BooleanVar:%lu\n", (uintptr_t)this);
}
void BooleanConst::print(){
- model_println("BooleanConst:%s", istrue?"TRUE" :"FALSE");
+ model_print("BooleanConst:%s\n", istrue?"TRUE" :"FALSE");
}
void BooleanOrder::serialize(Serializer* serializer){
}
void BooleanOrder::print(){
- model_println("{BooleanOrder: First= %lu, Second = %lu on Order:", first, second);
+ model_print("{BooleanOrder: First= %lu, Second = %lu on Order:\n", first, second);
order->print();
- model_println("}\n");
+ model_print("}\n");
}
void BooleanPredicate::serialize(Serializer* serializer){
}
void BooleanPredicate::print(){
- model_println("{BooleanPredicate:");
- predicate->print();
- model_println("elements:");
- uint size = inputs.getSize();
+ model_print("{BooleanPredicate:\n");
+ predicate->print();
+ model_print("elements:\n");
+ uint size = inputs.getSize();
for(uint i=0; i<size; i++){
Element *input = inputs.get(i);
input->print();
}
- model_println("}\n");
+ model_print("}\n");
}
void BooleanLogic::serialize(Serializer* serializer){
}
void BooleanLogic::print(){
- model_println("{BooleanLogic: %s",
- op ==SATC_AND? "AND": op == SATC_OR? "OR": op==SATC_NOT? "NOT":
- op == SATC_XOR? "XOR" : op==SATC_IFF? "IFF" : "IMPLIES");
- uint size = inputs.getSize();
+ model_print("{BooleanLogic: %s\n",
+ op ==SATC_AND? "AND": op == SATC_OR? "OR": op==SATC_NOT? "NOT":
+ op == SATC_XOR? "XOR" : op==SATC_IFF? "IFF" : "IMPLIES");
+ uint size = inputs.getSize();
for(uint i=0; i<size; i++){
BooleanEdge input = inputs.get(i);
- if(input.isNegated())
- model_print("!");
- input.getBoolean()->print();
+ if(input.isNegated())
+ model_print("!");
+ input.getBoolean()->print();
}
- model_println("}\n");
+ model_print("}\n");
}
}
void ElementSet::print(){
- model_println("{ElementSet:");
+ model_print("{ElementSet:\n");
set->print();
- model_println("}\n");
+ model_print("}\n");
}
void ElementConst::serialize(Serializer* serializer){
}
void ElementConst::print(){
- model_println("{ElementConst: %lu}", value);
+ model_print("{ElementConst: %lu}\n", value);
}
void ElementFunction::serialize(Serializer* serializer){
}
void ElementFunction::print(){
- model_println("{ElementFunction:");
+ model_print("{ElementFunction:\n");
function->print();
- model_println("Elements:");
+ model_print("Elements:\n");
uint size = inputs.getSize();
for(uint i=0; i<size; i++){
Element *input = inputs.get(i);
input->print();
}
- model_println("}\n");
+ model_print("}\n");
}
}
void FunctionTable::print(){
- model_println("{FunctionTable:");
- table->print();
- model_println("}\n");
-
+ model_print("{FunctionTable:\n");
+ table->print();
+ model_print("}\n");
}
void FunctionOperator::serialize(Serializer* serializer){
serializer->mywrite(&overflowbehavior, sizeof(OverFlowBehavior));
}
-void FunctionOperator::print(){
- model_println("{FunctionOperator: %s}", op == SATC_ADD? "ADD": "SUB" );
-}
\ No newline at end of file
+void FunctionOperator::print() {
+ model_print("{FunctionOperator: %s}\n", op == SATC_ADD? "ADD": "SUB" );
+}
}
void Order::print(){
- model_println("{Order on Set:");
- set->print();
- model_println("}\n");
+ model_print("{Order on Set:\n");
+ set->print();
+ model_print("}\n");
}
}
void PredicateTable::print(){
- model_println("{PredicateTable:");
- table->print();
- model_println("}\n");
+ model_print("{PredicateTable:\n");
+ table->print();
+ model_print("}\n");
}
void PredicateOperator::serialize(Serializer* serializer){
}
void PredicateOperator::print(){
- model_println("{PredicateOperator: %s }", op ==SATC_EQUALS? "EQUAL": "NOT-EQUAL");
+ model_print("{PredicateOperator: %s }\n", op ==SATC_EQUALS? "EQUAL": "NOT-EQUAL");
}
void CSolver::replaceBooleanWithTrue(BooleanEdge bexpr) {
if (constraints.contains(bexpr.negate())) {
constraints.remove(bexpr.negate());
-#ifdef TRACE_DEBUG
- model_println("replaceBooleanWithTrue");
-#endif
setUnSAT();
}
if (constraints.contains(bexpr)) {
void Set::print(){
model_print("{Set:");
- if(isRange){
- model_print("Range: low=%lu, high=%lu}\n\n", low, high);
- } else {
- uint size = members->getSize();
- model_print("Members: ");
- for(uint i=0; i<size; i++){
- uint64_t mem = members->get(i);
- model_print("%lu, ", mem);
- }
- model_println("}\n");
- }
+ if(isRange){
+ model_print("Range: low=%lu, high=%lu}\n\n", low, high);
+ } else {
+ uint size = members->getSize();
+ model_print("Members: ");
+ for(uint i=0; i<size; i++){
+ uint64_t mem = members->get(i);
+ model_print("%lu, ", mem);
+ }
+ model_print("}\n");
+ }
}
void Table::print(){
- model_println("{Table:");
+ model_print("{Table:\n");
SetIteratorTableEntry* iterator = getEntries();
while(iterator->hasNext()){
TableEntry* entry = iterator->next();
- model_print("<");
- for(uint i=0; i<entry->inputSize; i++){
- model_print("%lu, ", entry->inputs[i]);
- }
- model_print(" == %lu>", entry->output);
+ model_print("<");
+ for(uint i=0; i<entry->inputSize; i++){
+ model_print("%lu, ", entry->inputs[i]);
+ }
+ model_print(" == %lu>", entry->output);
}
- model_println("}\n");
+ model_print("}\n");
delete iterator;
}
void DFSNodeVisit(OrderNode *node, Vector<OrderNode *> *finishNodes, bool isReverse, bool mustvisit, uint sccNum) {
SetIteratorOrderEdge *iterator = isReverse ? node->inEdges.iterator() : node->outEdges.iterator();
-#ifdef TRACE_DEBUG
- model_print("Node:%lu=>", node->id);
-#endif
while (iterator->hasNext()) {
OrderEdge *edge = iterator->next();
-#ifdef TRACE_DEBUG
- model_print("Edge:%lu=>",(uintptr_t) edge);
-#endif
- if (mustvisit) {
+ if (mustvisit) {
if (!edge->mustPos)
continue;
} else
continue;
OrderNode *child = isReverse ? edge->source : edge->sink;
-#ifdef TRACE_DEBUG
- model_println("NodeChild:%lu", child->id);
-#endif
- if (child->status == NOTVISITED) {
+ if (child->status == NOTVISITED) {
child->status = VISITED;
DFSNodeVisit(child, finishNodes, isReverse, mustvisit, sccNum);
child->status = FINISHED;
OrderNode *sinkNode = outEdge->sink;
sinkNode->inEdges.remove(outEdge);
//Adding new edge to new sink and src nodes ...
- if(srcNode == sinkNode){
-#ifdef TRACE_DEBUG
- model_println("bypassMustBe 1");
-#endif
+ if(srcNode == sinkNode) {
This->setUnSAT();
delete iterout;
delete iterin;
OrderEdge *newEdge = graph->getOrderEdgeFromOrderGraph(srcNode, sinkNode);
newEdge->mustPos = true;
newEdge->polPos = true;
- if (newEdge->mustNeg){
-#ifdef TRACE_DEBUG
- model_println("BypassMustBe 2");
-#endif
+ if (newEdge->mustNeg)
This->setUnSAT();
- }
srcNode->outEdges.add(newEdge);
sinkNode->inEdges.add(newEdge);
}
OrderEdge *newedge = graph->getOrderEdgeFromOrderGraph(srcnode, node);
newedge->mustPos = true;
newedge->polPos = true;
- if (newedge->mustNeg){
-#ifdef TRACE_DEBUG
- model_println("DFS clear 1");
-#endif
+ if (newedge->mustNeg)
solver->setUnSAT();
- }
srcnode->outEdges.add(newedge);
node->inEdges.add(newedge);
}
if (!edge->mustPos && sources->contains(parent)) {
edge->mustPos = true;
edge->polPos = true;
- if (edge->mustNeg){
-#ifdef TRACE_DEBUG
- model_println("DFS clear 2");
-#endif
- solver->setUnSAT();
- }
+ if (edge->mustNeg)
+ solver->setUnSAT();
}
}
delete iterator;
edge->mustNeg = true;
edge->polNeg = true;
if (edge->mustPos){
-#ifdef TRACE_DEBUG
- model_println("DFS clear 3: NodeFrom:%lu=>edge%lu=>NodeTo:%lu", node->id, (uintptr_t) edge, child->id);
-#endif
- solver->setUnSAT();
- }
+ solver->setUnSAT();
+ }
}
}
delete iterator;
if (invEdge != NULL) {
if (!invEdge->mustPos) {
invEdge->polPos = false;
- } else {
-#ifdef TRACE_DEBUG
- model_println("localMustAnalysis Total");
-#endif
+ } else
solver->setUnSAT();
- }
invEdge->mustNeg = true;
invEdge->polNeg = true;
}
if (edge->mustPos) {
if (!edge->mustNeg) {
edge->polNeg = false;
- } else{
-#ifdef TRACE_DEBUG
- model_println("Local must analysis partial");
-#endif
+ } else {
solver->setUnSAT();
- }
+ }
OrderEdge *invEdge = graph->getInverseOrderEdge(edge);
if (invEdge != NULL) {
if (!invEdge->mustPos)
invEdge->polPos = false;
- else{
-#ifdef TRACE_DEBUG
- model_println("Local must analysis partial 2");
-#endif
+ else
solver->setUnSAT();
- }
invEdge->mustNeg = true;
invEdge->polNeg = true;
}
convertPass(cnf, false);
finishedClauses(cnf->solver);
long long startSolve = getTimeNano();
-#ifdef TRACE_DEBUG
- model_println("Backend: Calling the SAT Solver from CSolver ...");
-#endif
- int result = solve(cnf->solver);
- model_print("Backend: Result got from SATSolver: %d", result);
+ int result = solve(cnf->solver);
long long finishTime = getTimeNano();
cnf->encodeTime = startSolve - startTime;
cnf->solveTime = finishTime - startSolve;
SetIteratorBooleanEdge *iterator = csolver->getConstraints();
while (iterator->hasNext()) {
BooleanEdge constraint = iterator->next();
-// constraint.getBoolean()->print();
Edge c = encodeConstraintSATEncoder(constraint);
addConstraintCNF(cnf, c);
}
#include "config.h"
#include "time.h"
+/*
+ extern int model_out;
+ extern int model_err;
+ extern int switch_alloc;
+
+ #define model_dprintf(fd, fmt, ...) do { switch_alloc = 1; dprintf(fd, fmt, ## __VA_ARGS__); switch_alloc = 0; } while (0)
+ #define model_print(fmt, ...) do { printf(fmt, ## __VA_ARGS__); } while (0)
+ #define model_println(fmt, ...) do { model_print(fmt, ## __VA_ARGS__); model_print("\n");} while(0)
+
+ #define model_print(fmt, ...) do { model_dprintf(model_out, fmt, ## __VA_ARGS__); } while (0)
+
+ #define model_print_err(fmt, ...) do { model_dprintf(model_err, fmt, ## __VA_ARGS__); } while (0)
+ */
-extern int model_out;
-extern int model_err;
-extern int switch_alloc;
-
-#define model_dprintf(fd, fmt, ...) do { switch_alloc = 1; dprintf(fd, fmt, ## __VA_ARGS__); switch_alloc = 0; } while (0)
-
-#define model_print(fmt, ...) do { model_dprintf(model_out, fmt, ## __VA_ARGS__); } while (0)
-#define model_println(fmt, ...) do { model_print(fmt, ## __VA_ARGS__); model_print("\n");} while(0)
-#define model_print_err(fmt, ...) do { model_dprintf(model_err, fmt, ## __VA_ARGS__); } while (0)
-
-
-
-//#define model_print printf
+#define model_print printf
#define NEXTPOW2(x) ((x == 1) ? 1 : (1 << (sizeof(uint) * 8 - __builtin_clz(x - 1))))
#define NUMBITS(x) ((x == 0) ? 0 : 8 * sizeof(x) - __builtin_clz(x))
}
BooleanEdge CSolver::rewriteLogicalOperation(LogicOp op, BooleanEdge * array, uint asize) {
- return applyLogicalOperation(op, array, asize);
- /* BooleanEdge newarray[asize];
+ BooleanEdge newarray[asize];
memcpy(newarray, array, asize * sizeof(BooleanEdge));
for(uint i=0; i < asize; i++) {
BooleanEdge b=newarray[i];
}
}
}
- return applyLogicalOperation(op, newarray, asize);*/
+ return applyLogicalOperation(op, newarray, asize);
}
BooleanEdge CSolver::applyLogicalOperation(LogicOp op, BooleanEdge *array, uint asize) {
uint newindex = 0;
for (uint i = 0; i < asize; i++) {
BooleanEdge b = array[i];
-// model_print("And: Argument %u:", i);
-// if(b.isNegated())
-// model_print("!");
-// b->print();
if (b->type == LOGICOP) {
if (((BooleanLogic *)b.getBoolean())->replaced)
return rewriteLogicalOperation(op, array, asize);
}
case SATC_IMPLIES: {
//handle by translation
-// model_print("Implies: first:");
-// if(array[0].isNegated())
-// model_print("!");
-// array[0]->print();
-// model_print("Implies: second:");
-// if(array[1].isNegated())
-// model_print("!");
-// array[1]->print();
-// model_println("##### OK let's get the operation done");
return applyLogicalOperation(SATC_OR, applyLogicalOperation(SATC_NOT, array[0]), array[1]);
}
}
ASSERT(asize != 0);
Boolean *boolean = new BooleanLogic(this, op, array, asize);
- /* Boolean *b = boolMap.get(boolean);
+ Boolean *b = boolMap.get(boolean);
if (b == NULL) {
boolean->updateParents();
boolMap.put(boolean, boolean);
allBooleans.push(boolean);
return BooleanEdge(boolean);
} else {
- delete boolean;*/
+ delete boolean;
return BooleanEdge(boolean);
- /* }*/
+ }
}
BooleanEdge CSolver::orderConstraint(Order *order, uint64_t first, uint64_t second) {
-#ifdef TRACE_DEBUG
- model_println("Creating order: From:%lu => To:%lu", first, second);
-#endif
- if(first == second)
- return boolFalse;
+ ASSERT(first != second);
Boolean *constraint = new BooleanOrder(order, first, second);
allBooleans.push(constraint);
return BooleanEdge(constraint);
}
void CSolver::addConstraint(BooleanEdge constraint) {
-#ifdef TRACE_DEBUG
- model_println("****New Constraint******");
-#endif
- if(constraint.isNegated())
- model_print("!");
- constraint.getBoolean()->print();
+ if(constraint.isNegated())
+ model_print("!");
+ constraint.getBoolean()->print();
if (isTrue(constraint))
return;
- else if (isFalse(constraint)){
- int t=0;
-#ifdef TRACE_DEBUG
- model_println("Adding constraint which is false :|");
-#endif
- setUnSAT();
- }
+ else if (isFalse(constraint)) {
+ int t=0;
+ setUnSAT();
+ }
else {
if (constraint->type == LOGICOP) {
BooleanLogic *b=(BooleanLogic *) constraint.getBoolean();
if (!constraint.isNegated()) {
if (b->op==SATC_AND) {
for(uint i=0;i<b->inputs.getSize();i++) {
-#ifdef TRACE_DEBUG
- model_println("In loop");
-#endif
addConstraint(b->inputs.get(i));
}
return;
}
}
if (b->replaced) {
-#ifdef TRACE_DEBUG
- model_println("While rewriting");
-#endif
addConstraint(doRewrite(constraint));
return;
}
constraints.add(constraint);
Boolean *ptr=constraint.getBoolean();
- if (ptr->boolVal == BV_UNSAT){
-#ifdef TRACE_DEBUG
- model_println("BooleanValue is Set to UnSAT");
-#endif
- setUnSAT();
- }
+ if (ptr->boolVal == BV_UNSAT) {
+ setUnSAT();
+ }
replaceBooleanWithTrueNoRemove(constraint);
constraint->parents.clear();
long long startTime = getTimeNano();
computePolarities(this);
-// Preprocess pp(this);
-// pp.doTransform();
+ Preprocess pp(this);
+ pp.doTransform();
-// DecomposeOrderTransform dot(this);
-// dot.doTransform();
+ DecomposeOrderTransform dot(this);
+ dot.doTransform();
-// IntegerEncodingTransform iet(this);
-// iet.doTransform();
+ IntegerEncodingTransform iet(this);
+ iet.doTransform();
-// EncodingGraph eg(this);
-// eg.buildGraph();
-// eg.encode();
+ EncodingGraph eg(this);
+ eg.buildGraph();
+ eg.encode();
naiveEncodingDecision(this);
satEncoder->encodeAllSATEncoder(this);
- model_println("Is problem UNSAT after encoding: %d", unsat);
+ model_print("Is problem UNSAT after encoding: %d\n", unsat);
int result = unsat ? IS_UNSAT : satEncoder->solve();
- model_println("Result Computed in CSolver: %d", result);
+ model_print("Result Computed in CSolver: %d\n", result);
long long finishTime = getTimeNano();
elapsedTime = finishTime - startTime;
if (deleteTuner) {
bool isTrue(BooleanEdge b);
bool isFalse(BooleanEdge b);
- void setUnSAT() { model_println("Setting UNSAT %%%%%%"); unsat = true; }
+ void setUnSAT() { model_print("Setting UNSAT %%%%%%\n"); unsat = true; }
bool isUnSAT() { return unsat; }
void * ourrealloc(void *ptr, size_t size);
*/
-#if 1
+#if 0
void * model_malloc(size_t size);
void model_free(void *ptr);
void * model_calloc(size_t count, size_t size);