5 #include "corestructs.h"
7 #include "solver_interface.h"
15 /** This function creates a set containing the elements passed in the array. */
16 Set *createSet(VarType type, uint64_t *elements, uint num);
18 /** This function creates a set from lowrange to highrange (inclusive). */
20 Set *createRangeSet(VarType type, uint64_t lowrange, uint64_t highrange);
22 bool itemExistInSet(Set *set, uint64_t item);
24 VarType getSetVarType(Set *set);
26 Element *createRangeVar(VarType type, uint64_t lowrange, uint64_t highrange);
28 /** This function creates a mutable set.
29 * Note: You should use addItem for adding new item to Mutable sets, and
30 * at the end, you should call finalizeMutableSet!
33 MutableSet *createMutableSet(VarType type);
35 /** This function adds a new item to a set. */
37 //Deprecating this unless we need it...
38 void addItem(MutableSet *set, uint64_t element);
40 /** This function adds a new unique item to the set and returns it.
41 This function cannot be used in conjunction with manually adding
44 uint64_t createUniqueItem(MutableSet *set);
47 * Freeze and finalize the mutableSet ...
49 void finalizeMutableSet(MutableSet *set);
51 /** This function creates an element variable over a set. */
53 Element *getElementVar(Set *set);
55 /** This function creates an element constrant. */
56 Element *getElementConst(VarType type, uint64_t value);
58 Set *getElementRange (Element *element);
60 BooleanEdge getBooleanTrue();
62 BooleanEdge getBooleanFalse();
64 /** This function creates a boolean variable. */
66 BooleanEdge getBooleanVar(VarType type);
68 /** This function creates a function operator. */
70 Function *createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,
71 OverFlowBehavior overflowbehavior);
73 /** This function creates a predicate operator. */
75 Predicate *createPredicateOperator(CompOp op, Set **domain, uint numDomain);
77 Predicate *createPredicateTable(Table *table, UndefinedBehavior behavior);
79 /** This function creates an empty instance table.*/
81 Table *createTable(Set **domains, uint numDomain, Set *range);
83 Table *createTableForPredicate(Set **domains, uint numDomain);
84 /** This function adds an input output relation to a table. */
86 void addTableEntry(Table *table, uint64_t *inputs, uint inputSize, uint64_t result);
88 /** This function converts a completed table into a function. */
90 Function *completeTable(Table *, UndefinedBehavior behavior);
92 /** This function applies a function to the Elements in its input. */
94 Element *applyFunction(Function *function, Element **array, uint numArrays, BooleanEdge overflowstatus);
96 /** This function applies a predicate to the Elements in its input. */
98 BooleanEdge applyPredicateTable(Predicate *predicate, Element **inputs, uint numInputs, BooleanEdge undefinedStatus);
100 BooleanEdge applyPredicate(Predicate *predicate, Element **inputs, uint numInputs);
102 /** This function applies a logical operation to the Booleans in its input. */
104 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
106 /** This function applies a logical operation to the Booleans in its input. */
108 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge arg1, BooleanEdge arg2);
110 /** This function applies a logical operation to the Booleans in its input. */
112 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge arg);
114 /** This function adds a boolean constraint to the set of constraints
117 void addConstraint(BooleanEdge constraint);
119 /** This function instantiates an order of type type over the set set. */
120 Order *createOrder(OrderType type, Set *set);
122 /** This function instantiates a boolean on two items in an order. */
123 BooleanEdge orderConstraint(Order *order, uint64_t first, uint64_t second);
125 /** When everything is done, the client calls this function and then csolver starts to encode*/
128 /** After getting the solution from the SAT solver, client can get the value of an element via this function*/
129 uint64_t getElementValue(Element *element);
131 /** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
132 bool getBooleanValue(BooleanEdge boolean);
134 bool getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
136 bool isTrue(BooleanEdge b);
137 bool isFalse(BooleanEdge b);
139 void setUnSAT() { model_print("Setting UNSAT %%%%%%\n"); unsat = true; }
140 bool isUnSAT() { return unsat; }
142 void printConstraint(BooleanEdge boolean);
143 void printConstraints();
145 Vector<Order *> *getOrders() { return &allOrders;}
146 HashsetOrder *getActiveOrders() { return &activeOrders;}
148 Tuner *getTuner() { return tuner; }
150 SetIteratorBooleanEdge *getConstraints() { return constraints.iterator(); }
152 SATEncoder *getSATEncoder() {return satEncoder;}
154 void replaceBooleanWithTrue(BooleanEdge bexpr);
155 void replaceBooleanWithTrueNoRemove(BooleanEdge bexpr);
156 void replaceBooleanWithFalseNoRemove(BooleanEdge bexpr);
157 void replaceBooleanWithFalse(BooleanEdge bexpr);
158 void replaceBooleanWithBoolean(BooleanEdge oldb, BooleanEdge newb);
160 // Set* addItemsToRange(Element* element, uint num, ...);
162 static CSolver *deserialize(const char *file);
163 void autoTune(uint budget);
164 void inferFixedOrders();
165 void inferFixedOrder(Order *order);
168 void setTuner(Tuner *_tuner) { tuner = _tuner; }
169 long long getElapsedTime() { return elapsedTime; }
170 long long getEncodeTime();
171 long long getSolveTime();
176 void handleIFFTrue(BooleanLogic *bexpr, BooleanEdge child);
177 void handleANDTrue(BooleanLogic *bexpr, BooleanEdge child);
178 void handleFunction(ElementFunction * ef, BooleanEdge child);
180 //These two functions are helpers if the client has a pointer to a
181 //Boolean object that we have since replaced
182 BooleanEdge rewriteLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
183 BooleanEdge doRewrite(BooleanEdge b);
184 /** This is a vector of constraints that must be satisfied. */
185 HashsetBooleanEdge constraints;
187 /** This is a vector of all boolean structs that we have allocated. */
188 Vector<Boolean *> allBooleans;
190 /** This is a vector of all set structs that we have allocated. */
191 Vector<Set *> allSets;
193 /** This is a vector of all element structs that we have allocated. */
194 Vector<Element *> allElements;
196 /** This is a vector of all predicate structs that we have allocated. */
197 Vector<Predicate *> allPredicates;
199 /** This is a vector of all table structs that we have allocated. */
200 Vector<Table *> allTables;
202 /** This is a vector of all order structs that we have allocated. */
203 Vector<Order *> allOrders;
205 HashsetOrder activeOrders;
207 /** This is a vector of all function structs that we have allocated. */
208 Vector<Function *> allFunctions;
210 BooleanEdge boolTrue;
211 BooleanEdge boolFalse;
213 /** These two tables are used for deduplicating entries. */
214 BooleanMatchMap boolMap;
215 ElementMatchMap elemMap;
217 SATEncoder *satEncoder;
220 long long elapsedTime;