1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Aina Niemetz |
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 |
|
* Implementation of term enumeration utility. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "theory/quantifiers/term_enumeration.h" |
17 |
|
|
18 |
|
#include "theory/quantifiers/quant_bound_inference.h" |
19 |
|
|
20 |
|
using namespace cvc5::kind; |
21 |
|
|
22 |
|
namespace cvc5 { |
23 |
|
namespace theory { |
24 |
|
namespace quantifiers { |
25 |
|
|
26 |
13681 |
TermEnumeration::TermEnumeration(QuantifiersBoundInference* qbi) : d_qbi(qbi) {} |
27 |
|
|
28 |
1771 |
Node TermEnumeration::getEnumerateTerm(TypeNode tn, unsigned index) |
29 |
|
{ |
30 |
3542 |
Trace("term-db-enum") << "Get enumerate term " << tn << " " << index |
31 |
1771 |
<< std::endl; |
32 |
1771 |
std::unordered_map<TypeNode, size_t>::iterator it = d_typ_enum_map.find(tn); |
33 |
|
size_t teIndex; |
34 |
1771 |
if (it == d_typ_enum_map.end()) |
35 |
|
{ |
36 |
589 |
teIndex = d_typ_enum.size(); |
37 |
589 |
d_typ_enum_map[tn] = teIndex; |
38 |
589 |
d_typ_enum.push_back(TypeEnumerator(tn)); |
39 |
|
} |
40 |
|
else |
41 |
|
{ |
42 |
1182 |
teIndex = it->second; |
43 |
|
} |
44 |
3651 |
while (index >= d_enum_terms[tn].size()) |
45 |
|
{ |
46 |
940 |
if (d_typ_enum[teIndex].isFinished()) |
47 |
|
{ |
48 |
|
return Node::null(); |
49 |
|
} |
50 |
940 |
d_enum_terms[tn].push_back(*d_typ_enum[teIndex]); |
51 |
940 |
++d_typ_enum[teIndex]; |
52 |
|
} |
53 |
1771 |
return d_enum_terms[tn][index]; |
54 |
|
} |
55 |
|
|
56 |
|
bool TermEnumeration::getDomain(TypeNode tn, std::vector<Node>& dom) |
57 |
|
{ |
58 |
|
if (!d_qbi || !d_qbi->mayComplete(tn)) |
59 |
|
{ |
60 |
|
return false; |
61 |
|
} |
62 |
|
Node curre; |
63 |
|
unsigned counter = 0; |
64 |
|
do |
65 |
|
{ |
66 |
|
curre = getEnumerateTerm(tn, counter); |
67 |
|
counter++; |
68 |
|
if (!curre.isNull()) |
69 |
|
{ |
70 |
|
dom.push_back(curre); |
71 |
|
} |
72 |
|
} while (!curre.isNull()); |
73 |
|
return true; |
74 |
|
} |
75 |
|
|
76 |
|
} // namespace quantifiers |
77 |
|
} // namespace theory |
78 |
29340 |
} // namespace cvc5 |