1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Mathias Preiner, 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 |
|
* Utility for quantifiers state. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/quantifiers/quantifiers_state.h" |
17 |
|
|
18 |
|
#include "options/quantifiers_options.h" |
19 |
|
#include "theory/uf/equality_engine_iterator.h" |
20 |
|
|
21 |
|
namespace cvc5 { |
22 |
|
namespace theory { |
23 |
|
namespace quantifiers { |
24 |
|
|
25 |
9854 |
QuantifiersState::QuantifiersState(Env& env, |
26 |
|
Valuation val, |
27 |
9854 |
const LogicInfo& logicInfo) |
28 |
|
: TheoryState(env, val), |
29 |
|
d_ierCounterc(env.getContext()), |
30 |
9854 |
d_logicInfo(logicInfo) |
31 |
|
{ |
32 |
|
// allow theory combination to go first, once initially |
33 |
9854 |
d_ierCounter = options::instWhenTcFirst() ? 0 : 1; |
34 |
9854 |
d_ierCounterc = d_ierCounter; |
35 |
9854 |
d_ierCounterLc = 0; |
36 |
9854 |
d_ierCounterLastLc = 0; |
37 |
9854 |
d_instWhenPhase = |
38 |
9854 |
1 + (options::instWhenPhase() < 1 ? 1 : options::instWhenPhase()); |
39 |
9854 |
} |
40 |
|
|
41 |
26907 |
void QuantifiersState::incrementInstRoundCounters(Theory::Effort e) |
42 |
|
{ |
43 |
26907 |
if (e == Theory::EFFORT_FULL) |
44 |
|
{ |
45 |
|
// increment if a last call happened, we are not strictly enforcing |
46 |
|
// interleaving, or already were in phase |
47 |
30388 |
if (d_ierCounterLastLc != d_ierCounterLc |
48 |
12010 |
|| !options::instWhenStrictInterleave() |
49 |
27204 |
|| d_ierCounter % d_instWhenPhase != 0) |
50 |
|
{ |
51 |
4976 |
d_ierCounter = d_ierCounter + 1; |
52 |
4976 |
d_ierCounterLastLc = d_ierCounterLc; |
53 |
4976 |
d_ierCounterc = d_ierCounterc.get() + 1; |
54 |
|
} |
55 |
|
} |
56 |
11713 |
else if (e == Theory::EFFORT_LAST_CALL) |
57 |
|
{ |
58 |
11713 |
d_ierCounterLc = d_ierCounterLc + 1; |
59 |
|
} |
60 |
26907 |
} |
61 |
|
|
62 |
145250 |
bool QuantifiersState::getInstWhenNeedsCheck(Theory::Effort e) const |
63 |
|
{ |
64 |
290500 |
Trace("qstate-debug") << "Get inst when needs check, counts=" << d_ierCounter |
65 |
145250 |
<< ", " << d_ierCounterLc << std::endl; |
66 |
|
// determine if we should perform check, based on instWhenMode |
67 |
145250 |
bool performCheck = false; |
68 |
145250 |
if (options::instWhenMode() == options::InstWhenMode::FULL) |
69 |
|
{ |
70 |
36 |
performCheck = (e >= Theory::EFFORT_FULL); |
71 |
|
} |
72 |
145214 |
else if (options::instWhenMode() == options::InstWhenMode::FULL_DELAY) |
73 |
|
{ |
74 |
|
performCheck = (e >= Theory::EFFORT_FULL) && !d_valuation.needCheck(); |
75 |
|
} |
76 |
145214 |
else if (options::instWhenMode() == options::InstWhenMode::FULL_LAST_CALL) |
77 |
|
{ |
78 |
133008 |
performCheck = |
79 |
41757 |
((e == Theory::EFFORT_FULL && d_ierCounter % d_instWhenPhase != 0) |
80 |
260156 |
|| e == Theory::EFFORT_LAST_CALL); |
81 |
|
} |
82 |
24412 |
else if (options::instWhenMode() |
83 |
12206 |
== options::InstWhenMode::FULL_DELAY_LAST_CALL) |
84 |
|
{ |
85 |
|
performCheck = ((e == Theory::EFFORT_FULL && !d_valuation.needCheck() |
86 |
|
&& d_ierCounter % d_instWhenPhase != 0) |
87 |
|
|| e == Theory::EFFORT_LAST_CALL); |
88 |
|
} |
89 |
12206 |
else if (options::instWhenMode() == options::InstWhenMode::LAST_CALL) |
90 |
|
{ |
91 |
12206 |
performCheck = (e >= Theory::EFFORT_LAST_CALL); |
92 |
|
} |
93 |
|
else |
94 |
|
{ |
95 |
|
performCheck = true; |
96 |
|
} |
97 |
145250 |
Trace("qstate-debug") << "...returned " << performCheck << std::endl; |
98 |
145250 |
return performCheck; |
99 |
|
} |
100 |
|
|
101 |
|
uint64_t QuantifiersState::getInstRoundDepth() const |
102 |
|
{ |
103 |
|
return d_ierCounterc.get(); |
104 |
|
} |
105 |
|
|
106 |
|
uint64_t QuantifiersState::getInstRounds() const { return d_ierCounter; } |
107 |
|
|
108 |
|
void QuantifiersState::debugPrintEqualityEngine(const char* c) const |
109 |
|
{ |
110 |
|
bool traceEnabled = Trace.isOn(c); |
111 |
|
if (!traceEnabled) |
112 |
|
{ |
113 |
|
return; |
114 |
|
} |
115 |
|
eq::EqualityEngine* ee = getEqualityEngine(); |
116 |
|
eq::EqClassesIterator eqcs_i = eq::EqClassesIterator(ee); |
117 |
|
std::map<TypeNode, uint64_t> tnum; |
118 |
|
while (!eqcs_i.isFinished()) |
119 |
|
{ |
120 |
|
TNode r = (*eqcs_i); |
121 |
|
TypeNode tr = r.getType(); |
122 |
|
if (tnum.find(tr) == tnum.end()) |
123 |
|
{ |
124 |
|
tnum[tr] = 0; |
125 |
|
} |
126 |
|
tnum[tr]++; |
127 |
|
bool firstTime = true; |
128 |
|
Trace(c) << " " << r; |
129 |
|
Trace(c) << " : { "; |
130 |
|
eq::EqClassIterator eqc_i = eq::EqClassIterator(r, ee); |
131 |
|
while (!eqc_i.isFinished()) |
132 |
|
{ |
133 |
|
TNode n = (*eqc_i); |
134 |
|
if (r != n) |
135 |
|
{ |
136 |
|
if (firstTime) |
137 |
|
{ |
138 |
|
Trace(c) << std::endl; |
139 |
|
firstTime = false; |
140 |
|
} |
141 |
|
Trace(c) << " " << n << std::endl; |
142 |
|
} |
143 |
|
++eqc_i; |
144 |
|
} |
145 |
|
if (!firstTime) |
146 |
|
{ |
147 |
|
Trace(c) << " "; |
148 |
|
} |
149 |
|
Trace(c) << "}" << std::endl; |
150 |
|
++eqcs_i; |
151 |
|
} |
152 |
|
Trace(c) << std::endl; |
153 |
|
for (const std::pair<const TypeNode, uint64_t>& t : tnum) |
154 |
|
{ |
155 |
|
Trace(c) << "# eqc for " << t.first << " : " << t.second << std::endl; |
156 |
|
} |
157 |
|
} |
158 |
|
|
159 |
4581 |
const LogicInfo& QuantifiersState::getLogicInfo() const { return d_logicInfo; } |
160 |
|
|
161 |
242424 |
QuantifiersStatistics& QuantifiersState::getStats() { return d_statistics; } |
162 |
|
|
163 |
|
} // namespace quantifiers |
164 |
|
} // namespace theory |
165 |
29349 |
} // namespace cvc5 |