LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory - decision_strategy.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 5 60.0 %
Date: 2024-09-28 11:33:24 Functions: 3 7 42.9 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * Top contributors (to current version):
       3                 :            :  *   Andrew Reynolds, Andres Noetzli, Aina Niemetz
       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                 :            :  * Base classes for decision strategies used by theory solvers
      14                 :            :  * for use in the DecisionManager of TheoryEngine.
      15                 :            :  */
      16                 :            : 
      17                 :            : #include "cvc5_private.h"
      18                 :            : 
      19                 :            : #ifndef CVC5__THEORY__DECISION_STRATEGY__H
      20                 :            : #define CVC5__THEORY__DECISION_STRATEGY__H
      21                 :            : 
      22                 :            : #include "context/cdo.h"
      23                 :            : #include "expr/node.h"
      24                 :            : #include "smt/env_obj.h"
      25                 :            : #include "theory/valuation.h"
      26                 :            : 
      27                 :            : namespace cvc5::internal {
      28                 :            : namespace theory {
      29                 :            : 
      30                 :            : /**
      31                 :            :  * Virtual base class for decision strategies.
      32                 :            :  */
      33                 :            : class DecisionStrategy : protected EnvObj
      34                 :            : {
      35                 :            :  public:
      36                 :      66933 :   DecisionStrategy(Env& env) : EnvObj(env) {}
      37                 :      66529 :   virtual ~DecisionStrategy() {}
      38                 :            :   /**
      39                 :            :    * Initalize this strategy, This is called once per satisfiability call by
      40                 :            :    * the DecisionManager, prior to using this strategy.
      41                 :            :    */
      42                 :            :   virtual void initialize() = 0;
      43                 :            :   /**
      44                 :            :    * If this method returns a non-null node n, then n is the required next
      45                 :            :    * decision of this strategy. It must be the case that n is a literal in
      46                 :            :    * the current CNF stream.
      47                 :            :    */
      48                 :            :   virtual Node getNextDecisionRequest() = 0;
      49                 :            :   /** identify this strategy (for debugging) */
      50                 :            :   virtual std::string identify() const = 0;
      51                 :            : };
      52                 :            : 
      53                 :            : /**
      54                 :            :  * Decision strategy finite model finding.
      55                 :            :  *
      56                 :            :  * This is a virtual base class for decision strategies that follow the
      57                 :            :  * "finite model finding" pattern for decisions. Such strategies have the
      58                 :            :  * distinguishing feature that they are interested in a stream of literals
      59                 :            :  * L_1, L_2, L_3, ... and so on. At any given time, they request that L_i is
      60                 :            :  * asserted true for a minimal i.
      61                 :            :  *
      62                 :            :  * To enforce this strategy, this class maintains a SAT-context dependent
      63                 :            :  * index d_curr_literal, which corresponds to the minimal index of a literal
      64                 :            :  * in the above list that is not asserted false. A call to
      65                 :            :  * getNextDecisionRequest increments this value until we find a literal L_j
      66                 :            :  * that is not assigned false. If L_j is unassigned, we return it as a decision,
      67                 :            :  * otherwise we return no decisions.
      68                 :            :  */
      69                 :            : class DecisionStrategyFmf : public DecisionStrategy
      70                 :            : {
      71                 :            :  public:
      72                 :            :   DecisionStrategyFmf(Env& env, Valuation valuation);
      73                 :      17541 :   virtual ~DecisionStrategyFmf() {}
      74                 :            :   /** initialize */
      75                 :            :   void initialize() override;
      76                 :            :   /** get next decision request */
      77                 :            :   Node getNextDecisionRequest() override;
      78                 :            :   /** Make the n^th literal of this strategy */
      79                 :            :   virtual Node mkLiteral(unsigned n) = 0;
      80                 :            :   /**
      81                 :            :    * This method returns true iff there exists a (minimal) i such that L_i
      82                 :            :    * is a literal allocated by this class, and is asserted true in the current
      83                 :            :    * context. If it returns true, the argument i is set to this i.
      84                 :            :    */
      85                 :            :   bool getAssertedLiteralIndex(unsigned& i) const;
      86                 :            :   /**
      87                 :            :    * This method returns the literal L_i allocated by this class that
      88                 :            :    * has been asserted true in the current context and is such that i is
      89                 :            :    * minimal. It returns null if no such literals exist.
      90                 :            :    */
      91                 :            :   Node getAssertedLiteral();
      92                 :            :   /** Get the n^th literal of this strategy */
      93                 :            :   Node getLiteral(unsigned lit);
      94                 :            : 
      95                 :            :  protected:
      96                 :            :   /**
      97                 :            :    * The valuation of this class, used for knowing what literals are asserted,
      98                 :            :    * and with what polarity.
      99                 :            :    */
     100                 :            :   Valuation d_valuation;
     101                 :            :   /**
     102                 :            :    * The (SAT-context-dependent) flag that is true if there exists a literal
     103                 :            :    * of this class that is asserted true in the current context, according to
     104                 :            :    * d_valuation.
     105                 :            :    */
     106                 :            :   context::CDO<bool> d_has_curr_literal;
     107                 :            :   /**
     108                 :            :    * The (SAT-context-dependent) index of the current literal of this strategy.
     109                 :            :    * This corresponds to the first literal that is not asserted false in the
     110                 :            :    * current context, according to d_valuation.
     111                 :            :    */
     112                 :            :   context::CDO<unsigned> d_curr_literal;
     113                 :            :   /** the list of literals of this strategy */
     114                 :            :   std::vector<Node> d_literals;
     115                 :            : };
     116                 :            : 
     117                 :            : /**
     118                 :            :  * Special case of above where we only wish to allocate a single literal L_1.
     119                 :            :  */
     120                 :            : class DecisionStrategySingleton : public DecisionStrategyFmf
     121                 :            : {
     122                 :            :  public:
     123                 :            :   DecisionStrategySingleton(Env& env,
     124                 :            :                             const char* name,
     125                 :            :                             Node lit,
     126                 :            :                             Valuation valuation);
     127                 :            :   /**
     128                 :            :    * Make the n^th literal of this strategy. This method returns d_literal if
     129                 :            :    * n=0, null otherwise.
     130                 :            :    */
     131                 :            :   Node mkLiteral(unsigned n) override;
     132                 :            :   /** Get single literal */
     133                 :            :   Node getSingleLiteral();
     134                 :            :   /** identify */
     135                 :          0 :   std::string identify() const override { return d_name; }
     136                 :            : 
     137                 :            :  private:
     138                 :            :   /** the name of this strategy */
     139                 :            :   std::string d_name;
     140                 :            :   /** the literal to decide on */
     141                 :            :   Node d_literal;
     142                 :            : };
     143                 :            : 
     144                 :            : /**
     145                 :            :  * Special case of above where we only wish to allocate a (dynamic) vector
     146                 :            :  * of literals.
     147                 :            :  */
     148                 :            : class DecisionStrategyVector : public DecisionStrategyFmf
     149                 :            : {
     150                 :            :  public:
     151                 :            :   DecisionStrategyVector(Env& env, const char* name, Valuation valuation);
     152                 :            :   /**
     153                 :            :    * Make the n^th literal of this strategy. This method returns d_literal if
     154                 :            :    * n=0, null otherwise.
     155                 :            :    */
     156                 :            :   Node mkLiteral(unsigned n) override;
     157                 :            :   /** identify */
     158                 :          0 :   std::string identify() const override { return d_name; }
     159                 :            :   /** Add that literal n should be decided after the current list of literals */
     160                 :            :   void addLiteral(const Node& n);
     161                 :            : 
     162                 :            :  private:
     163                 :            :   /** the name of this strategy */
     164                 :            :   std::string d_name;
     165                 :            :   /** the literal to decide on */
     166                 :            :   std::vector<Node> d_literals;
     167                 :            : };
     168                 :            : 
     169                 :            : }  // namespace theory
     170                 :            : }  // namespace cvc5::internal
     171                 :            : 
     172                 :            : #endif /* CVC5__THEORY__DECISION_STRATEGY__H */

Generated by: LCOV version 1.14