Branch data Line data Source code
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-2025 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 : : * The solver for find-synth queries. 14 : : */ 15 : : 16 : : #include "smt/find_synth_solver.h" 17 : : 18 : : #include "expr/sygus_term_enumerator.h" 19 : : #include "options/base_options.h" 20 : : #include "options/quantifiers_options.h" 21 : : #include "theory/quantifiers/candidate_rewrite_database.h" 22 : : #include "theory/quantifiers/query_generator.h" 23 : : #include "theory/quantifiers/rewrite_verifier.h" 24 : : #include "theory/quantifiers/sygus/sygus_enumerator.h" 25 : : #include "theory/quantifiers/sygus_sampler.h" 26 : : #include "util/resource_manager.h" 27 : : 28 : : namespace cvc5::internal { 29 : : namespace smt { 30 : : 31 : 64 : FindSynthSolver::FindSynthSolver(Env& env) : EnvObj(env) {} 32 : : 33 : 76 : Node FindSynthSolver::findSynth(modes::FindSynthTarget fst, 34 : : const std::vector<TypeNode>& gtns) 35 : : { 36 : 76 : d_fst = fst; 37 : : // initialize the synthesis finders 38 : 76 : d_sfinders.clear(); 39 : 76 : d_finished.clear(); 40 [ + + ]: 169 : for (const TypeNode& gtn : gtns) 41 : : { 42 : 93 : d_sfinders.emplace_back(new theory::quantifiers::SynthFinder(d_env)); 43 : 93 : d_sfinders.back()->initialize(fst, gtn); 44 : : } 45 : 76 : d_currIndex = 0; 46 : 76 : return findSynthNext(); 47 : : } 48 : : 49 : 92 : Node FindSynthSolver::findSynthNext() 50 : : { 51 : : // cycle through each until one returns a solution 52 : 184 : Node ret; 53 : 92 : ResourceManager* rm = resourceManager(); 54 [ + + ][ + + ]: 2214 : while (d_finished.size() < d_sfinders.size() && !rm->out()) [ + + ] 55 : : { 56 : 2184 : rm->spendResource(Resource::FindSynthStep); 57 [ + + ]: 2184 : if (d_currIndex == d_sfinders.size()) 58 : : { 59 : 1555 : d_currIndex = 0; 60 : : } 61 [ + + ]: 2184 : if (d_finished.find(d_currIndex) == d_finished.end()) 62 : : { 63 : 1659 : theory::quantifiers::SynthFinder* curr = d_sfinders[d_currIndex].get(); 64 : 1659 : ret = curr->getCurrent(); 65 [ + + ]: 1659 : if (!curr->increment()) 66 : : { 67 : 26 : d_finished.insert(d_currIndex); 68 : : } 69 : : } 70 : 2177 : d_currIndex++; 71 : : // if we terminated 72 [ + + ]: 2177 : if (!ret.isNull()) 73 : : { 74 [ + + ]: 1303 : if (options().quantifiers.sygusStream) 75 : : { 76 : 1248 : std::ostream& out = options().base.out; 77 : 1248 : out << "(" << d_fst << " " << ret << ")" << std::endl; 78 : 1248 : ret = Node::null(); 79 : : } 80 : : else 81 : : { 82 : 55 : return ret; 83 : : } 84 : : } 85 : : } 86 : 30 : return Node::null(); 87 : : } 88 : : 89 : : } // namespace smt 90 : : } // namespace cvc5::internal