GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/theory/valuation.cpp Lines: 78 116 67.2 %
Date: 2021-08-20 Branches: 58 359 16.2 %

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