GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/valuation.cpp Lines: 72 116 62.1 %
Date: 2021-05-22 Branches: 52 361 14.4 %

Line Exec Source
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
862496
bool Valuation::isSatLiteral(TNode n) const {
81
862496
  Assert(d_engine != nullptr);
82
862496
  return d_engine->getPropEngine()->isSatLiteral(n);
83
}
84
85
35074
Node Valuation::getSatValue(TNode n) const {
86
35074
  Assert(d_engine != nullptr);
87
35074
  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
35074
    return d_engine->getPropEngine()->getValue(n);
97
  }
98
}
99
100
134681
bool Valuation::hasSatValue(TNode n, bool& value) const {
101
134681
  Assert(d_engine != nullptr);
102
134681
  if (d_engine->getPropEngine()->isSatLiteral(n)) {
103
134631
    return d_engine->getPropEngine()->hasValue(n, value);
104
  } else {
105
50
    return false;
106
  }
107
}
108
109
1197845
EqualityStatus Valuation::getEqualityStatus(TNode a, TNode b) {
110
1197845
  Assert(d_engine != nullptr);
111
1197845
  return d_engine->getEqualityStatus(a, b);
112
}
113
114
4654
Node Valuation::getModelValue(TNode var) {
115
4654
  Assert(d_engine != nullptr);
116
4654
  return d_engine->getModelValue(var);
117
}
118
119
156125
TheoryModel* Valuation::getModel() {
120
156125
  if (d_engine == nullptr)
121
  {
122
    // no theory engine, thus we don't have a model object
123
    return nullptr;
124
  }
125
156125
  return d_engine->getModel();
126
}
127
5217
SortInference* Valuation::getSortInference()
128
{
129
5217
  if (d_engine == nullptr)
130
  {
131
    // no theory engine, thus we don't have a sort inference object
132
    return nullptr;
133
  }
134
5217
  return d_engine->getSortInference();
135
}
136
137
101100
void Valuation::setUnevaluatedKind(Kind k)
138
{
139
101100
  TheoryModel* m = getModel();
140
101100
  if (m != nullptr)
141
  {
142
101100
    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
101100
}
148
149
18920
void Valuation::setSemiEvaluatedKind(Kind k)
150
{
151
18920
  TheoryModel* m = getModel();
152
18920
  if (m != nullptr)
153
  {
154
18920
    m->setSemiEvaluatedKind(k);
155
  }
156
18920
}
157
158
9460
void Valuation::setIrrelevantKind(Kind k)
159
{
160
9460
  TheoryModel* m = getModel();
161
9460
  if (m != nullptr)
162
  {
163
9460
    m->setIrrelevantKind(k);
164
  }
165
9460
}
166
167
156308
Node Valuation::ensureLiteral(TNode n) {
168
156308
  Assert(d_engine != nullptr);
169
156308
  return d_engine->getPropEngine()->ensureLiteral(n);
170
}
171
172
1436
Node Valuation::getPreprocessedTerm(TNode n)
173
{
174
1436
  Assert(d_engine != nullptr);
175
1436
  return d_engine->getPropEngine()->getPreprocessedTerm(n);
176
}
177
178
1582
Node Valuation::getPreprocessedTerm(TNode n,
179
                                    std::vector<Node>& skAsserts,
180
                                    std::vector<Node>& sks)
181
{
182
1582
  Assert(d_engine != nullptr);
183
1582
  return d_engine->getPropEngine()->getPreprocessedTerm(n, skAsserts, sks);
184
}
185
186
226480
bool Valuation::isDecision(Node lit) const {
187
226480
  Assert(d_engine != nullptr);
188
226480
  return d_engine->getPropEngine()->isDecision(lit);
189
}
190
191
int32_t Valuation::getDecisionLevel(Node lit) const
192
{
193
  Assert(d_engine != nullptr);
194
  return d_engine->getPropEngine()->getDecisionLevel(lit);
195
}
196
197
int32_t Valuation::getIntroLevel(Node lit) const
198
{
199
  Assert(d_engine != nullptr);
200
  return d_engine->getPropEngine()->getIntroLevel(lit);
201
}
202
203
9242
unsigned Valuation::getAssertionLevel() const{
204
9242
  Assert(d_engine != nullptr);
205
9242
  return d_engine->getPropEngine()->getAssertionLevel();
206
}
207
208
5031
std::pair<bool, Node> Valuation::entailmentCheck(options::TheoryOfMode mode,
209
                                                 TNode lit)
210
{
211
5031
  Assert(d_engine != nullptr);
212
5031
  return d_engine->entailmentCheck(mode, lit);
213
}
214
215
331353
bool Valuation::needCheck() const{
216
331353
  Assert(d_engine != nullptr);
217
331353
  return d_engine->needCheck();
218
}
219
220
11468
bool Valuation::isRelevant(Node lit) const { return d_engine->isRelevant(lit); }
221
222
6444
context::CDList<Assertion>::const_iterator Valuation::factsBegin(TheoryId tid)
223
{
224
6444
  Theory* theory = d_engine->theoryOf(tid);
225
6444
  Assert(theory != nullptr);
226
6444
  return theory->facts_begin();
227
}
228
6444
context::CDList<Assertion>::const_iterator Valuation::factsEnd(TheoryId tid)
229
{
230
6444
  Theory* theory = d_engine->theoryOf(tid);
231
6444
  Assert(theory != nullptr);
232
6444
  return theory->facts_end();
233
}
234
235
11008
bool Valuation::isFiniteType(TypeNode tn) const
236
{
237
11008
  return d_engine->isFiniteType(tn);
238
}
239
240
}  // namespace theory
241
28194
}  // namespace cvc5