1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Mathias Preiner, Haniel Barbosa, Liana Hadarean |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* SAT Solver. |
14 |
|
* |
15 |
|
* Implementation of the minisat interface for cvc5. |
16 |
|
*/ |
17 |
|
|
18 |
|
#pragma once |
19 |
|
|
20 |
|
#include "prop/sat_solver.h" |
21 |
|
#include "prop/minisat/simp/SimpSolver.h" |
22 |
|
#include "util/statistics_registry.h" |
23 |
|
|
24 |
|
namespace cvc5 { |
25 |
|
|
26 |
|
template <class Solver> |
27 |
|
prop::SatLiteral toSatLiteral(typename Solver::TLit lit); |
28 |
|
|
29 |
|
template <class Solver> |
30 |
|
void toSatClause(const typename Solver::TClause& minisat_cl, |
31 |
|
prop::SatClause& sat_cl); |
32 |
|
|
33 |
|
namespace prop { |
34 |
|
|
35 |
|
class MinisatSatSolver : public CDCLTSatSolverInterface |
36 |
|
{ |
37 |
|
public: |
38 |
|
MinisatSatSolver(StatisticsRegistry& registry); |
39 |
|
~MinisatSatSolver() override; |
40 |
|
|
41 |
|
static SatVariable toSatVariable(Minisat::Var var); |
42 |
|
static Minisat::Lit toMinisatLit(SatLiteral lit); |
43 |
|
static SatLiteral toSatLiteral(Minisat::Lit lit); |
44 |
|
static SatValue toSatLiteralValue(Minisat::lbool res); |
45 |
|
static Minisat::lbool toMinisatlbool(SatValue val); |
46 |
|
//(Commented because not in use) static bool tobool(SatValue val); |
47 |
|
|
48 |
|
static void toMinisatClause(SatClause& clause, Minisat::vec<Minisat::Lit>& minisat_clause); |
49 |
|
static void toSatClause (const Minisat::Clause& clause, SatClause& sat_clause); |
50 |
|
void initialize(context::Context* context, |
51 |
|
TheoryProxy* theoryProxy, |
52 |
|
cvc5::context::UserContext* userContext, |
53 |
|
ProofNodeManager* pnm) override; |
54 |
|
|
55 |
|
ClauseId addClause(SatClause& clause, bool removable) override; |
56 |
|
ClauseId addXorClause(SatClause& clause, bool rhs, bool removable) override |
57 |
|
{ |
58 |
|
Unreachable() << "Minisat does not support native XOR reasoning"; |
59 |
|
} |
60 |
|
|
61 |
|
SatVariable newVar(bool isTheoryAtom, |
62 |
|
bool preRegister, |
63 |
|
bool canErase) override; |
64 |
9982 |
SatVariable trueVar() override { return d_minisat->trueVar(); } |
65 |
9982 |
SatVariable falseVar() override { return d_minisat->falseVar(); } |
66 |
|
|
67 |
|
SatValue solve() override; |
68 |
|
SatValue solve(long unsigned int&) override; |
69 |
|
SatValue solve(const std::vector<SatLiteral>& assumptions) override; |
70 |
|
void getUnsatAssumptions(std::vector<SatLiteral>& unsat_assumptions) override; |
71 |
|
|
72 |
|
bool ok() const override; |
73 |
|
|
74 |
|
void interrupt() override; |
75 |
|
|
76 |
|
SatValue value(SatLiteral l) override; |
77 |
|
|
78 |
|
SatValue modelValue(SatLiteral l) override; |
79 |
|
|
80 |
|
bool properExplanation(SatLiteral lit, SatLiteral expl) const override; |
81 |
|
|
82 |
|
/** Incremental interface */ |
83 |
|
|
84 |
|
unsigned getAssertionLevel() const override; |
85 |
|
|
86 |
|
void push() override; |
87 |
|
|
88 |
|
void pop() override; |
89 |
|
|
90 |
|
void resetTrail() override; |
91 |
|
|
92 |
|
void requirePhase(SatLiteral lit) override; |
93 |
|
|
94 |
|
bool isDecision(SatVariable decn) const override; |
95 |
|
|
96 |
|
/** Return decision level at which `lit` was decided on. */ |
97 |
|
int32_t getDecisionLevel(SatVariable v) const override; |
98 |
|
|
99 |
|
/** |
100 |
|
* Return user level at which `lit` was introduced. |
101 |
|
* |
102 |
|
* Note: The user level is tracked independently in the SAT solver and does |
103 |
|
* not query the user-context for the user level. The user level in the SAT |
104 |
|
* solver starts at level 0 and does not include the global push/pop in |
105 |
|
* the SMT engine. |
106 |
|
*/ |
107 |
|
int32_t getIntroLevel(SatVariable v) const override; |
108 |
|
|
109 |
|
/** Retrieve a pointer to the underlying solver. */ |
110 |
|
Minisat::SimpSolver* getSolver() { return d_minisat; } |
111 |
|
|
112 |
|
/** Retrieve the proof manager of this SAT solver. */ |
113 |
|
SatProofManager* getProofManager(); |
114 |
|
|
115 |
|
/** Retrieve the refutation proof of this SAT solver. */ |
116 |
|
std::shared_ptr<ProofNode> getProof() override; |
117 |
|
|
118 |
|
private: |
119 |
|
|
120 |
|
/** The SatSolver used */ |
121 |
|
Minisat::SimpSolver* d_minisat; |
122 |
|
|
123 |
|
/** Context we will be using to synchronize the sat solver */ |
124 |
|
context::Context* d_context; |
125 |
|
|
126 |
|
/** |
127 |
|
* Stores assumptions passed via last solve() call. |
128 |
|
* |
129 |
|
* It is used in getUnsatAssumptions() to determine which of the literals in |
130 |
|
* the final conflict clause are assumptions. |
131 |
|
*/ |
132 |
|
std::unordered_set<SatLiteral, SatLiteralHashFunction> d_assumptions; |
133 |
|
|
134 |
|
void setupOptions(); |
135 |
|
|
136 |
9979 |
class Statistics { |
137 |
|
private: |
138 |
|
ReferenceStat<int64_t> d_statStarts, d_statDecisions; |
139 |
|
ReferenceStat<int64_t> d_statRndDecisions, d_statPropagations; |
140 |
|
ReferenceStat<int64_t> d_statConflicts, d_statClausesLiterals; |
141 |
|
ReferenceStat<int64_t> d_statLearntsLiterals, d_statMaxLiterals; |
142 |
|
ReferenceStat<int64_t> d_statTotLiterals; |
143 |
|
|
144 |
|
public: |
145 |
|
Statistics(StatisticsRegistry& registry); |
146 |
|
void init(Minisat::SimpSolver* d_minisat); |
147 |
|
void deinit(); |
148 |
|
};/* class MinisatSatSolver::Statistics */ |
149 |
|
Statistics d_statistics; |
150 |
|
|
151 |
|
}; /* class MinisatSatSolver */ |
152 |
|
|
153 |
|
} // namespace prop |
154 |
|
} // namespace cvc5 |