Adding checks to avoid further processing on UNSAT Problems
[satune.git] / src / ASTTransform / integerencoding.cc
1 #include "integerencoding.h"
2 #include "set.h"
3 #include "order.h"
4 #include "satencoder.h"
5 #include "csolver.h"
6 #include "integerencodingrecord.h"
7 #include "integerencorderresolver.h"
8 #include "tunable.h"
9 #include "polarityassignment.h"
10
11 IntegerEncodingTransform::IntegerEncodingTransform(CSolver *_solver)
12         : Transform(_solver)
13 {
14 }
15
16 IntegerEncodingTransform::~IntegerEncodingTransform() {
17 }
18
19 void IntegerEncodingTransform::doTransform() {
20         if(solver->isUnSAT()){
21                 return;
22         }
23         HashsetOrder *orders = solver->getActiveOrders()->copy();
24         SetIteratorOrder *orderit = orders->iterator();
25         while (orderit->hasNext()) {
26                 Order *order = orderit->next();
27                 if (GETVARTUNABLE(solver->getTuner(), order->type, ORDERINTEGERENCODING, &offon))
28                         integerEncode(order);
29         }
30         delete orders;
31         delete orderit;
32 }
33
34 void IntegerEncodingTransform::integerEncode(Order *currOrder) {
35         IntegerEncodingRecord *encodingRecord =  new IntegerEncodingRecord(
36                 solver->createRangeSet(currOrder->set->getType(), 0, (uint64_t) currOrder->set->getSize() - 1));
37         currOrder->setOrderEncodingType( INTEGERENCODING );
38         uint size = currOrder->constraints.getSize();
39         for (uint i = 0; i < size; i++) {
40                 orderIntegerEncodingSATEncoder(currOrder->constraints.get(i), encodingRecord);
41         }
42         currOrder->setOrderResolver(new IntegerEncOrderResolver(solver, encodingRecord));
43         solver->getActiveOrders()->remove(currOrder);
44 }
45
46
47 void IntegerEncodingTransform::orderIntegerEncodingSATEncoder(BooleanOrder *boolOrder, IntegerEncodingRecord *ierec) {
48         //getting two elements and using LT predicate ...
49         Element *elem1 = ierec->getOrderIntegerElement(solver, boolOrder->first);
50         Element *elem2 = ierec->getOrderIntegerElement(solver, boolOrder->second);
51         Predicate *predicate = solver->createPredicateOperator(SATC_LT);
52         Element *parray[] = {elem1, elem2};
53         BooleanEdge boolean = solver->applyPredicate(predicate, parray, 2);
54         updateEdgePolarity(boolean, boolOrder);
55         solver->replaceBooleanWithBoolean(boolOrder, boolean);
56 }
57