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