#include "element.h"
#include "predicate.h"
#include "orderelement.h"
+#include "orderpairresolver.h"
Edge SATEncoder::encodeOrderSATEncoder(BooleanOrder *constraint) {
+ //This is pairwised encoding ...
+ constraint->order->setOrderResolver(new OrderPairResolver(solver, constraint->order));
switch ( constraint->order->type) {
case SATC_PARTIAL:
return encodePartialOrderSATEncoder(constraint);
}
DecomposeOrderResolver::~DecomposeOrderResolver() {
- delete graph;
}
HappenedBefore DecomposeOrderResolver::resolveOrder(uint64_t first, uint64_t second){
} else if( edge != NULL && edge->mustNeg){
return SATC_SECOND;
}else {
- switch(graph->getOrder()->encoding.type){
+ switch(graph->getOrder()->type){
case SATC_TOTAL:
return from->sccNum < to->sccNum? SATC_FIRST: SATC_SECOND;
case SATC_PARTIAL:
+ //Adding support for partial order ...
default:
ASSERT(0);
}
--- /dev/null
+
+/*
+ * File: orderpairresolver.cc
+ * Author: hamed
+ *
+ * Created on September 1, 2017, 3:36 PM
+ */
+
+#include "orderpairresolver.h"
+#include "ordergraph.h"
+#include "order.h"
+#include "orderedge.h"
+#include "ordernode.h"
+#include "satencoder.h"
+#include "csolver.h"
+
+OrderPairResolver::OrderPairResolver(CSolver* _solver, Order* _order) :
+ solver(_solver),
+ order(_order)
+{
+}
+
+OrderPairResolver::~OrderPairResolver() {
+}
+
+HappenedBefore OrderPairResolver::resolveOrder(uint64_t first, uint64_t second){
+ if(order->graph != NULL){
+ // For the cases that tuning framework decides no to build a graph for order ...
+ OrderGraph* graph = order->graph;
+ OrderNode *from = graph->getOrderNodeFromOrderGraph(first, false /*Don't create new node if doesn't exist*/);
+ if(from == NULL){
+ return SATC_UNORDERED;
+ }
+ OrderNode *to = graph->getOrderNodeFromOrderGraph(second, false);
+ if(from == NULL){
+ return SATC_UNORDERED;
+ }
+
+ OrderEdge *edge = graph->getOrderEdgeFromOrderGraph(from, to, false /* Don't create a new edge*/);
+ if (edge != NULL && edge->mustPos){
+ return SATC_FIRST;
+ } else if( edge != NULL && edge->mustNeg){
+ return SATC_SECOND;
+ }
+ }
+
+ //Couldn't infer from graph. Should call the SAT Solver ...
+ switch( order->type){
+ case SATC_TOTAL:
+ resolveTotalOrder(first, second);
+ case SATC_PARTIAL:
+ //TODO: Support for partial order ...
+ default:
+ ASSERT(0);
+ }
+
+
+}
+
+
+HappenedBefore OrderPairResolver::resolveTotalOrder(uint64_t first, uint64_t second) {
+ ASSERT(order->orderPairTable != NULL);
+ OrderPair pair(first, second, E_NULL);
+ Edge var = getOrderConstraint(order->orderPairTable, &pair);
+ if (edgeIsNull(var))
+ return SATC_UNORDERED;
+ return getValueCNF(solver->getSATEncoder()->getCNF(), var) ? SATC_FIRST : SATC_SECOND;
+}
--- /dev/null
+
+/*
+ * File: orderpairresolver.h
+ * Author: hamed
+ *
+ * Created on September 1, 2017, 3:36 PM
+ */
+
+#ifndef ORDERPAIRRESOLVER_H
+#define ORDERPAIRRESOLVER_H
+
+#include "orderresolver.h"
+
+class OrderPairResolver : public OrderResolver{
+public:
+ OrderPairResolver(CSolver* _solver, Order* _order);
+ HappenedBefore resolveOrder(uint64_t first, uint64_t second);
+ virtual ~OrderPairResolver();
+private:
+ CSolver* solver;
+ Order* order;
+ HappenedBefore resolveTotalOrder(uint64_t first, uint64_t second);
+};
+
+#endif /* ORDERPAIRRESOLVER_H */
+
return getValueSolver(This->getSATEncoder()->getCNF()->solver, index);
}
-HappenedBefore getOrderConstraintValueSATTranslator(CSolver *This, Order *order, uint64_t first, uint64_t second) {
- ASSERT(order->orderPairTable != NULL);
- OrderPair pair(first, second, E_NULL);
- Edge var = getOrderConstraint(order->orderPairTable, &pair);
- if (edgeIsNull(var))
- return SATC_UNORDERED;
- return getValueCNF(This->getSATEncoder()->getCNF(), var) ? SATC_FIRST : SATC_SECOND;
-}
bool getBooleanVariableValueSATTranslator( CSolver *This, Boolean *boolean);
-HappenedBefore getOrderConstraintValueSATTranslator(CSolver *This, Order *order, uint64_t first, uint64_t second);
+
/**
* most significant bit is represented by variable index 0
*/
#include "autotuner.h"
#include "astops.h"
#include "structs.h"
+#include "orderresolver.h"
CSolver::CSolver() :
boolTrue(new BooleanConst(true)),
}
HappenedBefore CSolver::getOrderConstraintValue(Order *order, uint64_t first, uint64_t second) {
- return getOrderConstraintValueSATTranslator(this, order, first, second);
+ return order->encoding.resolver->resolveOrder(first, second);
}
long long CSolver::getEncodeTime() { return satEncoder->getEncodeTime(); }