1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Abdalrhman Mohamed |
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 |
|
* RConsObligation class implementation. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "rcons_obligation.h" |
17 |
|
|
18 |
|
#include <sstream> |
19 |
|
|
20 |
|
#include "expr/node_algorithm.h" |
21 |
|
#include "expr/skolem_manager.h" |
22 |
|
#include "theory/datatypes/sygus_datatype_utils.h" |
23 |
|
|
24 |
|
namespace cvc5 { |
25 |
|
namespace theory { |
26 |
|
namespace quantifiers { |
27 |
|
|
28 |
720 |
RConsObligation::RConsObligation(TypeNode stn, Node t) : d_ts({t}) |
29 |
|
{ |
30 |
720 |
SkolemManager* sm = NodeManager::currentNM()->getSkolemManager(); |
31 |
720 |
d_k = sm->mkDummySkolem("sygus_rcons", stn); |
32 |
720 |
} |
33 |
|
|
34 |
|
TypeNode RConsObligation::getType() const { return d_k.getType(); } |
35 |
|
|
36 |
16645 |
Node RConsObligation::getSkolem() const { return d_k; } |
37 |
|
|
38 |
1 |
void RConsObligation::addBuiltin(Node builtin) { d_ts.emplace(builtin); } |
39 |
|
|
40 |
90 |
const std::unordered_set<Node>& RConsObligation::getBuiltins() const |
41 |
|
{ |
42 |
90 |
return d_ts; |
43 |
|
} |
44 |
|
|
45 |
735 |
void RConsObligation::addCandidateSolution(Node candSol) |
46 |
|
{ |
47 |
735 |
d_candSols.emplace(candSol); |
48 |
735 |
} |
49 |
|
|
50 |
|
const std::unordered_set<Node>& RConsObligation::getCandidateSolutions() const |
51 |
|
{ |
52 |
|
return d_candSols; |
53 |
|
} |
54 |
|
|
55 |
27 |
void RConsObligation::addCandidateSolutionToWatchSet(Node candSol) |
56 |
|
{ |
57 |
27 |
d_watchSet.emplace(candSol); |
58 |
27 |
} |
59 |
|
|
60 |
712 |
const std::unordered_set<Node>& RConsObligation::getWatchSet() const |
61 |
|
{ |
62 |
712 |
return d_watchSet; |
63 |
|
} |
64 |
|
|
65 |
|
void RConsObligation::printCandSols( |
66 |
|
const RConsObligation* root, |
67 |
|
const std::vector<std::unique_ptr<RConsObligation>>& obs) |
68 |
|
{ |
69 |
|
std::unordered_set<Node> visited; |
70 |
|
std::vector<const RConsObligation*> stack; |
71 |
|
stack.push_back(root); |
72 |
|
Trace("sygus-rcons") << std::endl << "Eq classes: " << std::endl << '['; |
73 |
|
|
74 |
|
while (!stack.empty()) |
75 |
|
{ |
76 |
|
const RConsObligation* curr = stack.back(); |
77 |
|
stack.pop_back(); |
78 |
|
visited.emplace(curr->getSkolem()); |
79 |
|
|
80 |
|
Trace("sygus-rcons") << std::endl |
81 |
|
<< " " << *curr << std::endl |
82 |
|
<< " {" << std::endl; |
83 |
|
|
84 |
|
for (const Node& candSol : curr->getCandidateSolutions()) |
85 |
|
{ |
86 |
|
Trace("sygus-rcons") << " " |
87 |
|
<< datatypes::utils::sygusToBuiltin(candSol) |
88 |
|
<< std::endl; |
89 |
|
std::unordered_set<TNode> vars; |
90 |
|
expr::getVariables(candSol, vars); |
91 |
|
for (TNode var : vars) |
92 |
|
{ |
93 |
|
if (visited.find(var) == visited.cend()) |
94 |
|
for (const std::unique_ptr<RConsObligation>& ob : obs) |
95 |
|
{ |
96 |
|
if (ob->getSkolem() == var) |
97 |
|
{ |
98 |
|
stack.push_back(ob.get()); |
99 |
|
} |
100 |
|
} |
101 |
|
} |
102 |
|
} |
103 |
|
Trace("sygus-rcons") << " }" << std::endl; |
104 |
|
} |
105 |
|
|
106 |
|
Trace("sygus-rcons") << ']' << std::endl; |
107 |
|
} |
108 |
|
|
109 |
|
std::ostream& operator<<(std::ostream& out, const RConsObligation& ob) |
110 |
|
{ |
111 |
|
out << '(' << ob.getType() << ", " << ob.getSkolem() << ", {"; |
112 |
|
std::unordered_set<Node>::const_iterator it = ob.getBuiltins().cbegin(); |
113 |
|
out << *it; |
114 |
|
++it; |
115 |
|
while (it != ob.getBuiltins().cend()) |
116 |
|
{ |
117 |
|
out << ", " << *it; |
118 |
|
++it; |
119 |
|
} |
120 |
|
out << "})"; |
121 |
|
return out; |
122 |
|
} |
123 |
|
|
124 |
|
} // namespace quantifiers |
125 |
|
} // namespace theory |
126 |
31125 |
} // namespace cvc5 |