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