1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Haniel Barbosa |
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 unsat core manager of SolverEngine. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "unsat_core_manager.h" |
17 |
|
|
18 |
|
#include "proof/proof_node_algorithm.h" |
19 |
|
#include "smt/assertions.h" |
20 |
|
|
21 |
|
namespace cvc5 { |
22 |
|
namespace smt { |
23 |
|
|
24 |
3856 |
void UnsatCoreManager::getUnsatCore(std::shared_ptr<ProofNode> pfn, |
25 |
|
Assertions& as, |
26 |
|
std::vector<Node>& core) |
27 |
|
{ |
28 |
7712 |
Trace("unsat-core") << "UCManager::getUnsatCore: final proof: " << *pfn.get() |
29 |
3856 |
<< "\n"; |
30 |
3856 |
Assert(pfn->getRule() == PfRule::SCOPE); |
31 |
7712 |
std::vector<Node> fassumps; |
32 |
3856 |
expr::getFreeAssumptions(pfn->getChildren()[0].get(), fassumps); |
33 |
7712 |
Trace("unsat-core") << "UCManager::getUnsatCore: free assumptions: " |
34 |
3856 |
<< fassumps << "\n"; |
35 |
3856 |
const context::CDList<Node>& al = as.getAssertionList(); |
36 |
26943 |
for (const Node& a : al) |
37 |
|
{ |
38 |
23087 |
Trace("unsat-core") << "is assertion " << a << " there?\n"; |
39 |
23087 |
if (std::find(fassumps.begin(), fassumps.end(), a) != fassumps.end()) |
40 |
|
{ |
41 |
10228 |
Trace("unsat-core") << "\tyes\n"; |
42 |
10228 |
core.push_back(a); |
43 |
|
} |
44 |
|
} |
45 |
3856 |
if (Trace.isOn("unsat-core")) |
46 |
|
{ |
47 |
|
Trace("unsat-core") << "UCManager::getUnsatCore():\n"; |
48 |
|
for (const Node& n : core) |
49 |
|
{ |
50 |
|
Trace("unsat-core") << "- " << n << "\n"; |
51 |
|
} |
52 |
|
} |
53 |
3856 |
} |
54 |
|
|
55 |
7 |
void UnsatCoreManager::getRelevantInstantiations( |
56 |
|
std::shared_ptr<ProofNode> pfn, |
57 |
|
std::map<Node, InstantiationList>& insts, |
58 |
|
bool getDebugInfo) |
59 |
|
{ |
60 |
14 |
std::unordered_map<ProofNode*, bool> visited; |
61 |
7 |
std::unordered_map<ProofNode*, bool>::iterator it; |
62 |
14 |
std::vector<std::shared_ptr<ProofNode>> visit; |
63 |
7 |
std::map<Node, InstantiationList>::iterator itq; |
64 |
14 |
std::shared_ptr<ProofNode> cur; |
65 |
7 |
visit.push_back(pfn); |
66 |
317 |
do |
67 |
|
{ |
68 |
324 |
cur = visit.back(); |
69 |
324 |
visit.pop_back(); |
70 |
324 |
it = visited.find(cur.get()); |
71 |
324 |
if (it != visited.end()) |
72 |
|
{ |
73 |
38 |
continue; |
74 |
|
} |
75 |
286 |
visited[cur.get()] = true; |
76 |
286 |
const std::vector<std::shared_ptr<ProofNode>>& cs = cur->getChildren(); |
77 |
286 |
if (cur->getRule() == PfRule::INSTANTIATE) |
78 |
|
{ |
79 |
17 |
const std::vector<Node>& instTerms = cur->getArguments(); |
80 |
17 |
Assert(cs.size() == 1); |
81 |
34 |
Node q = cs[0]->getResult(); |
82 |
|
// the instantiation is a prefix of the arguments up to the number of |
83 |
|
// variables |
84 |
17 |
itq = insts.find(q); |
85 |
17 |
if (itq == insts.end()) |
86 |
|
{ |
87 |
11 |
insts[q].initialize(q); |
88 |
11 |
itq = insts.find(q); |
89 |
|
} |
90 |
68 |
itq->second.d_inst.push_back(InstantiationVec( |
91 |
51 |
{instTerms.begin(), instTerms.begin() + q[0].getNumChildren()})); |
92 |
17 |
if (getDebugInfo) |
93 |
|
{ |
94 |
|
std::vector<Node> extraArgs(instTerms.begin() + q[0].getNumChildren(), |
95 |
|
instTerms.end()); |
96 |
|
if (extraArgs.size() >= 1) |
97 |
|
{ |
98 |
|
getInferenceId(extraArgs[0], itq->second.d_inst.back().d_id); |
99 |
|
} |
100 |
|
if (extraArgs.size() >= 2) |
101 |
|
{ |
102 |
|
itq->second.d_inst.back().d_pfArg = extraArgs[1]; |
103 |
|
} |
104 |
|
} |
105 |
|
} |
106 |
603 |
for (const std::shared_ptr<ProofNode>& cp : cs) |
107 |
|
{ |
108 |
317 |
visit.push_back(cp); |
109 |
|
} |
110 |
324 |
} while (!visit.empty()); |
111 |
7 |
} |
112 |
|
|
113 |
|
} // namespace smt |
114 |
31137 |
} // namespace cvc5 |