Adding timeout for Alloy interpreter
[satune.git] / src / Test / tablepredicencodetest.cc
1 #include "csolver.h"
2 /**
3  * e1 = {1, 2}
4  * e2={1, 3, 5, 7}
5  * e3 = {6, 10, 19}
6  * e4= p(e1, e2, e3)
7  *      1 5 6 => T
8  *      2 3 19 => T
9  *      1 3 19 => F
10  *      2 7 10 => F
11  *      1 7 6 => F
12  *      2 5 6 => T
13  * e1 == e2
14  * e3 >= e2
15  * Result: e1=1, e2=1, e3=6 OR 10 OR 19, overflow=1
16  */
17 int main(int numargs, char **argv) {
18         CSolver *solver = new CSolver();
19         uint64_t set1[] = {1, 2};
20         uint64_t set2[] = {1, 3, 5, 7};
21         uint64_t set3[] = {6, 10, 19};
22         Set *s1 = solver->createSet(0, set1, 2);
23         Set *s2 = solver->createSet(0, set2, 4);
24         Set *s3 = solver->createSet(0, set3, 3);
25         Element *e1 = solver->getElementVar(s1);
26         Element *e2 = solver->getElementVar(s2);
27         Element *e3 = solver->getElementVar(s3);
28         //change the overflow flag
29         Table *t1 = solver->createTableForPredicate();
30         uint64_t row1[] = {1, 5, 6};
31         uint64_t row2[] = {2, 3, 19};
32         uint64_t row3[] = {1, 3, 19};
33         uint64_t row4[] = {2, 7, 10};
34         uint64_t row5[] = {1, 7, 6};
35         uint64_t row6[] = {2, 5, 6};
36         solver->addTableEntry(t1, row1, 3, true);
37         solver->addTableEntry(t1, row2, 3, true);
38         solver->addTableEntry(t1, row3, 3, false);
39         solver->addTableEntry(t1, row4, 3, false);
40         solver->addTableEntry(t1, row5, 3, false);
41         solver->addTableEntry(t1, row6, 3, true);
42         Predicate *p1 = solver->createPredicateTable(t1, SATC_FLAGIFFUNDEFINED);
43         BooleanEdge undef = solver->getBooleanVar(2);
44         Element *tmparray[] = {e1, e2, e3};
45         BooleanEdge b1 = solver->applyPredicateTable(p1, tmparray, 3, undef);
46         solver->addConstraint(b1);
47
48         Predicate *gte = solver->createPredicateOperator(SATC_GTE);
49         Element *inputs2 [] = {e3, e2};
50         BooleanEdge pred = solver->applyPredicate(gte, inputs2, 2);
51         solver->addConstraint(pred);
52
53         Predicate *eq = solver->createPredicateOperator(SATC_EQUALS);
54         Element *tmparray2[] = {e1, e2};
55         BooleanEdge pred2 = solver->applyPredicate(eq, tmparray2, 2);
56         solver->addConstraint(pred2);
57         solver->serialize();
58
59         if (solver->solve() == 1)
60                 printf("e1=%" PRIu64 " e2=%" PRIu64 " e3=%" PRIu64 " undefFlag:%d\n",
61                                          solver->getElementValue(e1), solver->getElementValue(e2),
62                                          solver->getElementValue(e3), solver->getBooleanValue(undef));
63         else
64                 printf("UNSAT\n");
65         delete solver;
66 }