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 VarType getSetVarType(Set *set);
24 Element *createRangeVar(VarType type, uint64_t lowrange, uint64_t highrange);
26 /** This function creates a mutable set. */
28 MutableSet *createMutableSet(VarType type);
30 /** This function adds a new item to a set. */
32 //Deprecating this unless we need it...
33 void addItem(MutableSet *set, uint64_t element);
35 /** This function adds a new unique item to the set and returns it.
36 This function cannot be used in conjunction with manually adding
39 uint64_t createUniqueItem(MutableSet *set);
42 * Freeze and finalize the mutableSet ...
44 void finalizeMutableSet(MutableSet *set);
46 /** This function creates an element variable over a set. */
48 Element *getElementVar(Set *set);
50 /** This function creates an element constrant. */
51 Element *getElementConst(VarType type, uint64_t value);
53 Set *getElementRange (Element *element);
55 BooleanEdge getBooleanTrue();
57 BooleanEdge getBooleanFalse();
59 /** This function creates a boolean variable. */
61 BooleanEdge getBooleanVar(VarType type);
63 /** This function creates a function operator. */
65 Function *createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,
66 OverFlowBehavior overflowbehavior);
68 /** This function creates a predicate operator. */
70 Predicate *createPredicateOperator(CompOp op, Set **domain, uint numDomain);
72 Predicate *createPredicateTable(Table *table, UndefinedBehavior behavior);
74 /** This function creates an empty instance table.*/
76 Table *createTable(Set **domains, uint numDomain, Set *range);
78 Table *createTableForPredicate(Set **domains, uint numDomain);
79 /** This function adds an input output relation to a table. */
81 void addTableEntry(Table *table, uint64_t *inputs, uint inputSize, uint64_t result);
83 /** This function converts a completed table into a function. */
85 Function *completeTable(Table *, UndefinedBehavior behavior);
87 /** This function applies a function to the Elements in its input. */
89 Element *applyFunction(Function *function, Element **array, uint numArrays, BooleanEdge overflowstatus);
91 /** This function applies a predicate to the Elements in its input. */
93 BooleanEdge applyPredicateTable(Predicate *predicate, Element **inputs, uint numInputs, BooleanEdge undefinedStatus);
95 BooleanEdge applyPredicate(Predicate *predicate, Element **inputs, uint numInputs);
97 /** This function applies a logical operation to the Booleans in its input. */
99 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
101 /** This function applies a logical operation to the Booleans in its input. */
103 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge arg1, BooleanEdge arg2);
105 /** This function applies a logical operation to the Booleans in its input. */
107 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge arg);
109 /** This function adds a boolean constraint to the set of constraints
112 void addConstraint(BooleanEdge constraint);
114 /** This function instantiates an order of type type over the set set. */
115 Order *createOrder(OrderType type, Set *set);
117 /** This function instantiates a boolean on two items in an order. */
118 BooleanEdge orderConstraint(Order *order, uint64_t first, uint64_t second);
120 /** When everything is done, the client calls this function and then csolver starts to encode*/
123 /** After getting the solution from the SAT solver, client can get the value of an element via this function*/
124 uint64_t getElementValue(Element *element);
126 /** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
127 bool getBooleanValue(BooleanEdge boolean);
129 bool getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
131 bool isTrue(BooleanEdge b);
132 bool isFalse(BooleanEdge b);
134 void setUnSAT() { model_print("Setting UNSAT %%%%%%\n"); unsat = true; }
135 bool isUnSAT() { return unsat; }
137 void printConstraint(BooleanEdge boolean);
138 void printConstraints();
140 Vector<Order *> *getOrders() { return &allOrders;}
141 HashsetOrder *getActiveOrders() { return &activeOrders;}
143 Tuner *getTuner() { return tuner; }
145 SetIteratorBooleanEdge *getConstraints() { return constraints.iterator(); }
147 SATEncoder *getSATEncoder() {return satEncoder;}
149 void replaceBooleanWithTrue(BooleanEdge bexpr);
150 void replaceBooleanWithTrueNoRemove(BooleanEdge bexpr);
151 void replaceBooleanWithFalseNoRemove(BooleanEdge bexpr);
152 void replaceBooleanWithFalse(BooleanEdge bexpr);
153 void replaceBooleanWithBoolean(BooleanEdge oldb, BooleanEdge newb);
156 static CSolver* deserialize(const char * file);
157 void autoTune(uint budget);
158 void inferFixedOrders();
159 void inferFixedOrder(Order *order);
162 void setTuner(Tuner *_tuner) { tuner = _tuner; }
163 long long getElapsedTime() { return elapsedTime; }
164 long long getEncodeTime();
165 long long getSolveTime();
170 void handleIFFTrue(BooleanLogic *bexpr, BooleanEdge child);
171 void handleANDTrue(BooleanLogic *bexpr, BooleanEdge child);
173 //These two functions are helpers if the client has a pointer to a
174 //Boolean object that we have since replaced
175 BooleanEdge rewriteLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
176 BooleanEdge doRewrite(BooleanEdge b);
177 /** This is a vector of constraints that must be satisfied. */
178 HashsetBooleanEdge constraints;
180 /** This is a vector of all boolean structs that we have allocated. */
181 Vector<Boolean *> allBooleans;
183 /** This is a vector of all set structs that we have allocated. */
184 Vector<Set *> allSets;
186 /** This is a vector of all element structs that we have allocated. */
187 Vector<Element *> allElements;
189 /** This is a vector of all predicate structs that we have allocated. */
190 Vector<Predicate *> allPredicates;
192 /** This is a vector of all table structs that we have allocated. */
193 Vector<Table *> allTables;
195 /** This is a vector of all order structs that we have allocated. */
196 Vector<Order *> allOrders;
198 HashsetOrder activeOrders;
200 /** This is a vector of all function structs that we have allocated. */
201 Vector<Function *> allFunctions;
203 BooleanEdge boolTrue;
204 BooleanEdge boolFalse;
206 /** These two tables are used for deduplicating entries. */
207 BooleanMatchMap boolMap;
208 ElementMatchMap elemMap;
210 SATEncoder *satEncoder;
213 long long elapsedTime;