GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/bv/bitblast/lazy_bitblaster.h Lines: 4 7 57.1 %
Date: 2021-05-22 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Mathias Preiner, Liana Hadarean, Clark Barrett
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
 * Bitblaster for the lazy bv solver.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__THEORY__BV__BITBLAST__LAZY_BITBLASTER_H
19
#define CVC5__THEORY__BV__BITBLAST__LAZY_BITBLASTER_H
20
21
#include "theory/bv/bitblast/bitblaster.h"
22
23
#include "context/cdhashmap.h"
24
#include "context/cdlist.h"
25
#include "prop/bv_sat_solver_notify.h"
26
#include "theory/bv/abstraction.h"
27
28
namespace cvc5 {
29
namespace prop {
30
class CnfStream;
31
class NullRegistrat;
32
}
33
namespace theory {
34
namespace bv {
35
36
class BVSolverLazy;
37
38
class TLazyBitblaster : public TBitblaster<Node>
39
{
40
 public:
41
  void bbTerm(TNode node, Bits& bits) override;
42
  void bbAtom(TNode node) override;
43
  Node getBBAtom(TNode atom) const override;
44
  void storeBBAtom(TNode atom, Node atom_bb) override;
45
  void storeBBTerm(TNode node, const Bits& bits) override;
46
  bool hasBBAtom(TNode atom) const override;
47
48
  TLazyBitblaster(context::Context* c,
49
                  BVSolverLazy* bv,
50
                  const std::string name = "",
51
                  bool emptyNotify = false);
52
  ~TLazyBitblaster();
53
  /**
54
   * Pushes the assumption literal associated with node to the SAT
55
   * solver assumption queue.
56
   *
57
   * @param node assumption
58
   * @param propagate run bcp or not
59
   *
60
   * @return false if a conflict detected
61
   */
62
  bool assertToSat(TNode node, bool propagate = true);
63
  bool propagate();
64
  bool solve();
65
  prop::SatValue solveWithBudget(unsigned long conflict_budget);
66
  void getConflict(std::vector<TNode>& conflict);
67
  void explain(TNode atom, std::vector<TNode>& explanation);
68
  void setAbstraction(AbstractionModule* abs);
69
70
  theory::EqualityStatus getEqualityStatus(TNode a, TNode b);
71
72
  /**
73
   * Adds a constant value for each bit-blasted variable in the model.
74
   *
75
   * @param m the model
76
   * @param termSet the set of relevant terms
77
   */
78
  bool collectModelValues(TheoryModel* m,
79
                          const std::set<Node>& termSet);
80
81
  typedef TNodeSet::const_iterator vars_iterator;
82
  vars_iterator beginVars() { return d_variables.begin(); }
83
  vars_iterator endVars() { return d_variables.end(); }
84
85
  /**
86
   * Creates the bits corresponding to the variable (or non-bv term).
87
   *
88
   * @param var
89
   */
90
  void makeVariable(TNode var, Bits& bits) override;
91
92
  bool isSharedTerm(TNode node);
93
  uint64_t computeAtomWeight(TNode node, NodeSet& seen);
94
  /**
95
   * Deletes SatSolver and CnfCache, but maintains bit-blasting
96
   * terms cache.
97
   *
98
   */
99
  void clearSolver();
100
101
 private:
102
  typedef std::vector<Node> Bits;
103
  typedef context::CDList<prop::SatLiteral> AssertionList;
104
  typedef context::CDHashMap<prop::SatLiteral,
105
                             std::vector<prop::SatLiteral>,
106
                             prop::SatLiteralHashFunction>
107
      ExplanationMap;
108
  /** This class gets callbacks from minisat on propagations */
109
18810
  class MinisatNotify : public prop::BVSatSolverNotify
110
  {
111
    prop::CnfStream* d_cnf;
112
    BVSolverLazy* d_bv;
113
    TLazyBitblaster* d_lazyBB;
114
115
   public:
116
9405
    MinisatNotify(prop::CnfStream* cnf, BVSolverLazy* bv, TLazyBitblaster* lbv)
117
9405
        : d_cnf(cnf), d_bv(bv), d_lazyBB(lbv)
118
    {
119
9405
    }
120
121
    bool notify(prop::SatLiteral lit) override;
122
    void notify(prop::SatClause& clause) override;
123
    void spendResource(Resource r) override;
124
    void safePoint(Resource r) override;
125
  };
126
127
  BVSolverLazy* d_bv;
128
  context::Context* d_ctx;
129
130
  std::unique_ptr<prop::NullRegistrar> d_nullRegistrar;
131
  std::unique_ptr<prop::BVSatSolverInterface> d_satSolver;
132
  std::unique_ptr<prop::BVSatSolverNotify> d_satSolverNotify;
133
134
  AssertionList*
135
      d_assertedAtoms;            /**< context dependent list storing the atoms
136
                                     currently asserted by the DPLL SAT solver. */
137
  ExplanationMap* d_explanations; /**< context dependent list of explanations
138
                                    for the propagated literals. Only used when
139
                                    bvEagerPropagate option enabled. */
140
  TNodeSet d_variables;
141
  TNodeSet d_bbAtoms;
142
  AbstractionModule* d_abstraction;
143
  bool d_emptyNotify;
144
145
  // The size of the fact queue when we most recently called solve() in the
146
  // bit-vector SAT solver. This is the level at which we should have
147
  // a full model in the bv SAT solver.
148
  context::CDO<int> d_fullModelAssertionLevel;
149
150
  void addAtom(TNode atom);
151
  bool hasValue(TNode a);
152
  Node getModelFromSatSolver(TNode a, bool fullModel) override;
153
  prop::SatSolver* getSatSolver() override { return d_satSolver.get(); }
154
155
  class Statistics
156
  {
157
   public:
158
    IntStat d_numTermClauses, d_numAtomClauses;
159
    IntStat d_numTerms, d_numAtoms;
160
    IntStat d_numExplainedPropagations;
161
    IntStat d_numBitblastingPropagations;
162
    TimerStat d_bitblastTimer;
163
    Statistics(const std::string& name);
164
  };
165
  std::string d_name;
166
167
 // NOTE: d_statistics is public since d_bitblastTimer needs to be initalized
168
 //       prior to calling bbAtom. As it is now, the timer can't be initialized
169
 //       in bbAtom since the method is called recursively and the timer would
170
 //       be initialized multiple times, which is not allowed.
171
 public:
172
  Statistics d_statistics;
173
};
174
175
}  // namespace bv
176
}  // namespace theory
177
}  // namespace cvc5
178
#endif  //  CVC5__THEORY__BV__BITBLAST__LAZY_BITBLASTER_H