Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * RConsObligation class implementation. 11 : : */ 12 : : 13 : : #include "rcons_obligation.h" 14 : : 15 : : #include <sstream> 16 : : 17 : : #include "expr/node_algorithm.h" 18 : : #include "theory/datatypes/sygus_datatype_utils.h" 19 : : 20 : : namespace cvc5::internal { 21 : : namespace theory { 22 : : namespace quantifiers { 23 : : 24 : 3864 : RConsObligation::RConsObligation(TypeNode stn, Node t) : d_ts({t}) 25 : : { 26 : 1932 : d_k = NodeManager::mkDummySkolem("sygus_rcons", stn); 27 : 1932 : } 28 : : 29 : 0 : TypeNode RConsObligation::getType() const { return d_k.getType(); } 30 : : 31 : 15406 : Node RConsObligation::getSkolem() const { return d_k; } 32 : : 33 : 6 : void RConsObligation::addBuiltin(Node builtin) { d_ts.emplace(builtin); } 34 : : 35 : 480 : const std::unordered_set<Node>& RConsObligation::getBuiltins() const 36 : : { 37 : 480 : return d_ts; 38 : : } 39 : : 40 : 2088 : void RConsObligation::addCandidateSolution(Node candSol) 41 : : { 42 : 2088 : d_candSols.emplace(candSol); 43 : 2088 : } 44 : : 45 : 0 : const std::unordered_set<Node>& RConsObligation::getCandidateSolutions() const 46 : : { 47 : 0 : return d_candSols; 48 : : } 49 : : 50 : 174 : void RConsObligation::addCandidateSolutionToWatchSet(Node candSol) 51 : : { 52 : 174 : d_watchSet.emplace(candSol); 53 : 174 : } 54 : : 55 : 1922 : const std::unordered_set<Node>& RConsObligation::getWatchSet() const 56 : : { 57 : 1922 : return d_watchSet; 58 : : } 59 : : 60 : 0 : void RConsObligation::printCandSols( 61 : : const RConsObligation* root, 62 : : const std::vector<std::unique_ptr<RConsObligation>>& obs) 63 : : { 64 : 0 : std::unordered_set<Node> visited; 65 : 0 : std::vector<const RConsObligation*> stack; 66 : 0 : stack.push_back(root); 67 [ - - ]: 0 : Trace("sygus-rcons") << std::endl << "Eq classes: " << std::endl << '['; 68 : : 69 [ - - ]: 0 : while (!stack.empty()) 70 : : { 71 : 0 : const RConsObligation* curr = stack.back(); 72 : 0 : stack.pop_back(); 73 : 0 : visited.emplace(curr->getSkolem()); 74 : : 75 [ - - ]: 0 : Trace("sygus-rcons") << std::endl 76 : 0 : << " " << *curr << std::endl 77 : 0 : << " {" << std::endl; 78 : : 79 [ - - ]: 0 : for (const Node& candSol : curr->getCandidateSolutions()) 80 : : { 81 [ - - ]: 0 : Trace("sygus-rcons") << " " 82 : 0 : << datatypes::utils::sygusToBuiltin(candSol) 83 : 0 : << std::endl; 84 : 0 : std::unordered_set<Node> vars; 85 : 0 : expr::getVariables(candSol, vars); 86 [ - - ]: 0 : for (const Node& var : vars) 87 : : { 88 [ - - ]: 0 : if (visited.find(var) == visited.cend()) 89 [ - - ]: 0 : for (const std::unique_ptr<RConsObligation>& ob : obs) 90 : : { 91 [ - - ]: 0 : if (ob->getSkolem() == var) 92 : : { 93 : 0 : stack.push_back(ob.get()); 94 : : } 95 : : } 96 : : } 97 : 0 : } 98 [ - - ]: 0 : Trace("sygus-rcons") << " }" << std::endl; 99 : : } 100 : : 101 [ - - ]: 0 : Trace("sygus-rcons") << ']' << std::endl; 102 : 0 : } 103 : : 104 : 0 : std::ostream& operator<<(std::ostream& out, const RConsObligation& ob) 105 : : { 106 : 0 : out << '(' << ob.getType() << ", " << ob.getSkolem() << ", {"; 107 : 0 : std::unordered_set<Node>::const_iterator it = ob.getBuiltins().cbegin(); 108 : 0 : out << *it; 109 : 0 : ++it; 110 [ - - ]: 0 : while (it != ob.getBuiltins().cend()) 111 : : { 112 : 0 : out << ", " << *it; 113 : 0 : ++it; 114 : : } 115 : 0 : out << "})"; 116 : 0 : return out; 117 : : } 118 : : 119 : : } // namespace quantifiers 120 : : } // namespace theory 121 : : } // namespace cvc5::internal