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 theory engine output channel. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__THEORY__OUTPUT_CHANNEL_H 16 : : #define CVC5__THEORY__OUTPUT_CHANNEL_H 17 : : 18 : : #include "expr/node.h" 19 : : #include "proof/trust_node.h" 20 : : #include "theory/incomplete_id.h" 21 : : #include "theory/inference_id.h" 22 : : #include "theory/lemma_property.h" 23 : : #include "theory/theory_id.h" 24 : : #include "util/resource_manager.h" 25 : : #include "util/statistics_stats.h" 26 : : 27 : : namespace cvc5::internal { 28 : : 29 : : class TheoryEngine; 30 : : 31 : : namespace theory { 32 : : 33 : : class Theory; 34 : : 35 : : /** 36 : : * An output channel for Theory that passes messages back to a TheoryEngine 37 : : * for a given Theory. 38 : : * 39 : : * Notice that it has interfaces trustedConflict and trustedLemma which are 40 : : * used for ensuring that proof generators are associated with the lemmas 41 : : * and conflicts sent on this output channel. 42 : : */ 43 : : class OutputChannel 44 : : { 45 : : friend class internal::TheoryEngine; 46 : : 47 : : public: 48 : : /** Default constructor */ 49 : : OutputChannel(); 50 : : /** Constructor for use by theory */ 51 : : OutputChannel(StatisticsRegistry& sr, 52 : : TheoryEngine* engine, 53 : : theory::TheoryId theory); 54 : : /** Constructor for use by non-theory */ 55 : : OutputChannel(StatisticsRegistry& sr, 56 : : TheoryEngine* engine, 57 : : const std::string& name, 58 : : size_t id = 0); 59 : 802324 : virtual ~OutputChannel() {} 60 : : 61 : : /** 62 : : * With safePoint(), the theory signals that it is at a safe point 63 : : * and can be interrupted. 64 : : * 65 : : * @throws Interrupted if the theory can be safely interrupted. 66 : : */ 67 : : virtual void safePoint(Resource r); 68 : : /** 69 : : * Indicate a theory conflict has arisen. 70 : : * 71 : : * @param n - a conflict at the current decision level. This should 72 : : * be an AND-kinded node of literals that are TRUE in the current 73 : : * assignment and are in conflict (i.e., at least one must be 74 : : * assigned false), or else a literal by itself (in the case of a 75 : : * unit conflict) which is assigned TRUE (and T-conflicting) in the 76 : : * current assignment. 77 : : */ 78 : : virtual void conflict(TNode conflictNode, InferenceId id); 79 : : /** 80 : : * Propagate a theory literal. 81 : : * 82 : : * @param n - a theory consequence at the current decision level 83 : : * @return false if an immediate conflict was encountered 84 : : */ 85 : : virtual bool propagate(TNode literal); 86 : : 87 : : /** 88 : : * Tell the core that a valid theory lemma at decision level 0 has 89 : : * been detected. (This requests a split.) 90 : : * 91 : : * @param n - a theory lemma valid at decision level 0 92 : : * @param p The properties of the lemma 93 : : */ 94 : : virtual void lemma(TNode lemma, 95 : : InferenceId id, 96 : : LemmaProperty p = LemmaProperty::NONE); 97 : : /** 98 : : * If a decision is made on n that is not requested from a theory, it must be 99 : : * in the phase specified. Note that this is enforced *globally*, i.e., it is 100 : : * completely context-INdependent. If you ever preferPhase() on a literal, 101 : : * it is phase-locked forever and ever. If it is to ever have the 102 : : * other phase as its assignment, it will be because it has been 103 : : * propagated that way (or it's a unit, at decision level 0). 104 : : * 105 : : * @param n - a theory atom with a SAT literal assigned; must have 106 : : * been pre-registered 107 : : * @param phase - the phase to decide on n 108 : : */ 109 : : virtual void preferPhase(TNode n, bool phase); 110 : : /** 111 : : * Notification from a theory that it realizes it is model unsound at 112 : : * this SAT context level. If SAT is later determined by the 113 : : * TheoryEngine, it should actually return an UNKNOWN result. 114 : : */ 115 : : virtual void setModelUnsound(IncompleteId id); 116 : : /** 117 : : * Notification from a theory that it realizes it is refutation unsound at 118 : : * this user context level. If UNSAT is later determined by the 119 : : * TheoryEngine, it should actually return an UNKNOWN result. 120 : : */ 121 : : virtual void setRefutationUnsound(IncompleteId id); 122 : : /** 123 : : * "Spend" a "resource." The meaning is specific to the context in 124 : : * which the theory is operating, and may even be ignored. The 125 : : * intended meaning is that if the user has set a limit on the "units 126 : : * of resource" that can be expended in a search, and that limit is 127 : : * exceeded, then the search is terminated. Note that the check for 128 : : * termination occurs in the main search loop, so while theories 129 : : * should call OutputChannel::spendResource() during particularly 130 : : * long-running operations, they cannot rely on resource() to break 131 : : * out of infinite or intractable computations. 132 : : */ 133 : : virtual void spendResource(Resource r); 134 : : 135 : : /** 136 : : * Let pconf be the pair (Node conf, ProofGenerator * pfg). This method 137 : : * sends conf on the output channel of this class whose proof can be generated 138 : : * by the generator pfg. Apart from pfg, the interface for this method is 139 : : * the same as calling OutputChannel::lemma on conf. 140 : : */ 141 : : virtual void trustedConflict(TrustNode pconf, InferenceId id); 142 : : /** 143 : : * Let plem be the pair (Node lem, ProofGenerator * pfg). 144 : : * Send lem on the output channel of this class whose proof can be generated 145 : : * by the generator pfg. Apart from pfg, the interface for this method is 146 : : * the same as calling OutputChannel::lemma on lem. 147 : : */ 148 : : virtual void trustedLemma(TrustNode plem, 149 : : InferenceId id, 150 : : LemmaProperty p = LemmaProperty::NONE); 151 : : /** 152 : : * Mark used. Called when we wish to mark that the output channel is used, 153 : : * for example, if we wish to manually call check again, even if no lemmas 154 : : * are sent. Note that theory engine determines whether to recheck 155 : : * (TheoryEngine::needsCheck) if lemmas were sent or if the output channel 156 : : * is marked as used. 157 : : */ 158 : : virtual void markUsed(); 159 : : /** 160 : : * Get the theory identifier 161 : : */ 162 : : TheoryId getId() const; 163 : : 164 : : protected: 165 : : /** 166 : : * Statistics for a particular theory. 167 : : */ 168 : : class Statistics 169 : : { 170 : : public: 171 : : Statistics(); 172 : : Statistics(StatisticsRegistry& sr, const std::string& statPrefix); 173 : : /** Number of calls to conflict, propagate, lemma, preferPhase */ 174 : : IntStat conflicts, propagations, lemmas, preferPhase, trustedConflicts, 175 : : trustedLemmas; 176 : : }; 177 : : /** The theory engine we're communicating with. */ 178 : : TheoryEngine* d_engine; 179 : : /** The name of the owner of this channel. */ 180 : : std::string d_name; 181 : : /** The statistics of the theory interractions. */ 182 : : Statistics d_statistics; 183 : : /** The theory owning this channel. */ 184 : : theory::TheoryId d_theory; 185 : : }; 186 : : 187 : : } // namespace theory 188 : : } // namespace cvc5::internal 189 : : 190 : : #endif /* CVC5__THEORY__OUTPUT_CHANNEL_H */