--- /dev/null
- #include "orderencoder.h"
+#include "analyzer.h"
+#include "common.h"
+#include "order.h"
+#include "boolean.h"
+#include "ordergraph.h"
+#include "ordernode.h"
+#include "rewriter.h"
+#include "orderedge.h"
+#include "mutableset.h"
+#include "ops.h"
+#include "csolver.h"
-
++#include "orderanalysis.h"
+#include "tunable.h"
+#include "transform.h"
+#include "element.h"
+#include "integerencoding.h"
+#include "decomposeordertransform.h"
+
+void orderAnalysis(CSolver *This) {
+ Vector<Order *> *orders = This->getOrders();
+ uint size = orders->getSize();
+ for (uint i = 0; i < size; i++) {
+ Order *order = orders->get(i);
+ DecomposeOrderTransform* decompose = new DecomposeOrderTransform(This, order, DECOMPOSEORDER, &onoff);
+ if (!decompose->canExecuteTransform()){
+ continue;
+ delete decompose;
+ }
+
+ OrderGraph *graph = buildOrderGraph(order);
+ if (order->type == PARTIAL) {
+ //Required to do SCC analysis for partial order graphs. It
+ //makes sure we don't incorrectly optimize graphs with negative
+ //polarity edges
+ completePartialOrderGraph(graph);
+ }
+
+
+ bool mustReachGlobal = GETVARTUNABLE(This->getTuner(), order->type, MUSTREACHGLOBAL, &onoff);
+
+ if (mustReachGlobal)
+ reachMustAnalysis(This, graph, false);
+
+ bool mustReachLocal = GETVARTUNABLE(This->getTuner(), order->type, MUSTREACHLOCAL, &onoff);
+
+ if (mustReachLocal) {
+ //This pair of analysis is also optional
+ if (order->type == PARTIAL) {
+ localMustAnalysisPartial(This, graph);
+ } else {
+ localMustAnalysisTotal(This, graph);
+ }
+ }
+
+ bool mustReachPrune = GETVARTUNABLE(This->getTuner(), order->type, MUSTREACHPRUNE, &onoff);
+
+ if (mustReachPrune)
+ removeMustBeTrueNodes(This, graph);
+
+ //This is needed for splitorder
+ computeStronglyConnectedComponentGraph(graph);
+ decompose->setOrderGraph(graph);
+ decompose->doTransform();
+ delete decompose;
+ delete graph;
+
- delete integerEncoding;
- }
++ /*
+ IntegerEncodingTransform* integerEncoding = new IntegerEncodingTransform(This, order, ORDERINTEGERENCODING, &offon);
+ if(!integerEncoding->canExecuteTransform()){
+ continue;
+ delete integerEncoding;
+ }
+ integerEncoding->doTransform();
++ delete integerEncoding; */
++ }
+}
+
+
bool order_element_equals(OrderElement *key1, OrderElement *key2);
unsigned int order_pair_hash_function(OrderPair *This);
bool order_pair_equals(OrderPair *key1, OrderPair *key2);
+unsigned int order_hash_function(Order *This);
+bool order_pair_equals(Order *key1, Order *key2);
+
typedef HashSet<Boolean *, uintptr_t, 4> HashSetBoolean;
typedef HashSet<TableEntry *, uintptr_t, 4, table_entry_hash_function, table_entry_equals> HashSetTableEntry;
typedef HashSet<OrderElement *, uintptr_t, 4, order_element_hash_function, order_element_equals> HashSetOrderElement;
typedef HashTable<OrderNode *, HashSetOrderNode *, uintptr_t, 4> HashTableNodeToNodeSet;
typedef HashTable<OrderPair *, OrderPair *, uintptr_t, 4, order_pair_hash_function, order_pair_equals> HashTableOrderPair;
+ typedef HashTable<void *, void *, uintptr_t, 4> CloneMap;
+typedef HashTable<Order* , IntegerEncodingRecord*, uintptr_t, 4, order_hash_function, order_pair_equals> HashTableOrderIntegerEncoding;
+
typedef HSIterator<TableEntry *, uintptr_t, 4, table_entry_hash_function, table_entry_equals> HSIteratorTableEntry;
typedef HSIterator<Boolean *, uintptr_t, 4> HSIteratorBoolean;
typedef HSIterator<OrderEdge *, uintptr_t, 4, order_edge_hash_function, order_edge_equals> HSIteratorOrderEdge;
typedef HSIterator<OrderNode *, uintptr_t, 4, order_node_hash_function, order_node_equals> HSIteratorOrderNode;
+
#endif
#include "sattranslator.h"
#include "tunable.h"
#include "polarityassignment.h"
-#include "orderdecompose.h"
+#include "analyzer.h"
-
- CSolver::CSolver() : unsat(false) {
- tuner = new Tuner();
- satEncoder = allocSATEncoder(this);
+ #include "autotuner.h"
+
+ CSolver::CSolver() :
+ unsat(false),
+ tuner(NULL),
+ elapsedTime(0)
+ {
+ satEncoder = new SATEncoder(this);
}
/** This function tears down the solver and the entire AST */
delete allFunctions.get(i);
}
- deleteSATEncoder(satEncoder);
- delete tuner;
+ delete satEncoder;
+ }
+
+ CSolver *CSolver::clone() {
+ CSolver *copy = new CSolver();
+ CloneMap map;
+ HSIteratorBoolean *it = getConstraints();
+ while (it->hasNext()) {
+ Boolean *b = it->next();
+ copy->addConstraint(b->clone(copy, &map));
+ }
+ delete it;
+ return copy;
}
Set *CSolver::createSet(VarType type, uint64_t *elements, uint numelements) {
}
Element *CSolver::getElementConst(VarType type, uint64_t value) {
- Element *element = new ElementConst(value, type);
- allElements.push(element);
- return element;
+ uint64_t array[] = {value};
+ Set *set = new Set(type, array, 1);
+ Element *element = new ElementConst(value, type, set);
+ Element *e = elemMap.get(element);
+ if (e == NULL) {
+ allSets.push(set);
+ allElements.push(element);
+ elemMap.put(element, element);
+ return element;
+ } else {
+ delete set;
+ delete element;
+ return e;
+ }
}
- Boolean *CSolver::getBooleanVar(VarType type) {
- Boolean *boolean = new BooleanVar(type);
- allBooleans.push(boolean);
- return boolean;
+ Element *CSolver::applyFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus) {
+ Element *element = new ElementFunction(function,array,numArrays,overflowstatus);
+ Element *e = elemMap.get(element);
+ if (e == NULL) {
+ allElements.push(element);
+ elemMap.put(element, element);
+ return element;
+ } else {
+ delete element;
+ return e;
+ }
}
Function *CSolver::createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,OverFlowBehavior overflowbehavior) {
return function;
}
- Element *CSolver::applyFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus) {
- Element *element = new ElementFunction(function,array,numArrays,overflowstatus);
- allElements.push(element);
- return element;
+ Boolean *CSolver::getBooleanVar(VarType type) {
+ Boolean *boolean = new BooleanVar(type);
+ allBooleans.push(boolean);
+ return boolean;
}
Boolean *CSolver::applyPredicate(Predicate *predicate, Element **inputs, uint numInputs) {
Boolean *CSolver::applyPredicateTable(Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus) {
BooleanPredicate *boolean = new BooleanPredicate(predicate, inputs, numInputs, undefinedStatus);
- allBooleans.push(boolean);
- return boolean;
+ Boolean * b = boolMap.get(boolean);
+ if (b == NULL) {
+ boolMap.put(boolean, boolean);
+ allBooleans.push(boolean);
+ return boolean;
+ } else {
+ delete boolean;
+ return b;
+ }
}
Boolean *CSolver::applyLogicalOperation(LogicOp op, Boolean **array, uint asize) {
Boolean *boolean = new BooleanLogic(this, op, array, asize);
- allBooleans.push(boolean);
- return boolean;
+ Boolean *b = boolMap.get(boolean);
+ if (b == NULL) {
+ boolMap.put(boolean, boolean);
+ allBooleans.push(boolean);
+ return boolean;
+ } else {
+ delete boolean;
+ return b;
+ }
+ }
+
+ Boolean *CSolver::orderConstraint(Order *order, uint64_t first, uint64_t second) {
+ Boolean *constraint = new BooleanOrder(order, first, second);
+ allBooleans.push(constraint);
+ return constraint;
}
void CSolver::addConstraint(Boolean *constraint) {
return order;
}
- Boolean *CSolver::orderConstraint(Order *order, uint64_t first, uint64_t second) {
- Boolean *constraint = new BooleanOrder(order, first, second);
- allBooleans.push(constraint);
- return constraint;
- }
-
int CSolver::startEncoding() {
+ bool deleteTuner = false;
+ if (tuner == NULL) {
+ tuner = new DefaultTuner();
+ deleteTuner = true;
+ }
+
+ long long startTime = getTimeNano();
computePolarities(this);
orderAnalysis(this);
naiveEncodingDecision(this);
- encodeAllSATEncoder(this, satEncoder);
- int result = solveCNF(satEncoder->cnf);
- model_print("sat_solver's result:%d\tsolutionSize=%d\n", result, satEncoder->cnf->solver->solutionsize);
- for (int i = 1; i <= satEncoder->cnf->solver->solutionsize; i++) {
- model_print("%d, ", satEncoder->cnf->solver->solution[i]);
+ satEncoder->encodeAllSATEncoder(this);
+ int result = unsat ? IS_UNSAT : satEncoder->solve();
+ long long finishTime = getTimeNano();
+ elapsedTime = finishTime - startTime;
+ if (deleteTuner) {
+ delete tuner;
+ tuner = NULL;
}
- model_print("\n");
return result;
}
uint64_t CSolver::getElementValue(Element *element) {
- switch (GETELEMENTTYPE(element)) {
+ switch (element->type) {
case ELEMSET:
case ELEMCONST:
case ELEMFUNCRETURN:
}
bool CSolver::getBooleanValue(Boolean *boolean) {
- switch (GETBOOLEANTYPE(boolean)) {
+ switch (boolean->type) {
case BOOLEANVAR:
return getBooleanVariableValueSATTranslator(this, boolean);
default:
return getOrderConstraintValueSATTranslator(this, order, first, second);
}
+ long long CSolver::getEncodeTime() { return satEncoder->getEncodeTime(); }
+
+ long long CSolver::getSolveTime() { return satEncoder->getSolveTime(); }
+
+ void CSolver::autoTune(uint budget) {
+ AutoTuner * autotuner=new AutoTuner(budget);
+ autotuner->addProblem(this);
+ autotuner->tune();
+ delete autotuner;
+ }