1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Liana Hadarean, Mathias Preiner, Morgan Deters |
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 |
|
* Sandboxed SAT solver for bv quickchecks. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__BV_QUICK_CHECK_H |
19 |
|
#define CVC5__BV_QUICK_CHECK_H |
20 |
|
|
21 |
|
#include <unordered_set> |
22 |
|
#include <vector> |
23 |
|
|
24 |
|
#include "context/cdo.h" |
25 |
|
#include "expr/node.h" |
26 |
|
#include "prop/sat_solver_types.h" |
27 |
|
#include "theory/bv/theory_bv_utils.h" |
28 |
|
#include "util/statistics_stats.h" |
29 |
|
|
30 |
|
namespace cvc5 { |
31 |
|
namespace theory { |
32 |
|
|
33 |
|
class TheoryModel; |
34 |
|
|
35 |
|
namespace bv { |
36 |
|
|
37 |
|
class TLazyBitblaster; |
38 |
|
class BVSolverLazy; |
39 |
|
|
40 |
|
class BVQuickCheck |
41 |
|
{ |
42 |
|
context::Context d_ctx; |
43 |
|
std::unique_ptr<TLazyBitblaster> d_bitblaster; |
44 |
|
Node d_conflict; |
45 |
|
context::CDO<bool> d_inConflict; |
46 |
|
void setConflict(); |
47 |
|
|
48 |
|
public: |
49 |
|
BVQuickCheck(const std::string& name, theory::bv::BVSolverLazy* bv); |
50 |
|
~BVQuickCheck(); |
51 |
|
bool inConflict(); |
52 |
|
Node getConflict() { return d_conflict; } |
53 |
|
/** |
54 |
|
* Checks the satisfiability for a given set of assumptions. |
55 |
|
* |
56 |
|
* @param assumptions literals assumed true |
57 |
|
* @param budget max number of conflicts |
58 |
|
* |
59 |
|
* @return |
60 |
|
*/ |
61 |
|
prop::SatValue checkSat(std::vector<Node>& assumptions, unsigned long budget); |
62 |
|
/** |
63 |
|
* Checks the satisfiability of given assertions. |
64 |
|
* |
65 |
|
* @param budget max number of conflicts |
66 |
|
* |
67 |
|
* @return |
68 |
|
*/ |
69 |
|
prop::SatValue checkSat(unsigned long budget); |
70 |
|
|
71 |
|
/** |
72 |
|
* Convert to CNF and assert the given literal. |
73 |
|
* |
74 |
|
* @param assumption bv literal |
75 |
|
* |
76 |
|
* @return false if a conflict has been found via bcp. |
77 |
|
*/ |
78 |
|
bool addAssertion(TNode assumption); |
79 |
|
|
80 |
|
void push(); |
81 |
|
void pop(); |
82 |
|
void popToZero(); |
83 |
|
/** |
84 |
|
* Deletes the SAT solver and CNF stream, but maintains the |
85 |
|
* bit-blasting term cache. |
86 |
|
* |
87 |
|
*/ |
88 |
|
void clearSolver(); |
89 |
|
|
90 |
|
/** |
91 |
|
* Computes the size of the circuit required to bit-blast |
92 |
|
* atom, by not recounting the nodes in seen. |
93 |
|
* |
94 |
|
* @param node |
95 |
|
* @param seen |
96 |
|
* |
97 |
|
* @return |
98 |
|
*/ |
99 |
|
uint64_t computeAtomWeight(TNode atom, NodeSet& seen); |
100 |
|
bool collectModelValues(theory::TheoryModel* model, |
101 |
|
const std::set<Node>& termSet); |
102 |
|
|
103 |
|
typedef std::unordered_set<TNode>::const_iterator vars_iterator; |
104 |
|
vars_iterator beginVars(); |
105 |
|
vars_iterator endVars(); |
106 |
|
|
107 |
|
Node getVarValue(TNode var, bool fullModel); |
108 |
|
}; |
109 |
|
|
110 |
|
class QuickXPlain |
111 |
|
{ |
112 |
|
struct Statistics |
113 |
|
{ |
114 |
|
TimerStat d_xplainTime; |
115 |
|
IntStat d_numSolved; |
116 |
|
IntStat d_numUnknown; |
117 |
|
IntStat d_numUnknownWasUnsat; |
118 |
|
IntStat d_numConflictsMinimized; |
119 |
|
IntStat d_finalPeriod; |
120 |
|
AverageStat d_avgMinimizationRatio; |
121 |
|
Statistics(const std::string& name); |
122 |
|
}; |
123 |
|
BVQuickCheck* d_solver; |
124 |
|
unsigned long d_budget; |
125 |
|
|
126 |
|
// crazy heuristic variables |
127 |
|
unsigned d_numCalled; // number of times called |
128 |
|
double d_minRatioSum; // sum of minimization ratio for computing average min |
129 |
|
// ratio |
130 |
|
unsigned d_numConflicts; // number of conflicts (including when minimization |
131 |
|
// not applied) |
132 |
|
// unsigned d_period; // after how many conflicts to try minimizing again |
133 |
|
|
134 |
|
// double d_thresh; // if minimization ratio is less, increase period |
135 |
|
// double d_hardThresh; // decrease period if minimization ratio is greater |
136 |
|
// than this |
137 |
|
|
138 |
|
Statistics d_statistics; |
139 |
|
/** |
140 |
|
* Uses solve with assumptions unsat core feature to |
141 |
|
* further minimize a conflict. The minimized conflict |
142 |
|
* will be between low and the returned value in conflict. |
143 |
|
* |
144 |
|
* @param low |
145 |
|
* @param high |
146 |
|
* @param conflict |
147 |
|
* |
148 |
|
* @return |
149 |
|
*/ |
150 |
|
unsigned selectUnsatCore(unsigned low, |
151 |
|
unsigned high, |
152 |
|
std::vector<TNode>& conflict); |
153 |
|
/** |
154 |
|
* Internal conflict minimization, attempts to minimize |
155 |
|
* literals in conflict between low and high and adds the |
156 |
|
* result in new_conflict. |
157 |
|
* |
158 |
|
* @param low |
159 |
|
* @param high |
160 |
|
* @param conflict |
161 |
|
* @param new_conflict |
162 |
|
*/ |
163 |
|
void minimizeConflictInternal(unsigned low, |
164 |
|
unsigned high, |
165 |
|
std::vector<TNode>& conflict, |
166 |
|
std::vector<TNode>& new_conflict); |
167 |
|
|
168 |
|
bool useHeuristic(); |
169 |
|
|
170 |
|
public: |
171 |
|
QuickXPlain(const std::string& name, |
172 |
|
BVQuickCheck* solver, |
173 |
|
unsigned long budged = 10000); |
174 |
|
~QuickXPlain(); |
175 |
|
Node minimizeConflict(TNode conflict); |
176 |
|
}; |
177 |
|
|
178 |
|
} // namespace bv |
179 |
|
} // namespace theory |
180 |
|
} // namespace cvc5 |
181 |
|
|
182 |
|
#endif /* CVC5__BV_QUICK_CHECK_H */ |