1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Mathias Preiner, Liana Hadarean, Tim King |
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 |
|
* Eager bit-blasting solver. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/bv/bv_eager_solver.h" |
17 |
|
|
18 |
|
#include "options/base_options.h" |
19 |
|
#include "options/bv_options.h" |
20 |
|
#include "options/smt_options.h" |
21 |
|
#include "theory/bv/bitblast/aig_bitblaster.h" |
22 |
|
#include "theory/bv/bitblast/eager_bitblaster.h" |
23 |
|
|
24 |
|
using namespace std; |
25 |
|
|
26 |
|
namespace cvc5 { |
27 |
|
namespace theory { |
28 |
|
namespace bv { |
29 |
|
|
30 |
2 |
EagerBitblastSolver::EagerBitblastSolver(context::Context* c, |
31 |
2 |
BVSolverLayered* bv) |
32 |
|
: d_assertionSet(c), |
33 |
|
d_assumptionSet(c), |
34 |
|
d_context(c), |
35 |
|
d_bitblaster(), |
36 |
|
d_aigBitblaster(), |
37 |
2 |
d_useAig(options::bitvectorAig()), |
38 |
4 |
d_bv(bv) |
39 |
|
{ |
40 |
2 |
} |
41 |
|
|
42 |
2 |
EagerBitblastSolver::~EagerBitblastSolver() {} |
43 |
|
|
44 |
|
void EagerBitblastSolver::turnOffAig() { |
45 |
|
Assert(d_aigBitblaster == nullptr && d_bitblaster == nullptr); |
46 |
|
d_useAig = false; |
47 |
|
} |
48 |
|
|
49 |
|
void EagerBitblastSolver::initialize() { |
50 |
|
Assert(!isInitialized()); |
51 |
|
if (d_useAig) { |
52 |
|
#ifdef CVC5_USE_ABC |
53 |
|
d_aigBitblaster.reset(new AigBitblaster()); |
54 |
|
#else |
55 |
|
Unreachable(); |
56 |
|
#endif |
57 |
|
} else { |
58 |
|
d_bitblaster.reset(new EagerBitblaster(d_bv, d_context)); |
59 |
|
} |
60 |
|
} |
61 |
|
|
62 |
|
bool EagerBitblastSolver::isInitialized() { |
63 |
|
const bool init = d_aigBitblaster != nullptr || d_bitblaster != nullptr; |
64 |
|
Assert(!init || !d_useAig || d_aigBitblaster); |
65 |
|
Assert(!init || d_useAig || d_bitblaster); |
66 |
|
return init; |
67 |
|
} |
68 |
|
|
69 |
|
void EagerBitblastSolver::assertFormula(TNode formula) { |
70 |
|
d_bv->spendResource(Resource::BvEagerAssertStep); |
71 |
|
Assert(isInitialized()); |
72 |
|
Debug("bitvector-eager") << "EagerBitblastSolver::assertFormula " << formula |
73 |
|
<< "\n"; |
74 |
|
if (options::incrementalSolving() && d_context->getLevel() > 1) |
75 |
|
{ |
76 |
|
d_assumptionSet.insert(formula); |
77 |
|
} |
78 |
|
d_assertionSet.insert(formula); |
79 |
|
// ensures all atoms are bit-blasted and converted to AIG |
80 |
|
if (d_useAig) { |
81 |
|
#ifdef CVC5_USE_ABC |
82 |
|
d_aigBitblaster->bbFormula(formula); |
83 |
|
#else |
84 |
|
Unreachable(); |
85 |
|
#endif |
86 |
|
} |
87 |
|
else |
88 |
|
{ |
89 |
|
d_bitblaster->bbFormula(formula); |
90 |
|
} |
91 |
|
} |
92 |
|
|
93 |
|
bool EagerBitblastSolver::checkSat() { |
94 |
|
Assert(isInitialized()); |
95 |
|
if (d_assertionSet.empty()) { |
96 |
|
return true; |
97 |
|
} |
98 |
|
|
99 |
|
if (d_useAig) { |
100 |
|
#ifdef CVC5_USE_ABC |
101 |
|
const std::vector<Node> assertions = {d_assertionSet.key_begin(), |
102 |
|
d_assertionSet.key_end()}; |
103 |
|
Assert(!assertions.empty()); |
104 |
|
|
105 |
|
Node query = utils::mkAnd(assertions); |
106 |
|
return d_aigBitblaster->solve(query); |
107 |
|
#else |
108 |
|
Unreachable(); |
109 |
|
#endif |
110 |
|
} |
111 |
|
|
112 |
|
if (options::incrementalSolving()) |
113 |
|
{ |
114 |
|
const std::vector<Node> assumptions = {d_assumptionSet.key_begin(), |
115 |
|
d_assumptionSet.key_end()}; |
116 |
|
return d_bitblaster->solve(assumptions); |
117 |
|
} |
118 |
|
return d_bitblaster->solve(); |
119 |
|
} |
120 |
|
|
121 |
|
bool EagerBitblastSolver::collectModelInfo(TheoryModel* m, bool fullModel) |
122 |
|
{ |
123 |
|
AlwaysAssert(!d_useAig && d_bitblaster); |
124 |
|
return d_bitblaster->collectModelInfo(m, fullModel); |
125 |
|
} |
126 |
|
|
127 |
|
} // namespace bv |
128 |
|
} // namespace theory |
129 |
29502 |
} // namespace cvc5 |