merge
[satune.git] / src / csolver.h
1 #ifndef CSOLVER_H
2 #define CSOLVER_H
3 #include "classlist.h"
4 #include "ops.h"
5 #include "structs.h"
6
7 struct CSolver {
8         /** This is a vector of constraints that must be satisfied. */
9         VectorBoolean * constraints;
10
11         /** This is a vector of all boolean structs that we have allocated. */
12         VectorBoolean * allBooleans;
13
14         /** This is a vector of all set structs that we have allocated. */
15         VectorSet * allSets;
16
17         /** This is a vector of all element structs that we have allocated. */
18         VectorElement * allElements;
19
20         /** This is a vector of all predicate structs that we have allocated. */
21         VectorPredicate * allPredicates;
22
23         /** This is a vector of all table structs that we have allocated. */
24         VectorTable * allTables;
25
26         /** This is a vector of all order structs that we have allocated. */
27         VectorOrder * allOrders;
28
29         /** This is a vector of all function structs that we have allocated. */
30         VectorFunction* allFunctions;
31 };
32
33 /** Create a new solver instance. */
34
35 CSolver * allocCSolver();
36
37 /** Delete solver instance. */
38
39 void deleteSolver(CSolver * This);
40
41 /** This function creates a set containing the elements passed in the array. */
42
43 Set * createSet(CSolver *, VarType type, uint64_t * elements, uint num);
44
45 /** This function creates a set from lowrange to highrange (inclusive). */
46
47 Set * createRangeSet(CSolver *, VarType type, uint64_t lowrange, uint64_t highrange);
48
49 /** This function creates a mutable set. */
50
51 MutableSet * createMutableSet(CSolver *, VarType type);
52
53 /** This function adds a new item to a set. */
54
55 void addItem(CSolver *, MutableSet * set, uint64_t element);
56
57 /** This function adds a new unique item to the set and returns it.
58     This function cannot be used in conjunction with manually adding
59     items to the set. */
60
61 uint64_t createUniqueItem(CSolver *, MutableSet * set);
62
63 /** This function creates an element variable over a set. */
64
65 Element * getElementVar(CSolver *, Set * set);
66
67 /** This function creates a boolean variable. */
68
69 Boolean * getBooleanVar(CSolver *, VarType type);
70
71 /** This function creates a function operator. */
72
73 Function * createFunctionOperator(CSolver *solver, ArithOp op, Set ** domain, uint numDomain, Set * range,
74                                                                                                                                         OverFlowBehavior overflowbehavior);
75
76 /** This function creates a predicate operator. */
77
78 Predicate * createPredicateOperator(CSolver *solver, CompOp op, Set ** domain, uint numDomain);
79
80 /** This function creates an empty instance table.*/
81
82 Table * createTable(CSolver *solver, Set **domains, uint numDomain, Set * range);
83
84 /** This function adds an input output relation to a table. */
85
86 void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSize, uint64_t result);
87
88 /** This function converts a completed table into a function. */
89
90 Function * completeTable(CSolver *, Table *);
91
92 /** This function applies a function to the Elements in its input. */
93
94 Element * applyFunction(CSolver *, Function * function, Element ** array, uint numArrays, Boolean * overflowstatus);
95
96 /** This function applies a predicate to the Elements in its input. */
97
98 Boolean * applyPredicate(CSolver *, Predicate * predicate, Element ** inputs, uint numInputs);
99
100 /** This function applies a logical operation to the Booleans in its input. */
101
102 Boolean * applyLogicalOperation(CSolver *, LogicOp op, Boolean ** array, uint asize);
103
104 /** This function adds a boolean constraint to the set of constraints
105     to be satisfied */
106
107 void addBoolean(CSolver *, Boolean * constraint);
108
109 /** This function instantiates an order of type type over the set set. */
110 Order * createOrder(CSolver *, OrderType type, Set * set);
111
112 /** This function instantiates a boolean on two items in an order. */
113 Boolean * orderConstraint(CSolver *, Order * order, uint64_t first, uint64_t second);
114
115 /** When everything is done, the client calls this function and then csolver starts to encode*/
116 void startEncoding(CSolver*);
117 #endif