1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Haniel Barbosa, 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 |
|
* Implementation of the propositional engine of cvc5. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "prop/prop_engine.h" |
17 |
|
|
18 |
|
#include <iomanip> |
19 |
|
#include <map> |
20 |
|
#include <utility> |
21 |
|
|
22 |
|
#include "base/check.h" |
23 |
|
#include "base/output.h" |
24 |
|
#include "decision/decision_engine_old.h" |
25 |
|
#include "decision/justification_strategy.h" |
26 |
|
#include "options/base_options.h" |
27 |
|
#include "options/decision_options.h" |
28 |
|
#include "options/main_options.h" |
29 |
|
#include "options/options.h" |
30 |
|
#include "options/proof_options.h" |
31 |
|
#include "options/smt_options.h" |
32 |
|
#include "prop/cnf_stream.h" |
33 |
|
#include "prop/minisat/minisat.h" |
34 |
|
#include "prop/prop_proof_manager.h" |
35 |
|
#include "prop/sat_solver.h" |
36 |
|
#include "prop/sat_solver_factory.h" |
37 |
|
#include "prop/theory_proxy.h" |
38 |
|
#include "smt/env.h" |
39 |
|
#include "smt/smt_statistics_registry.h" |
40 |
|
#include "theory/output_channel.h" |
41 |
|
#include "theory/theory_engine.h" |
42 |
|
#include "util/resource_manager.h" |
43 |
|
#include "util/result.h" |
44 |
|
|
45 |
|
namespace cvc5 { |
46 |
|
namespace prop { |
47 |
|
|
48 |
|
/** Keeps a boolean flag scoped */ |
49 |
|
class ScopedBool { |
50 |
|
|
51 |
|
private: |
52 |
|
|
53 |
|
bool d_original; |
54 |
|
bool& d_reference; |
55 |
|
|
56 |
|
public: |
57 |
|
|
58 |
20562 |
ScopedBool(bool& reference) : |
59 |
20562 |
d_reference(reference) { |
60 |
20562 |
d_original = reference; |
61 |
20562 |
} |
62 |
|
|
63 |
41124 |
~ScopedBool() { |
64 |
20562 |
d_reference = d_original; |
65 |
20562 |
} |
66 |
|
}; |
67 |
|
|
68 |
15339 |
PropEngine::PropEngine(TheoryEngine* te, Env& env) |
69 |
|
: d_inCheckSat(false), |
70 |
|
d_theoryEngine(te), |
71 |
|
d_env(env), |
72 |
15339 |
d_skdm(new SkolemDefManager(d_env.getContext(), d_env.getUserContext())), |
73 |
|
d_theoryProxy(nullptr), |
74 |
|
d_satSolver(nullptr), |
75 |
|
d_cnfStream(nullptr), |
76 |
|
d_pfCnfStream(nullptr), |
77 |
|
d_ppm(nullptr), |
78 |
|
d_interrupted(false), |
79 |
30678 |
d_assumptions(d_env.getUserContext()) |
80 |
|
{ |
81 |
15339 |
Debug("prop") << "Constructing the PropEngine" << std::endl; |
82 |
15339 |
context::UserContext* userContext = d_env.getUserContext(); |
83 |
15339 |
ProofNodeManager* pnm = d_env.getProofNodeManager(); |
84 |
15339 |
ResourceManager* rm = d_env.getResourceManager(); |
85 |
|
|
86 |
15339 |
options::DecisionMode dmode = options::decisionMode(); |
87 |
15339 |
if (dmode == options::DecisionMode::JUSTIFICATION |
88 |
3009 |
|| dmode == options::DecisionMode::STOPONLY) |
89 |
|
{ |
90 |
12755 |
d_decisionEngine.reset(new decision::JustificationStrategy(env)); |
91 |
|
} |
92 |
2584 |
else if (dmode == options::DecisionMode::JUSTIFICATION_OLD |
93 |
2581 |
|| dmode == options::DecisionMode::STOPONLY_OLD) |
94 |
|
{ |
95 |
3 |
d_decisionEngine.reset(new DecisionEngineOld(env)); |
96 |
|
} |
97 |
|
else |
98 |
|
{ |
99 |
2581 |
d_decisionEngine.reset(new decision::DecisionEngineEmpty(env)); |
100 |
|
} |
101 |
|
|
102 |
15339 |
d_satSolver = |
103 |
15339 |
SatSolverFactory::createCDCLTMinisat(d_env, smtStatisticsRegistry()); |
104 |
|
|
105 |
|
// CNF stream and theory proxy required pointers to each other, make the |
106 |
|
// theory proxy first |
107 |
15339 |
d_theoryProxy = new TheoryProxy( |
108 |
15339 |
this, d_theoryEngine, d_decisionEngine.get(), d_skdm.get(), d_env); |
109 |
46017 |
d_cnfStream = new CnfStream(d_satSolver, |
110 |
15339 |
d_theoryProxy, |
111 |
|
userContext, |
112 |
15339 |
&d_env, |
113 |
|
rm, |
114 |
|
FormulaLitPolicy::TRACK, |
115 |
30678 |
"prop"); |
116 |
|
|
117 |
|
// connect theory proxy |
118 |
15339 |
d_theoryProxy->finishInit(d_cnfStream); |
119 |
15339 |
bool satProofs = d_env.isSatProofProducing(); |
120 |
|
// connect SAT solver |
121 |
46017 |
d_satSolver->initialize(d_env.getContext(), |
122 |
|
d_theoryProxy, |
123 |
15339 |
d_env.getUserContext(), |
124 |
15339 |
satProofs ? pnm : nullptr); |
125 |
|
|
126 |
15339 |
d_decisionEngine->finishInit(d_satSolver, d_cnfStream); |
127 |
15339 |
if (satProofs) |
128 |
|
{ |
129 |
10762 |
d_pfCnfStream.reset(new ProofCnfStream( |
130 |
|
userContext, |
131 |
5381 |
*d_cnfStream, |
132 |
5381 |
static_cast<MinisatSatSolver*>(d_satSolver)->getProofManager(), |
133 |
10762 |
pnm)); |
134 |
10762 |
d_ppm.reset( |
135 |
5381 |
new PropPfManager(userContext, pnm, d_satSolver, d_pfCnfStream.get())); |
136 |
|
} |
137 |
15339 |
} |
138 |
|
|
139 |
15339 |
void PropEngine::finishInit() |
140 |
|
{ |
141 |
15339 |
NodeManager* nm = NodeManager::currentNM(); |
142 |
15339 |
d_cnfStream->convertAndAssert(nm->mkConst(true), false, false); |
143 |
|
// this is necessary because if True is later asserted to the prop engine the |
144 |
|
// CNF stream will ignore it since the SAT solver already had it registered, |
145 |
|
// thus not having True as an assumption for the SAT proof. To solve this |
146 |
|
// issue we track it directly here |
147 |
15339 |
if (isProofEnabled()) |
148 |
|
{ |
149 |
5381 |
static_cast<MinisatSatSolver*>(d_satSolver) |
150 |
|
->getProofManager() |
151 |
5381 |
->registerSatAssumptions({nm->mkConst(true)}); |
152 |
|
} |
153 |
15339 |
d_cnfStream->convertAndAssert(nm->mkConst(false).notNode(), false, false); |
154 |
15339 |
} |
155 |
|
|
156 |
30668 |
PropEngine::~PropEngine() { |
157 |
15334 |
Debug("prop") << "Destructing the PropEngine" << std::endl; |
158 |
15334 |
d_decisionEngine.reset(nullptr); |
159 |
15334 |
delete d_cnfStream; |
160 |
15334 |
delete d_satSolver; |
161 |
15334 |
delete d_theoryProxy; |
162 |
15334 |
} |
163 |
|
|
164 |
117635 |
TrustNode PropEngine::preprocess(TNode node, |
165 |
|
std::vector<theory::SkolemLemma>& newLemmas) |
166 |
|
{ |
167 |
117635 |
return d_theoryProxy->preprocess(node, newLemmas); |
168 |
|
} |
169 |
|
|
170 |
2 |
TrustNode PropEngine::removeItes(TNode node, |
171 |
|
std::vector<theory::SkolemLemma>& newLemmas) |
172 |
|
{ |
173 |
2 |
return d_theoryProxy->removeItes(node, newLemmas); |
174 |
|
} |
175 |
|
|
176 |
19097 |
void PropEngine::assertInputFormulas( |
177 |
|
const std::vector<Node>& assertions, |
178 |
|
std::unordered_map<size_t, Node>& skolemMap) |
179 |
|
{ |
180 |
19097 |
Assert(!d_inCheckSat) << "Sat solver in solve()!"; |
181 |
|
// notify the theory engine of preprocessed assertions |
182 |
19097 |
d_theoryEngine->notifyPreprocessedAssertions(assertions); |
183 |
|
// Now, notify the theory proxy of the assertions and skolem definitions. |
184 |
|
// Notice we do this before asserting the formulas to the CNF stream below, |
185 |
|
// since (preregistration) lemmas may occur during calls to assertInternal. |
186 |
|
// These lemmas we want to be notified about after the theory proxy has |
187 |
|
// been notified about all input assertions. |
188 |
19097 |
std::unordered_map<size_t, Node>::iterator it; |
189 |
154934 |
for (size_t i = 0, asize = assertions.size(); i < asize; i++) |
190 |
|
{ |
191 |
|
// is the assertion a skolem definition? |
192 |
135837 |
it = skolemMap.find(i); |
193 |
271674 |
Node skolem; |
194 |
135837 |
if (it != skolemMap.end()) |
195 |
|
{ |
196 |
18544 |
skolem = it->second; |
197 |
|
} |
198 |
135837 |
d_theoryProxy->notifyAssertion(assertions[i], skolem, false); |
199 |
|
} |
200 |
154924 |
for (const Node& node : assertions) |
201 |
|
{ |
202 |
135831 |
Debug("prop") << "assertFormula(" << node << ")" << std::endl; |
203 |
135835 |
assertInternal(node, false, false, true); |
204 |
|
} |
205 |
19093 |
} |
206 |
|
|
207 |
515559 |
void PropEngine::assertLemma(TrustNode tlemma, theory::LemmaProperty p) |
208 |
|
{ |
209 |
515559 |
bool removable = isLemmaPropertyRemovable(p); |
210 |
|
|
211 |
|
// call preprocessor |
212 |
1031118 |
std::vector<theory::SkolemLemma> ppLemmas; |
213 |
1031118 |
TrustNode tplemma = d_theoryProxy->preprocessLemma(tlemma, ppLemmas); |
214 |
|
|
215 |
|
// do final checks on the lemmas we are about to send |
216 |
1031114 |
if (isProofEnabled() |
217 |
515557 |
&& options::proofCheck() == options::ProofCheckMode::EAGER) |
218 |
|
{ |
219 |
106 |
Assert(tplemma.getGenerator() != nullptr); |
220 |
|
// ensure closed, make the proof node eagerly here to debug |
221 |
106 |
tplemma.debugCheckClosed("te-proof-debug", "TheoryEngine::lemma"); |
222 |
106 |
for (theory::SkolemLemma& lem : ppLemmas) |
223 |
|
{ |
224 |
|
Assert(lem.d_lemma.getGenerator() != nullptr); |
225 |
|
lem.d_lemma.debugCheckClosed("te-proof-debug", "TheoryEngine::lemma_new"); |
226 |
|
} |
227 |
|
} |
228 |
|
|
229 |
515557 |
if (Trace.isOn("te-lemma")) |
230 |
|
{ |
231 |
|
Trace("te-lemma") << "Lemma, output: " << tplemma.getProven() << std::endl; |
232 |
|
for (const theory::SkolemLemma& lem : ppLemmas) |
233 |
|
{ |
234 |
|
Trace("te-lemma") << "Lemma, new lemma: " << lem.d_lemma.getProven() |
235 |
|
<< " (skolem is " << lem.d_skolem << ")" << std::endl; |
236 |
|
} |
237 |
|
} |
238 |
|
|
239 |
|
// now, assert the lemmas |
240 |
515557 |
assertLemmasInternal(tplemma, ppLemmas, removable); |
241 |
515557 |
} |
242 |
|
|
243 |
526773 |
void PropEngine::assertTrustedLemmaInternal(TrustNode trn, bool removable) |
244 |
|
{ |
245 |
1053546 |
Node node = trn.getNode(); |
246 |
526773 |
Debug("prop::lemmas") << "assertLemma(" << node << ")" << std::endl; |
247 |
526773 |
bool negated = trn.getKind() == TrustNodeKind::CONFLICT; |
248 |
526773 |
Assert( |
249 |
|
!isProofEnabled() || trn.getGenerator() != nullptr |
250 |
|
|| options::unsatCores() |
251 |
|
|| (options::unsatCores() |
252 |
|
&& options::unsatCoresMode() != options::UnsatCoresMode::FULL_PROOF)); |
253 |
526773 |
assertInternal(trn.getNode(), negated, removable, false, trn.getGenerator()); |
254 |
526773 |
} |
255 |
|
|
256 |
662604 |
void PropEngine::assertInternal( |
257 |
|
TNode node, bool negated, bool removable, bool input, ProofGenerator* pg) |
258 |
|
{ |
259 |
|
// Assert as (possibly) removable |
260 |
662604 |
if (options::unsatCoresMode() == options::UnsatCoresMode::ASSUMPTIONS) |
261 |
|
{ |
262 |
171689 |
if (input) |
263 |
|
{ |
264 |
35485 |
d_cnfStream->ensureLiteral(node); |
265 |
35485 |
if (negated) |
266 |
|
{ |
267 |
|
d_assumptions.push_back(node.notNode()); |
268 |
|
} |
269 |
|
else |
270 |
|
{ |
271 |
35485 |
d_assumptions.push_back(node); |
272 |
|
} |
273 |
|
} |
274 |
|
else |
275 |
|
{ |
276 |
136204 |
d_cnfStream->convertAndAssert(node, removable, negated, input); |
277 |
|
} |
278 |
|
} |
279 |
490915 |
else if (isProofEnabled()) |
280 |
|
{ |
281 |
99111 |
d_pfCnfStream->convertAndAssert(node, negated, removable, pg); |
282 |
|
// if input, register the assertion in the proof manager |
283 |
99111 |
if (input) |
284 |
|
{ |
285 |
26778 |
d_ppm->registerAssertion(node); |
286 |
|
} |
287 |
|
} |
288 |
|
else |
289 |
|
{ |
290 |
391808 |
d_cnfStream->convertAndAssert(node, removable, negated, input); |
291 |
|
} |
292 |
662600 |
} |
293 |
|
|
294 |
768316 |
void PropEngine::assertLemmasInternal( |
295 |
|
TrustNode trn, |
296 |
|
const std::vector<theory::SkolemLemma>& ppLemmas, |
297 |
|
bool removable) |
298 |
|
{ |
299 |
768316 |
if (!trn.isNull()) |
300 |
|
{ |
301 |
515557 |
assertTrustedLemmaInternal(trn, removable); |
302 |
|
} |
303 |
779532 |
for (const theory::SkolemLemma& lem : ppLemmas) |
304 |
|
{ |
305 |
11216 |
assertTrustedLemmaInternal(lem.d_lemma, removable); |
306 |
|
} |
307 |
|
// assert to decision engine |
308 |
768316 |
if (!removable) |
309 |
|
{ |
310 |
|
// also add to the decision engine, where notice we don't need proofs |
311 |
617932 |
if (!trn.isNull()) |
312 |
|
{ |
313 |
|
// notify the theory proxy of the lemma |
314 |
365173 |
d_theoryProxy->notifyAssertion(trn.getProven(), TNode::null(), true); |
315 |
|
} |
316 |
629148 |
for (const theory::SkolemLemma& lem : ppLemmas) |
317 |
|
{ |
318 |
11216 |
d_theoryProxy->notifyAssertion(lem.getProven(), lem.d_skolem, true); |
319 |
|
} |
320 |
|
} |
321 |
768316 |
} |
322 |
|
|
323 |
72648 |
void PropEngine::requirePhase(TNode n, bool phase) { |
324 |
72648 |
Debug("prop") << "requirePhase(" << n << ", " << phase << ")" << std::endl; |
325 |
|
|
326 |
72648 |
Assert(n.getType().isBoolean()); |
327 |
72648 |
SatLiteral lit = d_cnfStream->getLiteral(n); |
328 |
72648 |
d_satSolver->requirePhase(phase ? lit : ~lit); |
329 |
72648 |
} |
330 |
|
|
331 |
171751 |
bool PropEngine::isDecision(Node lit) const { |
332 |
171751 |
Assert(isSatLiteral(lit)); |
333 |
171751 |
return d_satSolver->isDecision(d_cnfStream->getLiteral(lit).getSatVariable()); |
334 |
|
} |
335 |
|
|
336 |
8 |
int32_t PropEngine::getDecisionLevel(Node lit) const |
337 |
|
{ |
338 |
8 |
Assert(isSatLiteral(lit)); |
339 |
16 |
return d_satSolver->getDecisionLevel( |
340 |
16 |
d_cnfStream->getLiteral(lit).getSatVariable()); |
341 |
|
} |
342 |
|
|
343 |
8 |
int32_t PropEngine::getIntroLevel(Node lit) const |
344 |
|
{ |
345 |
8 |
Assert(isSatLiteral(lit)); |
346 |
16 |
return d_satSolver->getIntroLevel( |
347 |
16 |
d_cnfStream->getLiteral(lit).getSatVariable()); |
348 |
|
} |
349 |
|
|
350 |
|
void PropEngine::printSatisfyingAssignment(){ |
351 |
|
const CnfStream::NodeToLiteralMap& transCache = |
352 |
|
d_cnfStream->getTranslationCache(); |
353 |
|
Debug("prop-value") << "Literal | Value | Expr" << std::endl |
354 |
|
<< "----------------------------------------" |
355 |
|
<< "-----------------" << std::endl; |
356 |
|
for(CnfStream::NodeToLiteralMap::const_iterator i = transCache.begin(), |
357 |
|
end = transCache.end(); |
358 |
|
i != end; |
359 |
|
++i) { |
360 |
|
std::pair<Node, SatLiteral> curr = *i; |
361 |
|
SatLiteral l = curr.second; |
362 |
|
if(!l.isNegated()) { |
363 |
|
Node n = curr.first; |
364 |
|
SatValue value = d_satSolver->modelValue(l); |
365 |
|
Debug("prop-value") << "'" << l << "' " << value << " " << n << std::endl; |
366 |
|
} |
367 |
|
} |
368 |
|
} |
369 |
|
|
370 |
20562 |
Result PropEngine::checkSat() { |
371 |
20562 |
Assert(!d_inCheckSat) << "Sat solver in solve()!"; |
372 |
20562 |
Debug("prop") << "PropEngine::checkSat()" << std::endl; |
373 |
|
|
374 |
|
// Mark that we are in the checkSat |
375 |
41124 |
ScopedBool scopedBool(d_inCheckSat); |
376 |
20562 |
d_inCheckSat = true; |
377 |
|
|
378 |
|
// Note this currently ignores conflicts (a dangerous practice). |
379 |
20562 |
d_theoryProxy->presolve(); |
380 |
|
|
381 |
20562 |
if(options::preprocessOnly()) { |
382 |
3 |
return Result(Result::SAT_UNKNOWN, Result::REQUIRES_FULL_CHECK); |
383 |
|
} |
384 |
|
|
385 |
|
// Reset the interrupted flag |
386 |
20559 |
d_interrupted = false; |
387 |
|
|
388 |
|
// Check the problem |
389 |
|
SatValue result; |
390 |
20559 |
if (d_assumptions.size() == 0) |
391 |
|
{ |
392 |
16846 |
result = d_satSolver->solve(); |
393 |
|
} |
394 |
|
else |
395 |
|
{ |
396 |
7426 |
std::vector<SatLiteral> assumptions; |
397 |
53954 |
for (const Node& node : d_assumptions) |
398 |
|
{ |
399 |
50241 |
assumptions.push_back(d_cnfStream->getLiteral(node)); |
400 |
|
} |
401 |
3713 |
result = d_satSolver->solve(assumptions); |
402 |
|
} |
403 |
|
|
404 |
20536 |
if( result == SAT_VALUE_UNKNOWN ) { |
405 |
|
ResourceManager* rm = d_env.getResourceManager(); |
406 |
|
Result::UnknownExplanation why = Result::INTERRUPTED; |
407 |
|
if (rm->outOfTime()) |
408 |
|
{ |
409 |
|
why = Result::TIMEOUT; |
410 |
|
} |
411 |
|
if (rm->outOfResources()) |
412 |
|
{ |
413 |
|
why = Result::RESOURCEOUT; |
414 |
|
} |
415 |
|
return Result(Result::SAT_UNKNOWN, why); |
416 |
|
} |
417 |
|
|
418 |
20536 |
if( result == SAT_VALUE_TRUE && Debug.isOn("prop") ) { |
419 |
|
printSatisfyingAssignment(); |
420 |
|
} |
421 |
|
|
422 |
20536 |
Debug("prop") << "PropEngine::checkSat() => " << result << std::endl; |
423 |
20536 |
if(result == SAT_VALUE_TRUE && d_theoryEngine->isIncomplete()) { |
424 |
147 |
return Result(Result::SAT_UNKNOWN, Result::INCOMPLETE); |
425 |
|
} |
426 |
20389 |
return Result(result == SAT_VALUE_TRUE ? Result::SAT : Result::UNSAT); |
427 |
|
} |
428 |
|
|
429 |
50905 |
Node PropEngine::getValue(TNode node) const |
430 |
|
{ |
431 |
50905 |
Assert(node.getType().isBoolean()); |
432 |
50905 |
Assert(d_cnfStream->hasLiteral(node)); |
433 |
|
|
434 |
50905 |
SatLiteral lit = d_cnfStream->getLiteral(node); |
435 |
|
|
436 |
50905 |
SatValue v = d_satSolver->value(lit); |
437 |
50905 |
if (v == SAT_VALUE_TRUE) |
438 |
|
{ |
439 |
50872 |
return NodeManager::currentNM()->mkConst(true); |
440 |
|
} |
441 |
33 |
else if (v == SAT_VALUE_FALSE) |
442 |
|
{ |
443 |
33 |
return NodeManager::currentNM()->mkConst(false); |
444 |
|
} |
445 |
|
else |
446 |
|
{ |
447 |
|
Assert(v == SAT_VALUE_UNKNOWN); |
448 |
|
return Node::null(); |
449 |
|
} |
450 |
|
} |
451 |
|
|
452 |
35181523 |
bool PropEngine::isSatLiteral(TNode node) const |
453 |
|
{ |
454 |
35181523 |
return d_cnfStream->hasLiteral(node); |
455 |
|
} |
456 |
|
|
457 |
12763205 |
bool PropEngine::hasValue(TNode node, bool& value) const |
458 |
|
{ |
459 |
12763205 |
Assert(node.getType().isBoolean()); |
460 |
12763205 |
Assert(d_cnfStream->hasLiteral(node)) << node; |
461 |
|
|
462 |
12763205 |
SatLiteral lit = d_cnfStream->getLiteral(node); |
463 |
|
|
464 |
12763205 |
SatValue v = d_satSolver->value(lit); |
465 |
12763205 |
if (v == SAT_VALUE_TRUE) |
466 |
|
{ |
467 |
7760351 |
value = true; |
468 |
7760351 |
return true; |
469 |
|
} |
470 |
5002854 |
else if (v == SAT_VALUE_FALSE) |
471 |
|
{ |
472 |
190892 |
value = false; |
473 |
190892 |
return true; |
474 |
|
} |
475 |
|
else |
476 |
|
{ |
477 |
4811962 |
Assert(v == SAT_VALUE_UNKNOWN); |
478 |
4811962 |
return false; |
479 |
|
} |
480 |
|
} |
481 |
|
|
482 |
24995 |
void PropEngine::getBooleanVariables(std::vector<TNode>& outputVariables) const |
483 |
|
{ |
484 |
24995 |
d_cnfStream->getBooleanVariables(outputVariables); |
485 |
24995 |
} |
486 |
|
|
487 |
247563 |
Node PropEngine::ensureLiteral(TNode n) |
488 |
|
{ |
489 |
|
// must preprocess |
490 |
247563 |
Node preprocessed = getPreprocessedTerm(n); |
491 |
495126 |
Trace("ensureLiteral") << "ensureLiteral preprocessed: " << preprocessed |
492 |
247563 |
<< std::endl; |
493 |
247563 |
if (isProofEnabled()) |
494 |
|
{ |
495 |
26683 |
d_pfCnfStream->ensureLiteral(preprocessed); |
496 |
|
} |
497 |
|
else |
498 |
|
{ |
499 |
220880 |
d_cnfStream->ensureLiteral(preprocessed); |
500 |
|
} |
501 |
247563 |
return preprocessed; |
502 |
|
} |
503 |
|
|
504 |
252759 |
Node PropEngine::getPreprocessedTerm(TNode n) |
505 |
|
{ |
506 |
|
// must preprocess |
507 |
505518 |
std::vector<theory::SkolemLemma> newLemmas; |
508 |
505518 |
TrustNode tpn = d_theoryProxy->preprocess(n, newLemmas); |
509 |
|
// send lemmas corresponding to the skolems introduced by preprocessing n |
510 |
505518 |
TrustNode trnNull; |
511 |
252759 |
assertLemmasInternal(trnNull, newLemmas, false); |
512 |
505518 |
return tpn.isNull() ? Node(n) : tpn.getNode(); |
513 |
|
} |
514 |
|
|
515 |
2499 |
Node PropEngine::getPreprocessedTerm(TNode n, |
516 |
|
std::vector<Node>& skAsserts, |
517 |
|
std::vector<Node>& sks) |
518 |
|
{ |
519 |
|
// get the preprocessed form of the term |
520 |
2499 |
Node pn = getPreprocessedTerm(n); |
521 |
|
// initialize the set of skolems and assertions to process |
522 |
4998 |
std::vector<Node> toProcessAsserts; |
523 |
4998 |
std::vector<Node> toProcess; |
524 |
2499 |
d_theoryProxy->getSkolems(pn, toProcessAsserts, toProcess); |
525 |
2499 |
size_t index = 0; |
526 |
|
// until fixed point is reached |
527 |
7545 |
while (index < toProcess.size()) |
528 |
|
{ |
529 |
3701 |
Node ka = toProcessAsserts[index]; |
530 |
3701 |
Node k = toProcess[index]; |
531 |
2523 |
index++; |
532 |
2523 |
if (std::find(sks.begin(), sks.end(), k) != sks.end()) |
533 |
|
{ |
534 |
|
// already added the skolem to the list |
535 |
1345 |
continue; |
536 |
|
} |
537 |
|
// must preprocess lemmas as well |
538 |
2356 |
Node kap = getPreprocessedTerm(ka); |
539 |
1178 |
skAsserts.push_back(kap); |
540 |
1178 |
sks.push_back(k); |
541 |
|
// get the skolems in the preprocessed form of the lemma ka |
542 |
1178 |
d_theoryProxy->getSkolems(kap, toProcessAsserts, toProcess); |
543 |
|
} |
544 |
|
// return the preprocessed term |
545 |
4998 |
return pn; |
546 |
|
} |
547 |
|
|
548 |
4941 |
void PropEngine::push() |
549 |
|
{ |
550 |
4941 |
Assert(!d_inCheckSat) << "Sat solver in solve()!"; |
551 |
4941 |
d_satSolver->push(); |
552 |
4941 |
Debug("prop") << "push()" << std::endl; |
553 |
4941 |
} |
554 |
|
|
555 |
4941 |
void PropEngine::pop() |
556 |
|
{ |
557 |
4941 |
Assert(!d_inCheckSat) << "Sat solver in solve()!"; |
558 |
4941 |
d_satSolver->pop(); |
559 |
4941 |
Debug("prop") << "pop()" << std::endl; |
560 |
4941 |
} |
561 |
|
|
562 |
20539 |
void PropEngine::resetTrail() |
563 |
|
{ |
564 |
20539 |
d_satSolver->resetTrail(); |
565 |
20539 |
Debug("prop") << "resetTrail()" << std::endl; |
566 |
20539 |
} |
567 |
|
|
568 |
24391 |
unsigned PropEngine::getAssertionLevel() const |
569 |
|
{ |
570 |
24391 |
return d_satSolver->getAssertionLevel(); |
571 |
|
} |
572 |
|
|
573 |
|
bool PropEngine::isRunning() const { return d_inCheckSat; } |
574 |
|
void PropEngine::interrupt() |
575 |
|
{ |
576 |
|
if (!d_inCheckSat) |
577 |
|
{ |
578 |
|
return; |
579 |
|
} |
580 |
|
|
581 |
|
d_interrupted = true; |
582 |
|
d_satSolver->interrupt(); |
583 |
|
Debug("prop") << "interrupt()" << std::endl; |
584 |
|
} |
585 |
|
|
586 |
2680 |
void PropEngine::spendResource(Resource r) |
587 |
|
{ |
588 |
2680 |
d_env.getResourceManager()->spendResource(r); |
589 |
2680 |
} |
590 |
|
|
591 |
|
bool PropEngine::properExplanation(TNode node, TNode expl) const |
592 |
|
{ |
593 |
|
if (!d_cnfStream->hasLiteral(node)) |
594 |
|
{ |
595 |
|
Trace("properExplanation") |
596 |
|
<< "properExplanation(): Failing because node " |
597 |
|
<< "being explained doesn't have a SAT literal ?!" << std::endl |
598 |
|
<< "properExplanation(): The node is: " << node << std::endl; |
599 |
|
return false; |
600 |
|
} |
601 |
|
|
602 |
|
SatLiteral nodeLit = d_cnfStream->getLiteral(node); |
603 |
|
|
604 |
|
for (TNode::kinded_iterator i = expl.begin(kind::AND), |
605 |
|
i_end = expl.end(kind::AND); |
606 |
|
i != i_end; |
607 |
|
++i) |
608 |
|
{ |
609 |
|
if (!d_cnfStream->hasLiteral(*i)) |
610 |
|
{ |
611 |
|
Trace("properExplanation") |
612 |
|
<< "properExplanation(): Failing because one of explanation " |
613 |
|
<< "nodes doesn't have a SAT literal" << std::endl |
614 |
|
<< "properExplanation(): The explanation node is: " << *i |
615 |
|
<< std::endl; |
616 |
|
return false; |
617 |
|
} |
618 |
|
|
619 |
|
SatLiteral iLit = d_cnfStream->getLiteral(*i); |
620 |
|
|
621 |
|
if (iLit == nodeLit) |
622 |
|
{ |
623 |
|
Trace("properExplanation") |
624 |
|
<< "properExplanation(): Failing because the node" << std::endl |
625 |
|
<< "properExplanation(): " << node << std::endl |
626 |
|
<< "properExplanation(): cannot be made to explain itself!" |
627 |
|
<< std::endl; |
628 |
|
return false; |
629 |
|
} |
630 |
|
|
631 |
|
if (!d_satSolver->properExplanation(nodeLit, iLit)) |
632 |
|
{ |
633 |
|
Trace("properExplanation") |
634 |
|
<< "properExplanation(): SAT solver told us that node" << std::endl |
635 |
|
<< "properExplanation(): " << *i << std::endl |
636 |
|
<< "properExplanation(): is not part of a proper explanation node for" |
637 |
|
<< std::endl |
638 |
|
<< "properExplanation(): " << node << std::endl |
639 |
|
<< "properExplanation(): Perhaps it one of the two isn't assigned or " |
640 |
|
"the explanation" |
641 |
|
<< std::endl |
642 |
|
<< "properExplanation(): node wasn't propagated before the node " |
643 |
|
"being explained" |
644 |
|
<< std::endl; |
645 |
|
return false; |
646 |
|
} |
647 |
|
} |
648 |
|
|
649 |
|
return true; |
650 |
|
} |
651 |
|
|
652 |
3 |
void PropEngine::checkProof(const context::CDList<Node>& assertions) |
653 |
|
{ |
654 |
3 |
if (!d_env.isSatProofProducing()) |
655 |
|
{ |
656 |
|
return; |
657 |
|
} |
658 |
3 |
return d_ppm->checkProof(assertions); |
659 |
|
} |
660 |
|
|
661 |
15234 |
ProofCnfStream* PropEngine::getProofCnfStream() { return d_pfCnfStream.get(); } |
662 |
|
|
663 |
10061 |
std::shared_ptr<ProofNode> PropEngine::getProof() |
664 |
|
{ |
665 |
10061 |
if (!d_env.isSatProofProducing()) |
666 |
|
{ |
667 |
|
return nullptr; |
668 |
|
} |
669 |
10061 |
return d_ppm->getProof(); |
670 |
|
} |
671 |
|
|
672 |
1796147 |
bool PropEngine::isProofEnabled() const { return d_pfCnfStream != nullptr; } |
673 |
|
|
674 |
1409 |
void PropEngine::getUnsatCore(std::vector<Node>& core) |
675 |
|
{ |
676 |
1409 |
Assert(options::unsatCoresMode() == options::UnsatCoresMode::ASSUMPTIONS); |
677 |
2818 |
std::vector<SatLiteral> unsat_assumptions; |
678 |
1409 |
d_satSolver->getUnsatAssumptions(unsat_assumptions); |
679 |
8361 |
for (const SatLiteral& lit : unsat_assumptions) |
680 |
|
{ |
681 |
6952 |
core.push_back(d_cnfStream->getNode(lit)); |
682 |
|
} |
683 |
1409 |
} |
684 |
|
|
685 |
1409 |
std::shared_ptr<ProofNode> PropEngine::getRefutation() |
686 |
|
{ |
687 |
1409 |
Assert(options::unsatCoresMode() == options::UnsatCoresMode::ASSUMPTIONS); |
688 |
2818 |
std::vector<Node> core; |
689 |
1409 |
getUnsatCore(core); |
690 |
2818 |
CDProof cdp(d_env.getProofNodeManager()); |
691 |
2818 |
Node fnode = NodeManager::currentNM()->mkConst(false); |
692 |
1409 |
cdp.addStep(fnode, PfRule::SAT_REFUTATION, core, {}); |
693 |
2818 |
return cdp.getProofFor(fnode); |
694 |
|
} |
695 |
|
|
696 |
|
} // namespace prop |
697 |
31137 |
} // namespace cvc5 |