fix bug
[satune.git] / src / csolver.h
index 0093586600778d9c34bc4615884df69a45f3f25d..e8527f0eed35b418a41b03c453469bfd8f5c93e4 100644 (file)
 #include "ops.h"
 #include "structs.h"
 
-struct CSolver {
-       VectorBoolean * constraints;
-       VectorBoolean * allBooleans;
-       VectorSet * allSets;
-       VectorElement * allElements;
-       VectorPredicate * allPredicates;
-       VectorTable * allTables;
-};
+class CSolver {
+ public:
+       CSolver();
+       ~CSolver();
+       
+       SATEncoder *satEncoder;
+       bool unsat;
+       Tuner *tuner;
+       
+       /** This is a vector of constraints that must be satisfied. */
+       HashSetBoolean *constraints;
+
+       /** This is a vector of all boolean structs that we have allocated. */
+       VectorBoolean *allBooleans;
+
+       /** This is a vector of all set structs that we have allocated. */
+       VectorSet *allSets;
+
+       /** This is a vector of all element structs that we have allocated. */
+       VectorElement *allElements;
+
+       /** This is a vector of all predicate structs that we have allocated. */
+       VectorPredicate *allPredicates;
+
+       /** This is a vector of all table structs that we have allocated. */
+       VectorTable *allTables;
+
+       /** This is a vector of all order structs that we have allocated. */
+       VectorOrder *allOrders;
 
-/** Create a new solver instance. */
+       /** This is a vector of all function structs that we have allocated. */
+       VectorFunction *allFunctions;
 
-CSolver * allocCSolver();
+       /** This function creates a set containing the elements passed in the array. */
 
-/** This function creates a set containing the elements passed in the array. */
+       Set *createSet(VarType type, uint64_t *elements, uint num);
 
-Set * createSet(CSolver *, VarType type, uint64_t * elements, uint num);
+       /** This function creates a set from lowrange to highrange (inclusive). */
 
-/** This function creates a set from lowrange to highrange (inclusive). */
+       Set *createRangeSet(VarType type, uint64_t lowrange, uint64_t highrange);
+       
+       /** This function creates a mutable set. */
+       
+       MutableSet *createMutableSet(VarType type);
 
-Set * createRangeSet(CSolver *, VarType type, uint64_t lowrange, uint64_t highrange);
+       /** This function adds a new item to a set. */
 
-/** This function creates a mutable set. */
+       void addItem(MutableSet *set, uint64_t element);
 
-MutableSet * createMutableSet(CSolver *, VarType type);
+       /** This function adds a new unique item to the set and returns it.
+                       This function cannot be used in conjunction with manually adding
+                       items to the set. */
+       
+       uint64_t createUniqueItem(MutableSet *set);
 
-/** This function adds a new item to a set. */
+       /** This function creates an element variable over a set. */
 
-void addItem(CSolver *, MutableSet * set, uint64_t element);
+       Element *getElementVar(Set *set);
 
-/** This function adds a new unique item to the set and returns it.
-    This function cannot be used in conjunction with manually adding
-    items to the set. */
+       /** This function creates an element constrant. */
+       Element *getElementConst(VarType type, uint64_t value);
 
-uint64_t createUniqueItem(CSolver *, MutableSet * set);
+       /** This function creates a boolean variable. */
 
-/** This function creates an element variable over a set. */
+       Boolean *getBooleanVar(VarType type);
 
-Element * getElementVar(CSolver *, Set * set);
+       /** This function creates a function operator. */
 
-/** This function creates a boolean variable. */
+       Function *createFunctionOperator(ArithOp op, Set **domain, uint numDomain, Set *range,
+                                                                                                                                        OverFlowBehavior overflowbehavior);
 
-Boolean * getBooleanVar(CSolver *, VarType type);
+       /** This function creates a predicate operator. */
 
-/** This function creates a function operator. */
+       Predicate *createPredicateOperator(CompOp op, Set **domain, uint numDomain);
 
-Function * createFunctionOperator(CSolver *solver, enum ArithOp op, Set ** domain, uint numDomain, Set * range,
-                                                                                                                                       enum OverFlowBehavior overflowbehavior, Boolean * overflowstatus);
+       Predicate *createPredicateTable(Table *table, UndefinedBehavior behavior);
 
-/** This function creates a predicate operator. */
+       /** This function creates an empty instance table.*/
 
-Predicate * createPredicateOperator(CSolver *solver, enum CompOp op, Set ** domain, uint numDomain);
+       Table *createTable(Set **domains, uint numDomain, Set *range);
 
-/** This function creates an empty instance table.*/
+       Table *createTableForPredicate(Set **domains, uint numDomain);
+       /** This function adds an input output relation to a table. */
 
-Table * createTable(CSolver *solver, Set **domains, uint numDomain, Set * range);
+       void addTableEntry(Table *table, uint64_t *inputs, uint inputSize, uint64_t result);
 
-/** This function adds an input output relation to a table. */
+       /** This function converts a completed table into a function. */
 
-void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSize, uint64_t result);
+       Function *completeTable(Table *, UndefinedBehavior behavior);
 
-/** This function converts a completed table into a function. */
+       /** This function applies a function to the Elements in its input. */
 
-Function * completeTable(CSolver *, Table *);
+       Element *applyFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus);
 
-/** This function applies a function to the Elements in its input. */
+       /** This function applies a predicate to the Elements in its input. */
 
-Element * applyFunction(CSolver *, Function * function, Element ** array);
+       Boolean *applyPredicateTable(Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus);
 
-/** This function applies a predicate to the Elements in its input. */
+       Boolean *applyPredicate(Predicate *predicate, Element **inputs, uint numInputs);
 
-Boolean * applyPredicate(CSolver *, Predicate * predicate, Element ** inputs);
+       /** This function applies a logical operation to the Booleans in its input. */
 
-/** This function applies a logical operation to the Booleans in its input. */
+       Boolean *applyLogicalOperation(LogicOp op, Boolean **array, uint asize);
 
-Boolean * applyLogicalOperation(CSolver *, enum LogicOp op, Boolean ** array);
+       /** This function adds a boolean constraint to the set of constraints
+                       to be satisfied */
 
-/** This function adds a boolean constraint to the set of constraints
-    to be satisfied */
+       void addConstraint(Boolean *constraint);
 
-void addBoolean(CSolver *, Boolean * constraint);
+       /** This function instantiates an order of type type over the set set. */
+       Order *createOrder(OrderType type, Set *set);
 
-/** This function instantiates an order of type type over the set set. */
-Order * createOrder(CSolver *, enum OrderType type, Set * set);
+       /** This function instantiates a boolean on two items in an order. */
+       Boolean *orderConstraint(Order *order, uint64_t first, uint64_t second);
+
+       /** When everything is done, the client calls this function and then csolver starts to encode*/
+       int startEncoding();
+
+       /** After getting the solution from the SAT solver, client can get the value of an element via this function*/
+       uint64_t getElementValue(Element *element);
+
+       /** After getting the solution from the SAT solver, client can get the value of a boolean via this function*/
+       bool getBooleanValue(Boolean *boolean);
+
+       HappenedBefore getOrderConstraintValue(Order *order, uint64_t first, uint64_t second);
+
+       MEMALLOC;
+};
 
-/** This function instantiates a boolean on two items in an order. */
-Boolean * orderConstraint(CSolver *, Order * order, uint64_t first, uint64_t second);
 #endif