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