enum OrderType {PARTIAL, TOTAL};
typedef enum OrderType OrderType;
-enum HappenedBefore {UNORDERED, FIRST, SECOND};
+enum HappenedBefore {FIRST, SECOND, UNORDERED};
typedef enum HappenedBefore HappenedBefore;
/**
Edge getOrderConstraint(HashTableOrderPair *table, OrderPair *pair){
ASSERT(pair->first!= pair->second);
- Edge constraint = getOrderPair(table, pair)->constraint;
+ OrderPair* value = getOrderPair(table, pair);
+ if(value == NULL)
+ return E_NULL;
+ Edge constraint = value->constraint;
if(pair->first > pair->second || edgeIsNull(constraint))
return constraint;
else
return This->satEncoder->cnf->solver->solution[index] == true;
}
-HappenedBefore getOrderConstraintValueSATTranslator(CSolver* This, BooleanOrder* boolOrder){
- ASSERT(boolOrder->order->orderPairTable!= NULL);
- OrderPair pair={boolOrder->first, boolOrder->second, E_NULL};
- Edge var = getOrderConstraint(boolOrder->order->orderPairTable, & pair);
+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 UNORDERED;
int index = getEdgeVar( var );
bool getBooleanVariableValueSATTranslator( CSolver* This , Boolean* boolean);
-HappenedBefore getOrderConstraintValueSATTranslator(CSolver* This, BooleanOrder* boolOrder);
+HappenedBefore getOrderConstraintValueSATTranslator(CSolver* This, Order * order, uint64_t first, uint64_t second);
uint64_t getElementValueBinaryIndexSATTranslator(CSolver* This, ElementEncoding* elemEnc);
uint64_t getElementValueBinaryValueSATTranslator(CSolver* This, ElementEncoding* elemEnc);
uint64_t getElementValueOneHotSATTranslator(CSolver* This, ElementEncoding* elemEnc);
--- /dev/null
+
+#include "csolver.h"
+
+int main(int numargs, char ** argv) {
+ CSolver * solver=allocCSolver();
+ uint64_t set1[]={5, 1, 4};
+ Set * s=createSet(solver, 0, set1, 3);
+ Order* order = createOrder(solver, TOTAL, s);
+ Boolean* b1= orderConstraint(solver, order, 1, 4);
+ Boolean* b2= orderConstraint(solver, order, 5, 4);
+ addConstraint(solver, b1);
+ addConstraint(solver, b2);
+ if (startEncoding(solver)==1)
+ printf("O(1,4)=%d O(5,4)=%d O(4,5)=%d O(1,5)=%d\n",
+ getOrderConstraintValue(solver, order, 1, 4),
+ getOrderConstraintValue(solver, order, 5, 4),
+ getOrderConstraintValue(solver, order, 4, 5),
+ getOrderConstraintValue(solver, order, 1, 5));
+ else
+ printf("UNSAT\n");
+ deleteSolver(solver);
+}
\ No newline at end of file
exit(-1);
}
-HappenedBefore getOrderConstraintValue(CSolver* This, Boolean* orderConstr){
- switch(GETBOOLEANTYPE(orderConstr)){
- case ORDERCONST:
- return getOrderConstraintValueSATTranslator(This, (BooleanOrder*)orderConstr);
- default:
- ASSERT(0);
- }
- exit(-1);
+HappenedBefore getOrderConstraintValue(CSolver* This, Order * order, uint64_t first, uint64_t second){
+ return getOrderConstraintValueSATTranslator(This, order, first, second);
}
/** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
bool getBooleanValue( CSolver* , Boolean* boolean);
-HappenedBefore getOrderConstraintValue(CSolver*, Boolean* orderConstr);
+HappenedBefore getOrderConstraintValue(CSolver*, Order * order, uint64_t first, uint64_t second);
#endif