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

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
213654
bool Valuation::hasSatValue(TNode n, bool& value) const {
101
213654
  Assert(d_engine != nullptr);
102
213654
  if (d_engine->getPropEngine()->isSatLiteral(n)) {
103
213609
    return d_engine->getPropEngine()->hasValue(n, value);
104
  } else {
105
45
    return false;
106
  }
107
}
108
109
1280043
EqualityStatus Valuation::getEqualityStatus(TNode a, TNode b) {
110
1280043
  Assert(d_engine != nullptr);
111
1280043
  return d_engine->getEqualityStatus(a, b);
112
}
113
114
4490
Node Valuation::getModelValue(TNode var) {
115
4490
  Assert(d_engine != nullptr);
116
4490
  return d_engine->getModelValue(var);
117
}
118
119
170012
TheoryModel* Valuation::getModel() {
120
170012
  if (d_engine == nullptr)
121
  {
122
    // no theory engine, thus we don't have a model object
123
    return nullptr;
124
  }
125
170012
  return d_engine->getModel();
126
}
127
5171
SortInference* Valuation::getSortInference()
128
{
129
5171
  if (d_engine == nullptr)
130
  {
131
    // no theory engine, thus we don't have a sort inference object
132
    return nullptr;
133
  }
134
5171
  return d_engine->getSortInference();
135
}
136
137
105441
void Valuation::setUnevaluatedKind(Kind k)
138
{
139
105441
  TheoryModel* m = getModel();
140
105441
  if (m != nullptr)
141
  {
142
105441
    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
105441
}
148
149
19706
void Valuation::setSemiEvaluatedKind(Kind k)
150
{
151
19706
  TheoryModel* m = getModel();
152
19706
  if (m != nullptr)
153
  {
154
19706
    m->setSemiEvaluatedKind(k);
155
  }
156
19706
}
157
158
9853
void Valuation::setIrrelevantKind(Kind k)
159
{
160
9853
  TheoryModel* m = getModel();
161
9853
  if (m != nullptr)
162
  {
163
9853
    m->setIrrelevantKind(k);
164
  }
165
9853
}
166
167
202133
Node Valuation::ensureLiteral(TNode n) {
168
202133
  Assert(d_engine != nullptr);
169
202133
  return d_engine->getPropEngine()->ensureLiteral(n);
170
}
171
172
1535
Node Valuation::getPreprocessedTerm(TNode n)
173
{
174
1535
  Assert(d_engine != nullptr);
175
1535
  return d_engine->getPropEngine()->getPreprocessedTerm(n);
176
}
177
178
1611
Node Valuation::getPreprocessedTerm(TNode n,
179
                                    std::vector<Node>& skAsserts,
180
                                    std::vector<Node>& sks)
181
{
182
1611
  Assert(d_engine != nullptr);
183
1611
  return d_engine->getPropEngine()->getPreprocessedTerm(n, skAsserts, sks);
184
}
185
186
176861
bool Valuation::isDecision(Node lit) const {
187
176861
  Assert(d_engine != nullptr);
188
176861
  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
514857
bool Valuation::needCheck() const{
216
514857
  Assert(d_engine != nullptr);
217
514857
  return d_engine->needCheck();
218
}
219
220
7930
bool Valuation::isRelevant(Node lit) const { return d_engine->isRelevant(lit); }
221
222
7607
context::CDList<Assertion>::const_iterator Valuation::factsBegin(TheoryId tid)
223
{
224
7607
  Theory* theory = d_engine->theoryOf(tid);
225
7607
  Assert(theory != nullptr);
226
7607
  return theory->facts_begin();
227
}
228
7607
context::CDList<Assertion>::const_iterator Valuation::factsEnd(TheoryId tid)
229
{
230
7607
  Theory* theory = d_engine->theoryOf(tid);
231
7607
  Assert(theory != nullptr);
232
7607
  return theory->facts_end();
233
}
234
235
11287
bool Valuation::isFiniteType(TypeNode tn) const
236
{
237
11287
  return d_engine->isFiniteType(tn);
238
}
239
240
}  // namespace theory
241
29322
}  // namespace cvc5