Switch to vector class
[satune.git] / src / csolver.h
1 #ifndef CSOLVER_H
2 #define CSOLVER_H
3 #include "classlist.h"
4 #include "ops.h"
5 #include "structs.h"
6
7 class CSolver {
8  public:
9         CSolver();
10         ~CSolver();
11         
12         SATEncoder *satEncoder;
13         bool unsat;
14         Tuner *tuner;
15         
16         /** This is a vector of constraints that must be satisfied. */
17         HashSetBoolean *constraints;
18
19         /** This is a vector of all boolean structs that we have allocated. */
20         Vector<Boolean *> allBooleans;
21
22         /** This is a vector of all set structs that we have allocated. */
23         Vector<Set *> allSets;
24
25         /** This is a vector of all element structs that we have allocated. */
26         Vector<Element *> allElements;
27
28         /** This is a vector of all predicate structs that we have allocated. */
29         Vector<Predicate *> allPredicates;
30
31         /** This is a vector of all table structs that we have allocated. */
32         Vector<Table *> allTables;
33
34         /** This is a vector of all order structs that we have allocated. */
35         Vector<Order *> allOrders;
36
37         /** This is a vector of all function structs that we have allocated. */
38         Vector<Function *> allFunctions;
39
40         /** This function creates a set containing the elements passed in the array. */
41
42         Set *createSet(VarType type, uint64_t *elements, uint num);
43
44         /** This function creates a set from lowrange to highrange (inclusive). */
45
46         Set *createRangeSet(VarType type, uint64_t lowrange, uint64_t highrange);
47         
48         /** This function creates a mutable set. */
49         
50         MutableSet *createMutableSet(VarType type);
51
52         /** This function adds a new item to a set. */
53
54         void addItem(MutableSet *set, uint64_t element);
55
56         /** This function adds a new unique item to the set and returns it.
57                         This function cannot be used in conjunction with manually adding
58                         items to the set. */
59         
60         uint64_t createUniqueItem(MutableSet *set);
61
62         /** This function creates an element variable over a set. */
63
64         Element *getElementVar(Set *set);
65
66         /** This function creates an element constrant. */
67         Element *getElementConst(VarType type, uint64_t value);
68
69         /** This function creates a boolean variable. */
70
71         Boolean *getBooleanVar(VarType type);
72
73         /** This function creates a function operator. */
74
75         Function *createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,
76                                                                                                                                          OverFlowBehavior overflowbehavior);
77
78         /** This function creates a predicate operator. */
79
80         Predicate *createPredicateOperator(CompOp op, Set **domain, uint numDomain);
81
82         Predicate *createPredicateTable(Table *table, UndefinedBehavior behavior);
83
84         /** This function creates an empty instance table.*/
85
86         Table *createTable(Set **domains, uint numDomain, Set *range);
87
88         Table *createTableForPredicate(Set **domains, uint numDomain);
89         /** This function adds an input output relation to a table. */
90
91         void addTableEntry(Table *table, uint64_t *inputs, uint inputSize, uint64_t result);
92
93         /** This function converts a completed table into a function. */
94
95         Function *completeTable(Table *, UndefinedBehavior behavior);
96
97         /** This function applies a function to the Elements in its input. */
98
99         Element *applyFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus);
100
101         /** This function applies a predicate to the Elements in its input. */
102
103         Boolean *applyPredicateTable(Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus);
104
105         Boolean *applyPredicate(Predicate *predicate, Element **inputs, uint numInputs);
106
107         /** This function applies a logical operation to the Booleans in its input. */
108
109         Boolean *applyLogicalOperation(LogicOp op, Boolean **array, uint asize);
110
111         /** This function adds a boolean constraint to the set of constraints
112                         to be satisfied */
113
114         void addConstraint(Boolean *constraint);
115
116         /** This function instantiates an order of type type over the set set. */
117         Order *createOrder(OrderType type, Set *set);
118
119         /** This function instantiates a boolean on two items in an order. */
120         Boolean *orderConstraint(Order *order, uint64_t first, uint64_t second);
121
122         /** When everything is done, the client calls this function and then csolver starts to encode*/
123         int startEncoding();
124
125         /** After getting the solution from the SAT solver, client can get the value of an element via this function*/
126         uint64_t getElementValue(Element *element);
127
128         /** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
129         bool getBooleanValue(Boolean *boolean);
130
131         HappenedBefore getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
132
133         MEMALLOC;
134 };
135
136 #endif