1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Dejan Jovanovic, 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 |
|
* A "valuation" proxy for TheoryEngine. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/valuation.h" |
17 |
|
|
18 |
|
#include "expr/node.h" |
19 |
|
#include "options/theory_options.h" |
20 |
|
#include "prop/prop_engine.h" |
21 |
|
#include "theory/assertion.h" |
22 |
|
#include "theory/rewriter.h" |
23 |
|
#include "theory/theory_engine.h" |
24 |
|
#include "theory/theory_model.h" |
25 |
|
|
26 |
|
namespace cvc5 { |
27 |
|
namespace theory { |
28 |
|
|
29 |
|
std::ostream& operator<<(std::ostream& os, EqualityStatus s) |
30 |
|
{ |
31 |
|
switch (s) |
32 |
|
{ |
33 |
|
case EQUALITY_TRUE_AND_PROPAGATED: |
34 |
|
os << "EQUALITY_TRUE_AND_PROPAGATED"; |
35 |
|
break; |
36 |
|
case EQUALITY_FALSE_AND_PROPAGATED: |
37 |
|
os << "EQUALITY_FALSE_AND_PROPAGATED"; |
38 |
|
break; |
39 |
|
case EQUALITY_TRUE: os << "EQUALITY_TRUE"; break; |
40 |
|
case EQUALITY_FALSE: os << "EQUALITY_FALSE"; break; |
41 |
|
case EQUALITY_TRUE_IN_MODEL: os << "EQUALITY_TRUE_IN_MODEL"; break; |
42 |
|
case EQUALITY_FALSE_IN_MODEL: os << "EQUALITY_FALSE_IN_MODEL"; break; |
43 |
|
case EQUALITY_UNKNOWN: os << "EQUALITY_UNKNOWN"; break; |
44 |
|
default: Unhandled(); break; |
45 |
|
} |
46 |
|
return os; |
47 |
|
} |
48 |
|
|
49 |
|
bool equalityStatusCompatible(EqualityStatus s1, EqualityStatus s2) { |
50 |
|
switch (s1) { |
51 |
|
case EQUALITY_TRUE: |
52 |
|
case EQUALITY_TRUE_IN_MODEL: |
53 |
|
case EQUALITY_TRUE_AND_PROPAGATED: |
54 |
|
switch (s2) { |
55 |
|
case EQUALITY_TRUE: |
56 |
|
case EQUALITY_TRUE_IN_MODEL: |
57 |
|
case EQUALITY_TRUE_AND_PROPAGATED: |
58 |
|
return true; |
59 |
|
default: |
60 |
|
return false; |
61 |
|
} |
62 |
|
break; |
63 |
|
case EQUALITY_FALSE: |
64 |
|
case EQUALITY_FALSE_IN_MODEL: |
65 |
|
case EQUALITY_FALSE_AND_PROPAGATED: |
66 |
|
switch (s2) { |
67 |
|
case EQUALITY_FALSE: |
68 |
|
case EQUALITY_FALSE_IN_MODEL: |
69 |
|
case EQUALITY_FALSE_AND_PROPAGATED: |
70 |
|
return true; |
71 |
|
default: |
72 |
|
return false; |
73 |
|
} |
74 |
|
break; |
75 |
|
default: |
76 |
|
return false; |
77 |
|
} |
78 |
|
} |
79 |
|
|
80 |
212234 |
bool Valuation::isSatLiteral(TNode n) const { |
81 |
212234 |
Assert(d_engine != nullptr); |
82 |
212234 |
return d_engine->getPropEngine()->isSatLiteral(n); |
83 |
|
} |
84 |
|
|
85 |
50905 |
Node Valuation::getSatValue(TNode n) const { |
86 |
50905 |
Assert(d_engine != nullptr); |
87 |
50905 |
if(n.getKind() == kind::NOT) { |
88 |
|
Node atomRes = d_engine->getPropEngine()->getValue(n[0]); |
89 |
|
if(atomRes.getKind() == kind::CONST_BOOLEAN) { |
90 |
|
return NodeManager::currentNM()->mkConst(!atomRes.getConst<bool>()); |
91 |
|
} else { |
92 |
|
Assert(atomRes.isNull()); |
93 |
|
return atomRes; |
94 |
|
} |
95 |
|
} else { |
96 |
50905 |
return d_engine->getPropEngine()->getValue(n); |
97 |
|
} |
98 |
|
} |
99 |
|
|
100 |
247185 |
bool Valuation::hasSatValue(TNode n, bool& value) const { |
101 |
247185 |
Assert(d_engine != nullptr); |
102 |
247185 |
if (d_engine->getPropEngine()->isSatLiteral(n)) { |
103 |
247136 |
return d_engine->getPropEngine()->hasValue(n, value); |
104 |
|
} else { |
105 |
49 |
return false; |
106 |
|
} |
107 |
|
} |
108 |
|
|
109 |
1364448 |
EqualityStatus Valuation::getEqualityStatus(TNode a, TNode b) { |
110 |
1364448 |
Assert(d_engine != nullptr); |
111 |
1364448 |
return d_engine->getEqualityStatus(a, b); |
112 |
|
} |
113 |
|
|
114 |
4527 |
Node Valuation::getModelValue(TNode var) { |
115 |
4527 |
Assert(d_engine != nullptr); |
116 |
4527 |
return d_engine->getModelValue(var); |
117 |
|
} |
118 |
|
|
119 |
18075331 |
TheoryModel* Valuation::getModel() { |
120 |
18075331 |
if (d_engine == nullptr) |
121 |
|
{ |
122 |
|
// no theory engine, thus we don't have a model object |
123 |
|
return nullptr; |
124 |
|
} |
125 |
18075331 |
return d_engine->getModel(); |
126 |
|
} |
127 |
5313 |
SortInference* Valuation::getSortInference() |
128 |
|
{ |
129 |
5313 |
if (d_engine == nullptr) |
130 |
|
{ |
131 |
|
// no theory engine, thus we don't have a sort inference object |
132 |
|
return nullptr; |
133 |
|
} |
134 |
5313 |
return d_engine->getSortInference(); |
135 |
|
} |
136 |
|
|
137 |
171637 |
void Valuation::setUnevaluatedKind(Kind k) |
138 |
|
{ |
139 |
171637 |
TheoryModel* m = getModel(); |
140 |
171637 |
if (m != nullptr) |
141 |
|
{ |
142 |
171637 |
m->setUnevaluatedKind(k); |
143 |
|
} |
144 |
|
// If no model is available, this command has no effect. This is the case |
145 |
|
// when e.g. calling Theory::finishInit for theories that are using a |
146 |
|
// Valuation with no model. |
147 |
171637 |
} |
148 |
|
|
149 |
30546 |
void Valuation::setSemiEvaluatedKind(Kind k) |
150 |
|
{ |
151 |
30546 |
TheoryModel* m = getModel(); |
152 |
30546 |
if (m != nullptr) |
153 |
|
{ |
154 |
30546 |
m->setSemiEvaluatedKind(k); |
155 |
|
} |
156 |
30546 |
} |
157 |
|
|
158 |
15273 |
void Valuation::setIrrelevantKind(Kind k) |
159 |
|
{ |
160 |
15273 |
TheoryModel* m = getModel(); |
161 |
15273 |
if (m != nullptr) |
162 |
|
{ |
163 |
15273 |
m->setIrrelevantKind(k); |
164 |
|
} |
165 |
15273 |
} |
166 |
|
|
167 |
225995 |
Node Valuation::ensureLiteral(TNode n) { |
168 |
225995 |
Assert(d_engine != nullptr); |
169 |
225995 |
return d_engine->getPropEngine()->ensureLiteral(n); |
170 |
|
} |
171 |
|
|
172 |
1519 |
Node Valuation::getPreprocessedTerm(TNode n) |
173 |
|
{ |
174 |
1519 |
Assert(d_engine != nullptr); |
175 |
1519 |
return d_engine->getPropEngine()->getPreprocessedTerm(n); |
176 |
|
} |
177 |
|
|
178 |
1932 |
Node Valuation::getPreprocessedTerm(TNode n, |
179 |
|
std::vector<Node>& skAsserts, |
180 |
|
std::vector<Node>& sks) |
181 |
|
{ |
182 |
1932 |
Assert(d_engine != nullptr); |
183 |
1932 |
return d_engine->getPropEngine()->getPreprocessedTerm(n, skAsserts, sks); |
184 |
|
} |
185 |
|
|
186 |
171751 |
bool Valuation::isDecision(Node lit) const { |
187 |
171751 |
Assert(d_engine != nullptr); |
188 |
171751 |
return d_engine->getPropEngine()->isDecision(lit); |
189 |
|
} |
190 |
|
|
191 |
8 |
int32_t Valuation::getDecisionLevel(Node lit) const |
192 |
|
{ |
193 |
8 |
Assert(d_engine != nullptr); |
194 |
8 |
return d_engine->getPropEngine()->getDecisionLevel(lit); |
195 |
|
} |
196 |
|
|
197 |
8 |
int32_t Valuation::getIntroLevel(Node lit) const |
198 |
|
{ |
199 |
8 |
Assert(d_engine != nullptr); |
200 |
8 |
return d_engine->getPropEngine()->getIntroLevel(lit); |
201 |
|
} |
202 |
|
|
203 |
9119 |
unsigned Valuation::getAssertionLevel() const{ |
204 |
9119 |
Assert(d_engine != nullptr); |
205 |
9119 |
return d_engine->getPropEngine()->getAssertionLevel(); |
206 |
|
} |
207 |
|
|
208 |
8478 |
std::pair<bool, Node> Valuation::entailmentCheck(options::TheoryOfMode mode, |
209 |
|
TNode lit) |
210 |
|
{ |
211 |
8478 |
Assert(d_engine != nullptr); |
212 |
8478 |
return d_engine->entailmentCheck(mode, lit); |
213 |
|
} |
214 |
|
|
215 |
594126 |
bool Valuation::needCheck() const{ |
216 |
594126 |
Assert(d_engine != nullptr); |
217 |
594126 |
return d_engine->needCheck(); |
218 |
|
} |
219 |
|
|
220 |
9908 |
bool Valuation::isRelevant(Node lit) const { return d_engine->isRelevant(lit); } |
221 |
|
|
222 |
8017 |
context::CDList<Assertion>::const_iterator Valuation::factsBegin(TheoryId tid) |
223 |
|
{ |
224 |
8017 |
Theory* theory = d_engine->theoryOf(tid); |
225 |
8017 |
Assert(theory != nullptr); |
226 |
8017 |
return theory->facts_begin(); |
227 |
|
} |
228 |
8017 |
context::CDList<Assertion>::const_iterator Valuation::factsEnd(TheoryId tid) |
229 |
|
{ |
230 |
8017 |
Theory* theory = d_engine->theoryOf(tid); |
231 |
8017 |
Assert(theory != nullptr); |
232 |
8017 |
return theory->facts_end(); |
233 |
|
} |
234 |
|
|
235 |
|
} // namespace theory |
236 |
31137 |
} // namespace cvc5 |