00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _cvcl__include__search_sat_h_
00031 #define _cvcl__include__search_sat_h_
00032
00033 #include <vector>
00034 #include "search.h"
00035 #include "smartcdo.h"
00036 #include "cdlist.h"
00037 #include "cnf_manager.h"
00038 #include "expr.h"
00039 #include "dpllt.h"
00040 #include "theory_core.h"
00041
00042 namespace CVCL {
00043
00044
00045
00046 class SearchSat :public SearchEngine {
00047
00048
00049 std::string d_name;
00050
00051
00052 CDO<int> d_bottomScope;
00053
00054
00055 CDO<Expr> d_lastCheck;
00056
00057
00058
00059 CDO<Theorem> d_lastValid;
00060
00061
00062 CDList<Theorem> d_userAssumptions;
00063
00064
00065 CDList<Theorem> d_intAssumptions;
00066
00067
00068 CDO<unsigned> d_idxUserAssump;
00069
00070 TheoryCore::CoreSatAPI* d_coreSatAPI;
00071
00072
00073 SAT::DPLLT* d_dpllt;
00074
00075
00076 SAT::DPLLT::TheoryAPI* d_theoryAPI;
00077
00078
00079 SAT::DPLLT::Decider* d_decider;
00080
00081
00082 CDMap<Expr, Theorem> d_theorems;
00083
00084
00085 SAT::CNF_Manager *d_cnfManager;
00086
00087
00088 std::vector<SmartCDO<SAT::Var::Val> > d_vars;
00089
00090
00091 bool d_inCheckSat;
00092
00093
00094 SAT::CD_CNF_Formula d_lemmas;
00095
00096
00097 CDO<unsigned> d_lemmasNext;
00098
00099
00100 CDList<SAT::Lit> d_rootLits;
00101
00102
00103 CDO<unsigned> d_lastRegisteredVar;
00104
00105
00106 CDO<bool> d_dplltReady;
00107
00108 CDO<unsigned> d_nextImpliedLiteral;
00109
00110
00111
00112
00113
00114
00115 friend class Restorer;
00116 class Restorer :public ContextNotifyObj {
00117 SearchSat* d_ss;
00118 public:
00119 Restorer(Context* context, SearchSat* ss)
00120 : ContextNotifyObj(context), d_ss(ss) {}
00121 void notifyPre()
00122 { if (!d_ss->d_inCheckSat && d_context->level() == d_ss->getBottomScope())
00123 d_ss->restoreDPLLT(); }
00124 };
00125
00126 Restorer d_restorer;
00127
00128 private:
00129
00130
00131 void restoreDPLLT() { d_dpllt->returnFromSat(); }
00132
00133 friend class SearchSatCoreSatAPI;
00134
00135 void addLemma(const Theorem& thm);
00136
00137 int getBottomScope() { return d_bottomScope; }
00138
00139 void addSplitter(const Expr& e, int priority);
00140
00141 friend class SearchSatTheoryAPI;
00142
00143 void assertLit(SAT::Lit l);
00144
00145 SAT::DPLLT::ConsistentResult checkConsistent(SAT::Clause& c,bool fullEffort);
00146
00147 SAT::Lit getImplication();
00148
00149 void getExplanation(SAT::Lit l, SAT::Clause& c);
00150
00151 bool getNewClauses(SAT::CNF_Formula& cnf);
00152
00153 friend class SearchSatDecider;
00154
00155 SAT::Lit makeDecision();
00156
00157
00158
00159
00160
00161
00162
00163 bool findSplitterRec(SAT::Lit lit, SAT::Var::Val value,
00164 SAT::Lit* litDecision);
00165
00166
00167 SAT::Var::Val getValue(SAT::Lit c) {
00168 DebugAssert(!c.isVar() || unsigned(c.getVar()) < d_vars.size(),
00169 "Lit out of bounds in getValue");
00170 return c.isFalse() ? SAT::Var::FALSE : c.isTrue() ? SAT::Var::TRUE :
00171 c.isInverted() ? SAT::Var::invertValue(d_vars[c.getVar()]) :
00172 d_vars[c.getVar()]; }
00173
00174
00175 void setValue(SAT::Var v, SAT::Var::Val val) {
00176 DebugAssert(!v.isNull(), "expected non-null Var");
00177 DebugAssert(unsigned(v) < d_vars.size(), "Var out of bounds in getValue");
00178 d_vars[v] = val; }
00179
00180
00181 bool checkJustified(SAT::Var v)
00182 { return d_cnfManager->concreteLit(v).isJustified(); }
00183
00184
00185 void setJustified(SAT::Var v)
00186 { d_cnfManager->concreteLit(v).setJustified(); }
00187
00188
00189 Theorem check(const Expr& e, bool isRestart = false);
00190
00191 public:
00192
00193
00194 SearchSat(TheoryCore* core);
00195
00196
00197 virtual ~SearchSat();
00198
00199
00200 virtual const std::string& getName() { return d_name; }
00201 virtual void registerAtom(const Expr& e);
00202 virtual Theorem getImpliedLiteral();
00203 virtual Theorem checkValid(const Expr& e) { return check(e); }
00204 virtual Theorem restart(const Expr& e) { return check(e, true); }
00205 virtual void returnFromCheck();
00206 virtual Theorem lastThm() { return d_lastValid; }
00207 virtual Theorem newUserAssumption(const Expr& e, int scope = -1);
00208 virtual void getUserAssumptions(std::vector<Expr>& assumptions);
00209 virtual void getInternalAssumptions(std::vector<Expr>& assumptions);
00210 virtual void getAssumptions(std::vector<Expr>& assumptions);
00211 virtual bool isAssumption(const Expr& e);
00212 virtual void getCounterExample(std::vector<Expr>& assertions,
00213 bool inOrder = true);
00214 virtual Proof getProof();
00215
00216 };
00217
00218 }
00219
00220 #endif