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