1 /********************* */
2 /*! \file bv_solver_lazy.h
4 ** Top contributors (to current version):
5 ** Mathias Preiner, Liana Hadarean, Andrew Reynolds
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2020 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.\endverbatim
12 ** \brief Lazy bit-vector solver.
15 #include "cvc4_private.h"
17 #ifndef CVC4__THEORY__BV__BV_SOLVER_LAZY_H
18 #define CVC4__THEORY__BV__BV_SOLVER_LAZY_H
20 #include <unordered_map>
21 #include <unordered_set>
23 #include "context/cdhashset.h"
24 #include "context/cdlist.h"
25 #include "context/context.h"
26 #include "theory/bv/bv_solver.h"
27 #include "theory/bv/bv_subtheory.h"
28 #include "theory/bv/theory_bv.h"
29 #include "util/hash.h"
36 class InequalitySolver
;
37 class AlgebraicSolver
;
39 class EagerBitblastSolver
;
40 class AbstractionModule
;
42 class BVSolverLazy
: public BVSolver
44 /** Back reference to TheoryBV */
47 /** The context we are using */
48 context::Context
* d_context
;
50 /** Context dependent set of atoms we already propagated */
51 context::CDHashSet
<Node
, NodeHashFunction
> d_alreadyPropagatedSet
;
52 context::CDHashSet
<Node
, NodeHashFunction
> d_sharedTermsSet
;
54 std::vector
<std::unique_ptr
<SubtheorySolver
>> d_subtheories
;
55 std::unordered_map
<SubTheory
, SubtheorySolver
*, std::hash
<int>>
59 BVSolverLazy(TheoryBV
& bv
,
61 context::UserContext
* u
,
62 ProofNodeManager
* pnm
= nullptr,
63 std::string name
= "");
67 //--------------------------------- initialization
70 * Returns true if we need an equality engine. If so, we initialize the
71 * information regarding how it should be setup. For details, see the
72 * documentation in Theory::needsEqualityEngine.
74 bool needsEqualityEngine(EeSetupInfo
& esi
) override
;
76 /** finish initialization */
77 void finishInit() override
;
78 //--------------------------------- end initialization
80 void preRegisterTerm(TNode n
) override
;
82 bool preCheck(Theory::Effort e
) override
;
84 bool needsCheckLastEffort() override
;
86 void propagate(Theory::Effort e
) override
;
88 TrustNode
explain(TNode n
) override
;
90 bool collectModelValues(TheoryModel
* m
,
91 const std::set
<Node
>& termSet
) override
;
93 std::string
identify() const override
{ return std::string("BVSolverLazy"); }
95 Theory::PPAssertStatus
ppAssert(
96 TrustNode tin
, TrustSubstitutionMap
& outSubstitutions
) override
;
98 TrustNode
ppRewrite(TNode t
) override
;
100 void ppStaticLearn(TNode in
, NodeBuilder
<>& learned
) override
;
102 void presolve() override
;
104 bool applyAbstraction(const std::vector
<Node
>& assertions
,
105 std::vector
<Node
>& new_assertions
) override
;
107 bool isLeaf(TNode node
) { return d_bv
.isLeaf(node
); }
113 AverageStat d_avgConflictSize
;
114 IntStat d_solveSubstitutions
;
115 TimerStat d_solveTimer
;
116 IntStat d_numCallsToCheckFullEffort
;
117 IntStat d_numCallsToCheckStandardEffort
;
118 TimerStat d_weightComputationTimer
;
119 IntStat d_numMultSlice
;
124 Statistics d_statistics
;
126 void check(Theory::Effort e
);
127 void spendResource(ResourceManager::Resource r
);
129 typedef std::unordered_set
<TNode
, TNodeHashFunction
> TNodeSet
;
130 typedef std::unordered_set
<Node
, NodeHashFunction
> NodeSet
;
131 NodeSet d_staticLearnCache
;
133 typedef std::unordered_map
<Node
, Node
, NodeHashFunction
> NodeToNode
;
135 context::CDO
<bool> d_lemmasAdded
;
137 // Are we in conflict?
138 context::CDO
<bool> d_conflict
;
140 // Invalidate the model cache if check was called
141 context::CDO
<bool> d_invalidateModelCache
;
143 /** The conflict node */
146 /** Literals to propagate */
147 context::CDList
<Node
> d_literalsToPropagate
;
149 /** Index of the next literal to propagate */
150 context::CDO
<unsigned> d_literalsToPropagateIndex
;
153 * Keeps a map from nodes to the subtheory that propagated it so that we can
154 * explain it properly.
156 typedef context::CDHashMap
<Node
, SubTheory
, NodeHashFunction
> PropagatedMap
;
157 PropagatedMap d_propagatedBy
;
159 std::unique_ptr
<EagerBitblastSolver
> d_eagerSolver
;
160 std::unique_ptr
<AbstractionModule
> d_abstractionModule
;
161 bool d_calledPreregister
;
163 bool wasPropagatedBySubtheory(TNode literal
) const
165 return d_propagatedBy
.find(literal
) != d_propagatedBy
.end();
168 SubTheory
getPropagatingSubtheory(TNode literal
) const
170 Assert(wasPropagatedBySubtheory(literal
));
171 PropagatedMap::const_iterator find
= d_propagatedBy
.find(literal
);
172 return (*find
).second
;
175 /** Should be called to propagate the literal. */
176 bool storePropagation(TNode literal
, SubTheory subtheory
);
179 * Explains why this literal (propagated by subtheory) is true by adding
182 void explain(TNode literal
, std::vector
<TNode
>& assumptions
);
184 void notifySharedTerm(TNode t
) override
;
186 bool isSharedTerm(TNode t
) { return d_sharedTermsSet
.contains(t
); }
188 EqualityStatus
getEqualityStatus(TNode a
, TNode b
) override
;
190 Node
getModelValue(TNode var
);
192 inline std::string
indent()
194 std::string
indentStr(d_context
->getLevel(), ' ');
198 void setConflict(Node conflict
= Node::null());
200 bool inConflict() { return d_conflict
; }
204 void lemma(TNode node
)
206 d_im
.lemma(node
, InferenceId::UNKNOWN
);
207 d_lemmasAdded
= true;
210 void checkForLemma(TNode node
);
212 size_t numAssertions() { return d_bv
.numAssertions(); }
214 theory::Assertion
get() { return d_bv
.get(); }
216 bool done() { return d_bv
.done(); }
218 friend class LazyBitblaster
;
219 friend class TLazyBitblaster
;
220 friend class EagerBitblaster
;
221 friend class BitblastSolver
;
222 friend class EqualitySolver
;
223 friend class CoreSolver
;
224 friend class InequalitySolver
;
225 friend class AlgebraicSolver
;
226 friend class EagerBitblastSolver
;
227 }; /* class BVSolverLazy */
230 } // namespace theory
234 #endif /* CVC4__THEORY__BV__BV_SOLVER_LAZY_H */