1 /********************* */
4 ** Original author: dejan
6 ** Minor contributors (to current version):
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009-2014 The Analysis of Computer Systems Group (ACSys)
9 ** Courant Institute of Mathematical Sciences
10 ** New York University
11 ** See the file COPYING in the top-level source directory for licensing
12 ** information.\endverbatim
16 ** Implementation of the minisat for cvc4 (bitvectors).
19 #include "cvc4_private.h"
23 #include "prop/sat_solver.h"
24 #include "prop/sat_solver_registry.h"
25 #include "prop/bvminisat/simp/SimpSolver.h"
26 #include "context/cdo.h"
31 class BVMinisatSatSolver
: public BVSatSolverInterface
, public context::ContextNotifyObj
{
35 class MinisatNotify
: public BVMinisat::Notify
{
36 BVSatSolverInterface::Notify
* d_notify
;
38 MinisatNotify(BVSatSolverInterface::Notify
* notify
)
41 bool notify(BVMinisat::Lit lit
) {
42 return d_notify
->notify(toSatLiteral(lit
));
44 void notify(BVMinisat::vec
<BVMinisat::Lit
>& clause
) {
46 toSatClause(clause
, satClause
);
47 d_notify
->notify(satClause
);
51 d_notify
->safePoint();
55 BVMinisat::SimpSolver
* d_minisat
;
56 MinisatNotify
* d_minisatNotify
;
58 unsigned d_assertionsCount
;
59 context::CDO
<unsigned> d_assertionsRealCount
;
60 context::CDO
<unsigned> d_lastPropagation
;
64 void contextNotifyPop();
68 BVMinisatSatSolver() :
69 ContextNotifyObj(NULL
, false),
70 d_assertionsRealCount(NULL
, (unsigned)0),
71 d_lastPropagation(NULL
, (unsigned)0),
74 BVMinisatSatSolver(context::Context
* mainSatContext
, const std::string
& name
= "");
75 ~BVMinisatSatSolver() throw(AssertionException
);
77 void setNotify(Notify
* notify
);
79 void addClause(SatClause
& clause
, bool removable
, uint64_t proof_id
);
83 SatVariable
newVar(bool isTheoryAtom
= false, bool preRegister
= false, bool canErase
= true);
85 SatVariable
trueVar() { return d_minisat
->trueVar(); }
86 SatVariable
falseVar() { return d_minisat
->falseVar(); }
88 void markUnremovable(SatLiteral lit
);
95 SatValue
solve(long unsigned int&);
96 void getUnsatCore(SatClause
& unsatCore
);
98 SatValue
value(SatLiteral l
);
99 SatValue
modelValue(SatLiteral l
);
101 void unregisterVar(SatLiteral lit
);
102 void renewVar(SatLiteral lit
, int level
= -1);
103 unsigned getAssertionLevel() const;
106 // helper methods for converting from the internal Minisat representation
108 static SatVariable
toSatVariable(BVMinisat::Var var
);
109 static BVMinisat::Lit
toMinisatLit(SatLiteral lit
);
110 static SatLiteral
toSatLiteral(BVMinisat::Lit lit
);
111 static SatValue
toSatLiteralValue(bool res
);
112 static SatValue
toSatLiteralValue(BVMinisat::lbool res
);
114 static void toMinisatClause(SatClause
& clause
, BVMinisat::vec
<BVMinisat::Lit
>& minisat_clause
);
115 static void toSatClause (BVMinisat::vec
<BVMinisat::Lit
>& clause
, SatClause
& sat_clause
);
116 void addMarkerLiteral(SatLiteral lit
);
118 void explain(SatLiteral lit
, std::vector
<SatLiteral
>& explanation
);
120 SatValue
assertAssumption(SatLiteral lit
, bool propagate
);
122 void popAssumption();
126 ReferenceStat
<uint64_t> d_statStarts
, d_statDecisions
;
127 ReferenceStat
<uint64_t> d_statRndDecisions
, d_statPropagations
;
128 ReferenceStat
<uint64_t> d_statConflicts
, d_statClausesLiterals
;
129 ReferenceStat
<uint64_t> d_statLearntsLiterals
, d_statMaxLiterals
;
130 ReferenceStat
<uint64_t> d_statTotLiterals
;
131 ReferenceStat
<int> d_statEliminatedVars
;
132 IntStat d_statCallsToSolve
;
133 BackedStat
<double> d_statSolveTime
;
134 bool d_registerStats
;
135 Statistics(const std::string
& prefix
);
137 void init(BVMinisat::SimpSolver
* minisat
);
140 Statistics d_statistics
;