GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/bv/bv_solver_layered.h Lines: 0 21 0.0 %
Date: 2021-09-10 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
                  Env& env,
62
                  context::Context* c,
63
                  context::UserContext* u,
64
                  ProofNodeManager* pnm = nullptr,
65
                  std::string name = "");
66
67
  ~BVSolverLayered();
68
69
  //--------------------------------- initialization
70
71
  /**
72
   * Returns true if we need an equality engine. If so, we initialize the
73
   * information regarding how it should be setup. For details, see the
74
   * documentation in Theory::needsEqualityEngine.
75
   */
76
  bool needsEqualityEngine(EeSetupInfo& esi) override;
77
78
  /** finish initialization */
79
  void finishInit() override;
80
  //--------------------------------- end initialization
81
82
  void preRegisterTerm(TNode n) override;
83
84
  bool preCheck(Theory::Effort e) override;
85
86
  void propagate(Theory::Effort e) override;
87
88
  TrustNode explain(TNode n) override;
89
90
  bool collectModelValues(TheoryModel* m,
91
                          const std::set<Node>& termSet) override;
92
93
  std::string identify() const override
94
  {
95
    return std::string("BVSolverLayered");
96
  }
97
98
  TrustNode ppRewrite(TNode t) override;
99
100
  void ppStaticLearn(TNode in, NodeBuilder& learned) override;
101
102
  void presolve() override;
103
104
  bool applyAbstraction(const std::vector<Node>& assertions,
105
                        std::vector<Node>& new_assertions) override;
106
107
  bool isLeaf(TNode node) { return d_bv.isLeaf(node); }
108
109
 private:
110
  class Statistics
111
  {
112
   public:
113
    AverageStat d_avgConflictSize;
114
    TimerStat d_solveTimer;
115
    IntStat d_numCallsToCheckFullEffort;
116
    IntStat d_numCallsToCheckStandardEffort;
117
    TimerStat d_weightComputationTimer;
118
    IntStat d_numMultSlice;
119
    Statistics();
120
  };
121
122
  Statistics d_statistics;
123
124
  void check(Theory::Effort e);
125
  void spendResource(Resource r);
126
127
  typedef std::unordered_set<TNode> TNodeSet;
128
  typedef std::unordered_set<Node> NodeSet;
129
  NodeSet d_staticLearnCache;
130
131
  typedef std::unordered_map<Node, Node> NodeToNode;
132
133
  context::CDO<bool> d_lemmasAdded;
134
135
  // Are we in conflict?
136
  context::CDO<bool> d_conflict;
137
138
  // Invalidate the model cache if check was called
139
  context::CDO<bool> d_invalidateModelCache;
140
141
  /** The conflict node */
142
  Node d_conflictNode;
143
144
  /** Literals to propagate */
145
  context::CDList<Node> d_literalsToPropagate;
146
147
  /** Index of the next literal to propagate */
148
  context::CDO<unsigned> d_literalsToPropagateIndex;
149
150
  /**
151
   * Keeps a map from nodes to the subtheory that propagated it so that we can
152
   * explain it properly.
153
   */
154
  typedef context::CDHashMap<Node, SubTheory> PropagatedMap;
155
  PropagatedMap d_propagatedBy;
156
157
  std::unique_ptr<EagerBitblastSolver> d_eagerSolver;
158
  std::unique_ptr<AbstractionModule> d_abstractionModule;
159
  bool d_calledPreregister;
160
161
  bool wasPropagatedBySubtheory(TNode literal) const
162
  {
163
    return d_propagatedBy.find(literal) != d_propagatedBy.end();
164
  }
165
166
  SubTheory getPropagatingSubtheory(TNode literal) const
167
  {
168
    Assert(wasPropagatedBySubtheory(literal));
169
    PropagatedMap::const_iterator find = d_propagatedBy.find(literal);
170
    return (*find).second;
171
  }
172
173
  /** Should be called to propagate the literal.  */
174
  bool storePropagation(TNode literal, SubTheory subtheory);
175
176
  /**
177
   * Explains why this literal (propagated by subtheory) is true by adding
178
   * assumptions.
179
   */
180
  void explain(TNode literal, std::vector<TNode>& assumptions);
181
182
  void notifySharedTerm(TNode t) override;
183
184
  bool isSharedTerm(TNode t) { return d_sharedTermsSet.contains(t); }
185
186
  EqualityStatus getEqualityStatus(TNode a, TNode b) override;
187
188
  Node getModelValue(TNode var);
189
190
  inline std::string indent()
191
  {
192
    std::string indentStr(d_context->getLevel(), ' ');
193
    return indentStr;
194
  }
195
196
  void setConflict(Node conflict = Node::null());
197
198
  bool inConflict() { return d_conflict; }
199
200
  void sendConflict();
201
202
  void lemma(TNode node)
203
  {
204
    d_im.lemma(node, InferenceId::BV_LAYERED_LEMMA);
205
    d_lemmasAdded = true;
206
  }
207
208
  void checkForLemma(TNode node);
209
210
  size_t numAssertions() { return d_bv.numAssertions(); }
211
212
  theory::Assertion get() { return d_bv.get(); }
213
214
  bool done() { return d_bv.done(); }
215
216
  friend class LazyBitblaster;
217
  friend class TLazyBitblaster;
218
  friend class EagerBitblaster;
219
  friend class BitblastSolver;
220
  friend class EqualitySolver;
221
  friend class CoreSolver;
222
  friend class InequalitySolver;
223
  friend class AlgebraicSolver;
224
  friend class EagerBitblastSolver;
225
}; /* class BVSolverLayered */
226
227
}  // namespace bv
228
}  // namespace theory
229
230
}  // namespace cvc5
231
232
#endif /* CVC5__THEORY__BV__BV_SOLVER_LAZY_H */