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

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