Merge branch 'master' into brian
[satune.git] / src / Test / buildconstraints.c
1 #include "csolver.h"
2
3 int main(int numargs, char ** argv) {
4         CSolver * solver=allocCSolver();
5         uint64_t set1[]={0, 1, 2};
6         Set * s=createSet(solver, 0, set1, 3);
7         Element * e1=getElementVar(solver, s);
8         Element * e2=getElementVar(solver, s);
9         Set * domain[]={s, s};
10         Predicate *equals=createPredicateOperator(solver, EQUALS, domain, 2);
11         Element * inputs[]={e1, e2};
12         Boolean * b=applyPredicate(solver, equals, inputs, 2);
13         addBoolean(solver, b);
14         Order * o=createOrder(solver, TOTAL, s);
15         Boolean * oc=orderConstraint(solver, o, 1, 2);
16         addBoolean(solver, oc);
17                 
18         uint64_t set2[] = {2, 3};
19         Set* rangef1 = createSet(solver, 1, set2, 2);
20         Function * f1 = createFunctionOperator(solver, ADD, domain, 2, rangef1, IGNORE);
21         
22         Table* table = createTable(solver, domain, 2, s);
23         uint64_t row1[] = {0, 1};
24         uint64_t row2[] = {1, 1};
25         uint64_t row3[] = {2, 1};
26         uint64_t row4[] = {1, 2};
27         addTableEntry(solver, table, row1, 2, 0);
28         addTableEntry(solver, table, row2, 2, 1);
29         addTableEntry(solver, table, row3, 2, 2);
30         addTableEntry(solver, table, row4, 2, 2);
31         Function * f2 = completeTable(solver, table); //its range would be as same as s
32         
33         Boolean* overflow = getBooleanVar(solver , 2);
34         Element * e3 = applyFunction(solver, f1, inputs, 2, overflow);
35         Element * e4 = applyFunction(solver, f2, inputs, 2, overflow);
36         Set* domain2[] = {s,rangef1};
37         Predicate* equal2 = createPredicateOperator(solver, EQUALS, domain2, 2);
38         Element* inputs2 [] = {e4, e3};
39         Boolean* pred = applyPredicate(solver, equal2, inputs2, 2);
40         addBoolean(solver, pred);
41         
42         startEncoding(solver);
43         deleteSolver(solver);
44 }