GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/bv/bv_solver_layered.h Lines: 0 21 0.0 %
Date: 2021-08-17 Branches: 0 42 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Mathias Preiner, Liana Hadarean, Andrew Reynolds
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
 * Layered bit-vector solver.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__BV__BV_SOLVER_LAYERED_H
19
#define CVC5__THEORY__BV__BV_SOLVER_LAYERED_H
20
21
#include <unordered_map>
22
#include <unordered_set>
23
24
#include "context/cdhashset.h"
25
#include "context/cdlist.h"
26
#include "context/context.h"
27
#include "theory/bv/bv_solver.h"
28
#include "theory/bv/bv_subtheory.h"
29
#include "theory/bv/theory_bv.h"
30
#include "util/hash.h"
31
32
namespace cvc5 {
33
namespace theory {
34
namespace bv {
35
36
class CoreSolver;
37
class InequalitySolver;
38
class AlgebraicSolver;
39
class BitblastSolver;
40
class EagerBitblastSolver;
41
class AbstractionModule;
42
43
class BVSolverLayered : public BVSolver
44
{
45
  /** Back reference to TheoryBV */
46
  TheoryBV& d_bv;
47
48
  /** The context we are using */
49
  context::Context* d_context;
50
51
  /** Context dependent set of atoms we already propagated */
52
  context::CDHashSet<Node> d_alreadyPropagatedSet;
53
  context::CDHashSet<Node> d_sharedTermsSet;
54
55
  std::vector<std::unique_ptr<SubtheorySolver>> d_subtheories;
56
  std::unordered_map<SubTheory, SubtheorySolver*, std::hash<int>>
57
      d_subtheoryMap;
58
59
 public:
60
  BVSolverLayered(TheoryBV& bv,
61
                  context::Context* c,
62
                  context::UserContext* u,
63
                  ProofNodeManager* pnm = nullptr,
64
                  std::string name = "");
65
66
  ~BVSolverLayered();
67
68
  //--------------------------------- initialization
69
70
  /**
71
   * Returns true if we need an equality engine. If so, we initialize the
72
   * information regarding how it should be setup. For details, see the
73
   * documentation in Theory::needsEqualityEngine.
74
   */
75
  bool needsEqualityEngine(EeSetupInfo& esi) override;
76
77
  /** finish initialization */
78
  void finishInit() override;
79
  //--------------------------------- end initialization
80
81
  void preRegisterTerm(TNode n) override;
82
83
  bool preCheck(Theory::Effort e) override;
84
85
  void propagate(Theory::Effort e) override;
86
87
  TrustNode explain(TNode n) override;
88
89
  bool collectModelValues(TheoryModel* m,
90
                          const std::set<Node>& termSet) override;
91
92
  std::string identify() const override
93
  {
94
    return std::string("BVSolverLayered");
95
  }
96
97
  TrustNode ppRewrite(TNode t) override;
98
99
  void ppStaticLearn(TNode in, NodeBuilder& learned) override;
100
101
  void presolve() override;
102
103
  bool applyAbstraction(const std::vector<Node>& assertions,
104
                        std::vector<Node>& new_assertions) override;
105
106
  bool isLeaf(TNode node) { return d_bv.isLeaf(node); }
107
108
 private:
109
  class Statistics
110
  {
111
   public:
112
    AverageStat d_avgConflictSize;
113
    TimerStat d_solveTimer;
114
    IntStat d_numCallsToCheckFullEffort;
115
    IntStat d_numCallsToCheckStandardEffort;
116
    TimerStat d_weightComputationTimer;
117
    IntStat d_numMultSlice;
118
    Statistics();
119
  };
120
121
  Statistics d_statistics;
122
123
  void check(Theory::Effort e);
124
  void spendResource(Resource r);
125
126
  typedef std::unordered_set<TNode> TNodeSet;
127
  typedef std::unordered_set<Node> NodeSet;
128
  NodeSet d_staticLearnCache;
129
130
  typedef std::unordered_map<Node, Node> NodeToNode;
131
132
  context::CDO<bool> d_lemmasAdded;
133
134
  // Are we in conflict?
135
  context::CDO<bool> d_conflict;
136
137
  // Invalidate the model cache if check was called
138
  context::CDO<bool> d_invalidateModelCache;
139
140
  /** The conflict node */
141
  Node d_conflictNode;
142
143
  /** Literals to propagate */
144
  context::CDList<Node> d_literalsToPropagate;
145
146
  /** Index of the next literal to propagate */
147
  context::CDO<unsigned> d_literalsToPropagateIndex;
148
149
  /**
150
   * Keeps a map from nodes to the subtheory that propagated it so that we can
151
   * explain it properly.
152
   */
153
  typedef context::CDHashMap<Node, SubTheory> PropagatedMap;
154
  PropagatedMap d_propagatedBy;
155
156
  std::unique_ptr<EagerBitblastSolver> d_eagerSolver;
157
  std::unique_ptr<AbstractionModule> d_abstractionModule;
158
  bool d_calledPreregister;
159
160
  bool wasPropagatedBySubtheory(TNode literal) const
161
  {
162
    return d_propagatedBy.find(literal) != d_propagatedBy.end();
163
  }
164
165
  SubTheory getPropagatingSubtheory(TNode literal) const
166
  {
167
    Assert(wasPropagatedBySubtheory(literal));
168
    PropagatedMap::const_iterator find = d_propagatedBy.find(literal);
169
    return (*find).second;
170
  }
171
172
  /** Should be called to propagate the literal.  */
173
  bool storePropagation(TNode literal, SubTheory subtheory);
174
175
  /**
176
   * Explains why this literal (propagated by subtheory) is true by adding
177
   * assumptions.
178
   */
179
  void explain(TNode literal, std::vector<TNode>& assumptions);
180
181
  void notifySharedTerm(TNode t) override;
182
183
  bool isSharedTerm(TNode t) { return d_sharedTermsSet.contains(t); }
184
185
  EqualityStatus getEqualityStatus(TNode a, TNode b) override;
186
187
  Node getModelValue(TNode var);
188
189
  inline std::string indent()
190
  {
191
    std::string indentStr(d_context->getLevel(), ' ');
192
    return indentStr;
193
  }
194
195
  void setConflict(Node conflict = Node::null());
196
197
  bool inConflict() { return d_conflict; }
198
199
  void sendConflict();
200
201
  void lemma(TNode node)
202
  {
203
    d_im.lemma(node, InferenceId::BV_LAYERED_LEMMA);
204
    d_lemmasAdded = true;
205
  }
206
207
  void checkForLemma(TNode node);
208
209
  size_t numAssertions() { return d_bv.numAssertions(); }
210
211
  theory::Assertion get() { return d_bv.get(); }
212
213
  bool done() { return d_bv.done(); }
214
215
  friend class LazyBitblaster;
216
  friend class TLazyBitblaster;
217
  friend class EagerBitblaster;
218
  friend class BitblastSolver;
219
  friend class EqualitySolver;
220
  friend class CoreSolver;
221
  friend class InequalitySolver;
222
  friend class AlgebraicSolver;
223
  friend class EagerBitblastSolver;
224
}; /* class BVSolverLayered */
225
226
}  // namespace bv
227
}  // namespace theory
228
229
}  // namespace cvc5
230
231
#endif /* CVC5__THEORY__BV__BV_SOLVER_LAZY_H */