1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds |
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 |
|
* Pool-based instantiation strategy |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/quantifiers/inst_strategy_pool.h" |
17 |
|
|
18 |
|
#include "options/quantifiers_options.h" |
19 |
|
#include "theory/quantifiers/first_order_model.h" |
20 |
|
#include "theory/quantifiers/instantiate.h" |
21 |
|
#include "theory/quantifiers/quantifiers_inference_manager.h" |
22 |
|
#include "theory/quantifiers/term_pools.h" |
23 |
|
#include "theory/quantifiers/term_registry.h" |
24 |
|
#include "theory/quantifiers/term_tuple_enumerator.h" |
25 |
|
|
26 |
|
using namespace cvc5::kind; |
27 |
|
using namespace cvc5::context; |
28 |
|
|
29 |
|
namespace cvc5 { |
30 |
|
namespace theory { |
31 |
|
namespace quantifiers { |
32 |
|
|
33 |
4769 |
InstStrategyPool::InstStrategyPool(Env& env, |
34 |
|
QuantifiersState& qs, |
35 |
|
QuantifiersInferenceManager& qim, |
36 |
|
QuantifiersRegistry& qr, |
37 |
4769 |
TermRegistry& tr) |
38 |
4769 |
: QuantifiersModule(env, qs, qim, qr, tr) |
39 |
|
{ |
40 |
4769 |
} |
41 |
|
|
42 |
5725 |
void InstStrategyPool::presolve() {} |
43 |
|
|
44 |
35278 |
bool InstStrategyPool::needsCheck(Theory::Effort e) |
45 |
|
{ |
46 |
35278 |
return d_qstate.getInstWhenNeedsCheck(e); |
47 |
|
} |
48 |
|
|
49 |
19864 |
void InstStrategyPool::reset_round(Theory::Effort e) {} |
50 |
|
|
51 |
10532 |
void InstStrategyPool::registerQuantifier(Node q) |
52 |
|
{ |
53 |
|
// take into account user pools |
54 |
10532 |
if (q.getNumChildren() == 3) |
55 |
|
{ |
56 |
4410 |
Node subsPat = d_qreg.substituteBoundVariablesToInstConstants(q[2], q); |
57 |
|
// add patterns |
58 |
4571 |
for (const Node& p : subsPat) |
59 |
|
{ |
60 |
2366 |
if (p.getKind() == INST_POOL) |
61 |
|
{ |
62 |
2 |
d_userPools[q].push_back(p); |
63 |
|
} |
64 |
|
} |
65 |
|
} |
66 |
10532 |
} |
67 |
|
|
68 |
33333 |
void InstStrategyPool::check(Theory::Effort e, QEffort quant_e) |
69 |
|
{ |
70 |
33333 |
if (d_userPools.empty()) |
71 |
|
{ |
72 |
33332 |
return; |
73 |
|
} |
74 |
1 |
double clSet = 0; |
75 |
1 |
if (Trace.isOn("pool-engine")) |
76 |
|
{ |
77 |
|
clSet = double(clock()) / double(CLOCKS_PER_SEC); |
78 |
|
Trace("pool-engine") << "---Pool instantiation, effort = " << e << "---" |
79 |
|
<< std::endl; |
80 |
|
} |
81 |
1 |
FirstOrderModel* fm = d_treg.getModel(); |
82 |
1 |
bool inConflict = false; |
83 |
1 |
uint64_t addedLemmas = 0; |
84 |
1 |
size_t nquant = fm->getNumAssertedQuantifiers(); |
85 |
1 |
std::map<Node, std::vector<Node> >::iterator uit; |
86 |
2 |
for (size_t i = 0; i < nquant; i++) |
87 |
|
{ |
88 |
2 |
Node q = fm->getAssertedQuantifier(i, true); |
89 |
1 |
uit = d_userPools.find(q); |
90 |
1 |
if (uit == d_userPools.end()) |
91 |
|
{ |
92 |
|
// no user pools for this |
93 |
|
continue; |
94 |
|
} |
95 |
1 |
if (!d_qreg.hasOwnership(q, this) || !fm->isQuantifierActive(q)) |
96 |
|
{ |
97 |
|
// quantified formula is not owned by this or is inactive |
98 |
|
continue; |
99 |
|
} |
100 |
|
// process with each user pool |
101 |
2 |
for (const Node& p : uit->second) |
102 |
|
{ |
103 |
1 |
inConflict = process(q, p, addedLemmas); |
104 |
1 |
if (inConflict) |
105 |
|
{ |
106 |
|
break; |
107 |
|
} |
108 |
|
} |
109 |
1 |
if (inConflict) |
110 |
|
{ |
111 |
|
break; |
112 |
|
} |
113 |
|
} |
114 |
1 |
if (Trace.isOn("pool-engine")) |
115 |
|
{ |
116 |
|
Trace("pool-engine") << "Added lemmas = " << addedLemmas << std::endl; |
117 |
|
double clSet2 = double(clock()) / double(CLOCKS_PER_SEC); |
118 |
|
Trace("pool-engine") << "Finished pool instantiation, time = " |
119 |
|
<< (clSet2 - clSet) << std::endl; |
120 |
|
} |
121 |
|
} |
122 |
|
|
123 |
84813 |
std::string InstStrategyPool::identify() const |
124 |
|
{ |
125 |
84813 |
return std::string("InstStrategyPool"); |
126 |
|
} |
127 |
|
|
128 |
1 |
bool InstStrategyPool::process(Node q, Node p, uint64_t& addedLemmas) |
129 |
|
{ |
130 |
|
TermTupleEnumeratorEnv ttec; |
131 |
1 |
ttec.d_fullEffort = true; |
132 |
1 |
ttec.d_increaseSum = options::fullSaturateSum(); |
133 |
1 |
TermPools* tp = d_treg.getTermPools(); |
134 |
|
std::shared_ptr<TermTupleEnumeratorInterface> enumerator( |
135 |
2 |
mkTermTupleEnumeratorPool(q, &ttec, tp, p)); |
136 |
1 |
Instantiate* ie = d_qim.getInstantiate(); |
137 |
2 |
std::vector<Node> terms; |
138 |
2 |
std::vector<bool> failMask; |
139 |
|
// we instantiate exhaustively |
140 |
1 |
enumerator->init(); |
141 |
5 |
while (enumerator->hasNext()) |
142 |
|
{ |
143 |
2 |
if (d_qstate.isInConflict()) |
144 |
|
{ |
145 |
|
// could be conflicting for an internal reason |
146 |
|
return true; |
147 |
|
} |
148 |
2 |
enumerator->next(terms); |
149 |
|
// try instantiation |
150 |
2 |
failMask.clear(); |
151 |
2 |
if (ie->addInstantiationExpFail( |
152 |
|
q, terms, failMask, InferenceId::QUANTIFIERS_INST_POOL)) |
153 |
|
{ |
154 |
2 |
Trace("pool-inst") << "Success with " << terms << std::endl; |
155 |
2 |
addedLemmas++; |
156 |
|
} |
157 |
|
else |
158 |
|
{ |
159 |
|
Trace("pool-inst") << "Fail with " << terms << std::endl; |
160 |
|
// notify the enumerator of the failure |
161 |
|
enumerator->failureReason(failMask); |
162 |
|
} |
163 |
|
} |
164 |
1 |
return false; |
165 |
|
} |
166 |
|
|
167 |
|
} // namespace quantifiers |
168 |
|
} // namespace theory |
169 |
22755 |
} // namespace cvc5 |