00001
00002
00003
00004
00005
00006
00007
00008 #ifndef CLAUSESOLVE_H_
00009 #define CLAUSESOLVE_H_
00010
00011 #include <set>
00012 #include <vector>
00013 #include <map>
00014 #include <list>
00015 using namespace std;
00016 #include "InteractionManager.h"
00017 #include "util.h"
00018 #include "bignum.h"
00019
00020
00021
00022 class CNode;
00023 class VarMap;
00024 class NormalForm;
00025 class Clause;
00026 class Term;
00027 class ILPLeaf;
00028 class EqLeaf;
00029 class Leaf;
00030 class FunctionTerm;
00031 class Matrix;
00032 class Equation;
00033 class Solver;
00034 class ModLeaf;
00035
00036 #include "bignum.h"
00037 #include "SatValue.h"
00038
00039
00040
00041
00042 class ClauseSolve {
00043 friend class InteractionManager;
00044 friend class QueryComparator;
00045 friend class VariableEliminator;
00046 friend class EqualityFinder;
00047
00048 private:
00049 bool repeated_solve;
00050
00051 bool sat;
00052 Clause* cl;
00053 map<Term*, SatValue>* assignments;
00054
00055 map<Term*, bignum> ilp_assignments;
00056
00057
00058
00059
00060
00061 map<Term*, set<Term*> > eq_members;
00062
00063
00064
00065
00066
00067 map<Term*, int> eq_size;
00068
00069
00070
00071
00072
00073 map<Term*, int> eq_class_const;
00074
00075
00076
00077
00078 map<Term*, set<Term*> > eq_parents;
00079
00080
00081
00082
00083 map<int, int> var_to_col_map;
00084
00085
00086
00087
00088 vector<string> vars;
00089
00090
00091
00092
00093 set<int> ilp_vars;
00094
00095
00096
00097
00098 set<int> function_vars;
00099
00100
00101
00102
00103 Matrix* m;
00104
00105
00106
00107
00108
00109 set< set< pair<Equation*, bignum> > > neq_constraints;
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 set<Term*> top_level_terms;
00121
00122
00123
00124
00125 map<Term*, Term*> denestings;
00126
00127
00128
00129
00130 set<Term*> constants;
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 struct history_elem {
00150 Term* old_rep;
00151 set<Term*>* eq_members;
00152 bool has_constant;
00153 int constant;
00154
00155 history_elem(Term* old_rep, set<Term*>& eq_members):old_rep(old_rep),
00156 eq_members(&eq_members)
00157 {
00158
00159 }
00160
00161 };
00162
00163
00164
00165
00166 vector< history_elem > undo_buffer;
00167
00168
00169
00170
00171 int time_denesting;
00172 int time_initial_ilp;
00173 int time_initial_union_find;
00174 int time_total_ilp;
00175 int time_total_union_find;
00176 int time_preparing_queries;
00177 int start;
00178 int num_interaction_queries;
00179
00180
00181
00182 public:
00183 ClauseSolve(CNode* node, map<Term*, SatValue>* assignments = NULL);
00184 ClauseSolve(Clause* clause, map<Term*, SatValue>* assignments = NULL);
00185 ~ClauseSolve();
00186 bool is_sat();
00187 void print_stats();
00188
00189
00190
00191 private:
00192 bool solve(CNode* node);
00193 bool clause_sat();
00194 void init_congruence_classes_term(Term *t, Term* parent,
00195 set<Term*> & cur_parents, set<int> & function_ids);
00196 void init_congruence_classes(set<int> & function_ids,
00197 set<Term*> & eq_terms);
00198 void clear_ilp_representatives(set<ILPLeaf*> & leaves);
00199 void clear_mod_representatives(set<ModLeaf*> & leaves);
00200
00201
00202
00203 bool process_equalities();
00204 bool perform_union(Term* t1, Term* t2);
00205 Term* find_representative(Term* t);
00206 bool congruent(FunctionTerm* f1, FunctionTerm* f2);
00207 string terms_to_string(set<Term*>& eq_class );
00208 bool have_contradictory_constants(Term* rep1, Term* rep2);
00209 bool has_contradiction();
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 bool perform_conditional_union(Term* t1, Term* t2,
00220 set<Term*>& changed_eq_classes, bool& used_function_axiom);
00221 void undo_conditional_union();
00222
00223 void compute_ilp_var_ids();
00224 void build_var_to_col_map();
00225 void construct_ilp_matrix();
00226 void populate_matrix_row(ILPLeaf* l, bool sign);
00227 bool add_inequality(set<pair<Term*, Term*> > disjunctive_ineq,
00228 set< pair<Equation*, bignum> > & new_inequality);
00229 void add_inequality(ILPLeaf* ilp);
00230 void generate_sat_assignment(vector<bignum>* ilp_assignments);
00231 void add_equality(Term* t1, Term* t2);
00232 void print_neq_matrix();
00233 void add_ilp_vars_in_mod_leaf(ModLeaf* ml, bool pos, int counter);
00234 void convert_mod(ModLeaf* ml, bool pos, int counter);
00235 inline void add_ilp_to_matrix(ILPLeaf* ilp);
00236 inline void init_top_level_terms();
00237 inline void init_top_level_terms_eq(set<EqLeaf*>& eq_leaves);
00238 inline void init_top_level_terms_ilp(set<ILPLeaf*>& ilp_leaves);
00239 inline void init_top_level_terms_mod(set<ModLeaf*>& mod_leaves);
00240 void init_top_level_terms_term(Term* t);
00241 void print_congruence_classes();
00242 void clear();
00243 void get_ilp_assignment(vector<bignum>& ilp_assign);
00244 void init(set<VariableTerm*>& vars );
00245
00246
00247
00248
00249
00250 bool check_assignment();
00251
00252 void print_eq_classes();
00253 string eq_classes_to_string();
00254
00255 void init_stats();
00256
00257
00258
00259
00260 };
00261
00262 #endif