Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Andrew Reynolds, Hans-Joerg Schurr, Mathias Preiner 4 : : * 5 : : * This file is part of the cvc5 project. 6 : : * 7 : : * Copyright (c) 2009-2024 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 module for processing the difficulty of input assumptions 14 : : * based on proof nodes. 15 : : */ 16 : : 17 : : #include "smt/difficulty_post_processor.h" 18 : : 19 : : #include "smt/env.h" 20 : : #include "util/rational.h" 21 : : 22 : : using namespace cvc5::internal::kind; 23 : : using namespace cvc5::internal::theory; 24 : : 25 : : namespace cvc5::internal { 26 : : namespace smt { 27 : : 28 : 201 : DifficultyPostprocessCallback::DifficultyPostprocessCallback() 29 : 201 : : d_currDifficulty(0) 30 : : { 31 : 201 : } 32 : : 33 : 413 : bool DifficultyPostprocessCallback::setCurrentDifficulty(Node d) 34 : : { 35 [ + - ][ + - ]: 826 : if (d.isConst() && d.getType().isInteger() [ - - ] 36 [ + - ]: 413 : && d.getConst<Rational>().sgn() >= 0 37 [ + - ][ + - ]: 826 : && d.getConst<Rational>().getNumerator().fitsUnsignedInt()) [ + - ][ + - ] [ - - ] 38 : : { 39 : 413 : d_currDifficulty = d.getConst<Rational>().getNumerator().toUnsignedInt(); 40 : 413 : return true; 41 : : } 42 : 0 : return false; 43 : : } 44 : : 45 : 1130 : bool DifficultyPostprocessCallback::shouldUpdate(std::shared_ptr<ProofNode> pn, 46 : : const std::vector<Node>& fa, 47 : : bool& continueUpdate) 48 : : { 49 : 1130 : ProofRule r = pn->getRule(); 50 [ + + ]: 1130 : if (r == ProofRule::ASSUME) 51 : : { 52 [ + - ]: 808 : Trace("difficulty-debug") 53 [ - + ][ - - ]: 404 : << " found assume: " << pn->getResult() << std::endl; 54 : 404 : d_accMap[pn->getResult()] += d_currDifficulty; 55 : : } 56 [ + + ]: 726 : else if (r == ProofRule::MACRO_SR_EQ_INTRO 57 [ + + ]: 530 : || r == ProofRule::MACRO_SR_PRED_INTRO) 58 : : { 59 : : // premise is just a substitution, ignore 60 : 198 : continueUpdate = false; 61 : 198 : return false; 62 : : } 63 : 932 : return true; 64 : : } 65 : : 66 : 201 : void DifficultyPostprocessCallback::getDifficultyMap( 67 : : std::map<Node, Node>& dmap) const 68 : : { 69 [ - + ][ - + ]: 201 : Assert(dmap.empty()); [ - - ] 70 : 201 : NodeManager* nm = NodeManager::currentNM(); 71 [ + + ]: 605 : for (const std::pair<const Node, uint64_t>& d : d_accMap) 72 : : { 73 : 404 : dmap[d.first] = nm->mkConstInt(Rational(d.second)); 74 : : } 75 : 201 : } 76 : : 77 : : } // namespace smt 78 : : } // namespace cvc5::internal