LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/smt - difficulty_post_processor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 25 26 96.2 %
Date: 2026-01-21 12:59:26 Functions: 4 4 100.0 %
Branches: 19 38 50.0 %

           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-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                 :            :  * 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                 :        229 : DifficultyPostprocessCallback::DifficultyPostprocessCallback()
      29                 :        229 :     : d_currDifficulty(0)
      30                 :            : {
      31                 :        229 : }
      32                 :            : 
      33                 :        466 : bool DifficultyPostprocessCallback::setCurrentDifficulty(Node d)
      34                 :            : {
      35 [ +  - ][ +  - ]:        932 :   if (d.isConst() && d.getType().isInteger()
                 [ -  - ]
      36         [ +  - ]:        466 :       && d.getConst<Rational>().sgn() >= 0
      37 [ +  - ][ +  - ]:        932 :       && d.getConst<Rational>().getNumerator().fitsUnsignedInt())
         [ +  - ][ +  - ]
                 [ -  - ]
      38                 :            :   {
      39                 :        466 :     d_currDifficulty = d.getConst<Rational>().getNumerator().toUnsignedInt();
      40                 :        466 :     return true;
      41                 :            :   }
      42                 :          0 :   return false;
      43                 :            : }
      44                 :            : 
      45                 :       1271 : bool DifficultyPostprocessCallback::shouldUpdate(std::shared_ptr<ProofNode> pn,
      46                 :            :                                                  const std::vector<Node>& fa,
      47                 :            :                                                  bool& continueUpdate)
      48                 :            : {
      49                 :       1271 :   ProofRule r = pn->getRule();
      50         [ +  + ]:       1271 :   if (r == ProofRule::ASSUME)
      51                 :            :   {
      52         [ +  - ]:        918 :     Trace("difficulty-debug")
      53 [ -  + ][ -  - ]:        459 :         << "  found assume: " << pn->getResult() << std::endl;
      54                 :        459 :     d_accMap[pn->getResult()] += d_currDifficulty;
      55                 :            :   }
      56         [ +  + ]:        812 :   else if (r == ProofRule::MACRO_SR_EQ_INTRO
      57         [ +  + ]:        586 :            || r == ProofRule::MACRO_SR_PRED_INTRO)
      58                 :            :   {
      59                 :            :     // premise is just a substitution, ignore
      60                 :        228 :     continueUpdate = false;
      61                 :        228 :     return false;
      62                 :            :   }
      63                 :       1043 :   return true;
      64                 :            : }
      65                 :            : 
      66                 :        229 : void DifficultyPostprocessCallback::getDifficultyMap(
      67                 :            :     NodeManager* nm, std::map<Node, Node>& dmap) const
      68                 :            : {
      69 [ -  + ][ -  + ]:        229 :   Assert(dmap.empty());
                 [ -  - ]
      70         [ +  + ]:        688 :   for (const std::pair<const Node, uint64_t>& d : d_accMap)
      71                 :            :   {
      72                 :        459 :     dmap[d.first] = nm->mkConstInt(Rational(d.second));
      73                 :            :   }
      74                 :        229 : }
      75                 :            : 
      76                 :            : }  // namespace smt
      77                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14