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);
38 /** This function creates an element variable over a set. */
40 Element *getElementVar(Set *set);
42 /** This function creates an element constrant. */
43 Element *getElementConst(VarType type, uint64_t value);
45 BooleanEdge getBooleanTrue();
47 BooleanEdge getBooleanFalse();
49 /** This function creates a boolean variable. */
51 BooleanEdge getBooleanVar(VarType type);
53 /** This function creates a function operator. */
55 Function *createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,
56 OverFlowBehavior overflowbehavior);
58 /** This function creates a predicate operator. */
60 Predicate *createPredicateOperator(CompOp op, Set **domain, uint numDomain);
62 Predicate *createPredicateTable(Table *table, UndefinedBehavior behavior);
64 /** This function creates an empty instance table.*/
66 Table *createTable(Set **domains, uint numDomain, Set *range);
68 Table *createTableForPredicate(Set **domains, uint numDomain);
69 /** This function adds an input output relation to a table. */
71 void addTableEntry(Table *table, uint64_t *inputs, uint inputSize, uint64_t result);
73 /** This function converts a completed table into a function. */
75 Function *completeTable(Table *, UndefinedBehavior behavior);
77 /** This function applies a function to the Elements in its input. */
79 Element *applyFunction(Function *function, Element **array, uint numArrays, BooleanEdge overflowstatus);
81 /** This function applies a predicate to the Elements in its input. */
83 BooleanEdge applyPredicateTable(Predicate *predicate, Element **inputs, uint numInputs, BooleanEdge undefinedStatus);
85 BooleanEdge applyPredicate(Predicate *predicate, Element **inputs, uint numInputs);
87 /** This function applies a logical operation to the Booleans in its input. */
89 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
91 /** This function applies a logical operation to the Booleans in its input. */
93 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge arg1, BooleanEdge arg2);
95 /** This function applies a logical operation to the Booleans in its input. */
97 BooleanEdge applyLogicalOperation(LogicOp op, BooleanEdge arg);
99 /** This function adds a boolean constraint to the set of constraints
102 void addConstraint(BooleanEdge constraint);
104 /** This function instantiates an order of type type over the set set. */
105 Order *createOrder(OrderType type, Set *set);
107 /** This function instantiates a boolean on two items in an order. */
108 BooleanEdge orderConstraint(Order *order, uint64_t first, uint64_t second);
110 /** When everything is done, the client calls this function and then csolver starts to encode*/
113 /** After getting the solution from the SAT solver, client can get the value of an element via this function*/
114 uint64_t getElementValue(Element *element);
116 /** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
117 bool getBooleanValue(BooleanEdge boolean);
119 bool getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
121 bool isTrue(BooleanEdge b);
122 bool isFalse(BooleanEdge b);
124 void setUnSAT() { unsat = true; }
126 bool isUnSAT() { return unsat; }
128 Vector<Order *> *getOrders() { return &allOrders;}
129 HashsetOrder * getActiveOrders() { return &activeOrders;}
131 Tuner *getTuner() { return tuner; }
133 SetIteratorBooleanEdge * getConstraints() { return constraints.iterator(); }
135 SATEncoder *getSATEncoder() {return satEncoder;}
137 void replaceBooleanWithTrue(BooleanEdge bexpr);
138 void replaceBooleanWithTrueNoRemove(BooleanEdge bexpr);
139 void replaceBooleanWithFalse(BooleanEdge bexpr);
140 void replaceBooleanWithBoolean(BooleanEdge oldb, BooleanEdge newb);
143 void autoTune(uint budget);
145 void setTuner(Tuner *_tuner) { tuner = _tuner; }
146 long long getElapsedTime() { return elapsedTime; }
147 long long getEncodeTime();
148 long long getSolveTime();
153 void handleIFFTrue(BooleanLogic *bexpr, BooleanEdge child);
154 void handleANDTrue(BooleanLogic *bexpr, BooleanEdge child);
156 //These two functions are helpers if the client has a pointer to a
157 //Boolean object that we have since replaced
158 BooleanEdge rewriteLogicalOperation(LogicOp op, BooleanEdge *array, uint asize);
159 BooleanEdge doRewrite(BooleanEdge b);
160 /** This is a vector of constraints that must be satisfied. */
161 HashsetBooleanEdge constraints;
163 /** This is a vector of all boolean structs that we have allocated. */
164 Vector<Boolean *> allBooleans;
166 /** This is a vector of all set structs that we have allocated. */
167 Vector<Set *> allSets;
169 /** This is a vector of all element structs that we have allocated. */
170 Vector<Element *> allElements;
172 /** This is a vector of all predicate structs that we have allocated. */
173 Vector<Predicate *> allPredicates;
175 /** This is a vector of all table structs that we have allocated. */
176 Vector<Table *> allTables;
178 /** This is a vector of all order structs that we have allocated. */
179 Vector<Order *> allOrders;
181 HashsetOrder activeOrders;
183 /** This is a vector of all function structs that we have allocated. */
184 Vector<Function *> allFunctions;
186 BooleanEdge boolTrue;
187 BooleanEdge boolFalse;
189 /** These two tables are used for deduplicating entries. */
190 BooleanMatchMap boolMap;
191 ElementMatchMap elemMap;
193 SATEncoder *satEncoder;
196 long long elapsedTime;