5 #include "corestructs.h"
7 #include "solver_interface.h"
14 /** This function creates a set containing the elements passed in the array. */
15 Set *createSet(VarType type, uint64_t *elements, uint num);
17 /** This function creates a set from lowrange to highrange (inclusive). */
19 Set *createRangeSet(VarType type, uint64_t lowrange, uint64_t highrange);
21 Element *createRangeVar(VarType type, uint64_t lowrange, uint64_t highrange);
23 /** This function creates a mutable set. */
25 MutableSet *createMutableSet(VarType type);
27 /** This function adds a new item to a set. */
29 //Deprecating this unless we need it...
30 void addItem(MutableSet *set, uint64_t element);
32 /** This function adds a new unique item to the set and returns it.
33 This function cannot be used in conjunction with manually adding
36 uint64_t createUniqueItem(MutableSet *set);
39 * Freeze and finalize the mutableSet ...
41 void finalizeMutableSet(MutableSet* set);
43 /** This function creates an element variable over a set. */
45 Element *getElementVar(Set *set);
47 /** This function creates an element constrant. */
48 Element *getElementConst(VarType type, uint64_t value);
50 BooleanEdge getBooleanTrue();
52 BooleanEdge getBooleanFalse();
54 /** This function creates a boolean variable. */
56 BooleanEdge getBooleanVar(VarType type);
58 /** This function creates a function operator. */
60 Function *createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,
61 OverFlowBehavior overflowbehavior);
63 /** This function creates a predicate operator. */
65 Predicate *createPredicateOperator(CompOp op, Set **domain, uint numDomain);
67 Predicate *createPredicateTable(Table *table, UndefinedBehavior behavior);
69 /** This function creates an empty instance table.*/
71 Table *createTable(Set **domains, uint numDomain, Set *range);
73 Table *createTableForPredicate(Set **domains, uint numDomain);
74 /** This function adds an input output relation to a table. */
76 void addTableEntry(Table *table, uint64_t *inputs, uint inputSize, uint64_t result);
78 /** This function converts a completed table into a function. */
80 Function *completeTable(Table *, UndefinedBehavior behavior);
82 /** This function applies a function to the Elements in its input. */
84 Element *applyFunction(Function *function, Element **array, uint numArrays, BooleanEdge overflowstatus);
86 /** This function applies a predicate to the Elements in its input. */
88 BooleanEdge applyPredicateTable(Predicate *predicate, Element **inputs, uint numInputs, BooleanEdge undefinedStatus);
90 BooleanEdge applyPredicate(Predicate *predicate, Element **inputs, uint numInputs);
92 /** This function applies a logical operation to the Booleans in its input. */
94 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
96 /** This function applies a logical operation to the Booleans in its input. */
98 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge arg1, BooleanEdge arg2);
100 /** This function applies a logical operation to the Booleans in its input. */
102 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge arg);
104 /** This function adds a boolean constraint to the set of constraints
107 void addConstraint(BooleanEdge constraint);
109 /** This function instantiates an order of type type over the set set. */
110 Order *createOrder(OrderType type, Set *set);
112 /** This function instantiates a boolean on two items in an order. */
113 BooleanEdge orderConstraint(Order *order, uint64_t first, uint64_t second);
115 /** When everything is done, the client calls this function and then csolver starts to encode*/
118 /** After getting the solution from the SAT solver, client can get the value of an element via this function*/
119 uint64_t getElementValue(Element *element);
121 /** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
122 bool getBooleanValue(BooleanEdge boolean);
124 bool getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
126 bool isTrue(BooleanEdge b);
127 bool isFalse(BooleanEdge b);
129 void setUnSAT() { unsat = true; }
131 bool isUnSAT() { return unsat; }
133 Vector<Order *> *getOrders() { return &allOrders;}
134 HashsetOrder * getActiveOrders() { return &activeOrders;}
136 Tuner *getTuner() { return tuner; }
138 SetIteratorBooleanEdge * getConstraints() { return constraints.iterator(); }
140 SATEncoder *getSATEncoder() {return satEncoder;}
142 void replaceBooleanWithTrue(BooleanEdge bexpr);
143 void replaceBooleanWithTrueNoRemove(BooleanEdge bexpr);
144 void replaceBooleanWithFalse(BooleanEdge bexpr);
145 void replaceBooleanWithBoolean(BooleanEdge oldb, BooleanEdge newb);
148 void autoTune(uint budget);
150 void setTuner(Tuner *_tuner) { tuner = _tuner; }
151 long long getElapsedTime() { return elapsedTime; }
152 long long getEncodeTime();
153 long long getSolveTime();
158 void handleIFFTrue(BooleanLogic *bexpr, BooleanEdge child);
159 void handleANDTrue(BooleanLogic *bexpr, BooleanEdge child);
161 //These two functions are helpers if the client has a pointer to a
162 //Boolean object that we have since replaced
163 BooleanEdge rewriteLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
164 BooleanEdge doRewrite(BooleanEdge b);
165 /** This is a vector of constraints that must be satisfied. */
166 HashsetBooleanEdge constraints;
168 /** This is a vector of all boolean structs that we have allocated. */
169 Vector<Boolean *> allBooleans;
171 /** This is a vector of all set structs that we have allocated. */
172 Vector<Set *> allSets;
174 /** This is a vector of all element structs that we have allocated. */
175 Vector<Element *> allElements;
177 /** This is a vector of all predicate structs that we have allocated. */
178 Vector<Predicate *> allPredicates;
180 /** This is a vector of all table structs that we have allocated. */
181 Vector<Table *> allTables;
183 /** This is a vector of all order structs that we have allocated. */
184 Vector<Order *> allOrders;
186 HashsetOrder activeOrders;
188 /** This is a vector of all function structs that we have allocated. */
189 Vector<Function *> allFunctions;
191 BooleanEdge boolTrue;
192 BooleanEdge boolFalse;
194 /** These two tables are used for deduplicating entries. */
195 BooleanMatchMap boolMap;
196 ElementMatchMap elemMap;
198 SATEncoder *satEncoder;
201 long long elapsedTime;