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 : : * [[ Add one-line brief description here ]] 11 : : * 12 : : * [[ Add lengthier description here ]] 13 : : * \todo document this file 14 : : */ 15 : : 16 : : #pragma once 17 : : 18 : : #include "expr/node.h" 19 : : #include "theory/arith/linear/arithvar.h" 20 : : #include "theory/arith/linear/bound_counts.h" 21 : : #include "theory/arith/linear/constraint_forward.h" 22 : : #include "theory/inference_id.h" 23 : : #include "util/rational.h" 24 : : 25 : : namespace cvc5::internal { 26 : : 27 : : class ProofNode; 28 : : 29 : : namespace theory { 30 : : namespace arith::linear { 31 : : 32 : : class TheoryArithPrivate; 33 : : 34 : : /** 35 : : * ArithVarCallBack provides a mechanism for agreeing on callbacks while 36 : : * breaking mutual recursion inclusion order problems. 37 : : */ 38 : : class ArithVarCallBack 39 : : { 40 : : public: 41 : 57381 : virtual ~ArithVarCallBack() {} 42 : : virtual void operator()(ArithVar x) = 0; 43 : : }; 44 : : 45 : : /** 46 : : * Requests arithmetic variables for internal use, 47 : : * and releases arithmetic variables that are no longer being used. 48 : : */ 49 : : class ArithVarMalloc 50 : : { 51 : : public: 52 : 344312 : virtual ~ArithVarMalloc() {} 53 : : virtual ArithVar request() = 0; 54 : : virtual void release(ArithVar v) = 0; 55 : : }; 56 : : 57 : : class TNodeCallBack 58 : : { 59 : : public: 60 : 57381 : virtual ~TNodeCallBack() {} 61 : : virtual void operator()(TNode n) = 0; 62 : : }; 63 : : 64 : : class NodeCallBack 65 : : { 66 : : public: 67 : : virtual ~NodeCallBack() {} 68 : : virtual void operator()(Node n) = 0; 69 : : }; 70 : : 71 : : class RationalCallBack 72 : : { 73 : : public: 74 : 57381 : virtual ~RationalCallBack() {} 75 : : virtual Rational operator()() const = 0; 76 : : }; 77 : : 78 : : class SetupLiteralCallBack : public TNodeCallBack 79 : : { 80 : : private: 81 : : TheoryArithPrivate& d_arith; 82 : : 83 : : public: 84 : : SetupLiteralCallBack(TheoryArithPrivate& ta); 85 : : void operator()(TNode lit) override; 86 : : }; 87 : : 88 : : class DeltaComputeCallback : public RationalCallBack 89 : : { 90 : : private: 91 : : const TheoryArithPrivate& d_ta; 92 : : 93 : : public: 94 : : DeltaComputeCallback(const TheoryArithPrivate& ta); 95 : : Rational operator()() const override; 96 : : }; 97 : : 98 : : class BasicVarModelUpdateCallBack : public ArithVarCallBack 99 : : { 100 : : private: 101 : : TheoryArithPrivate& d_ta; 102 : : 103 : : public: 104 : : BasicVarModelUpdateCallBack(TheoryArithPrivate& ta); 105 : : void operator()(ArithVar x) override; 106 : : }; 107 : : 108 : : class TempVarMalloc : public ArithVarMalloc 109 : : { 110 : : private: 111 : : TheoryArithPrivate& d_ta; 112 : : 113 : : public: 114 : : TempVarMalloc(TheoryArithPrivate& ta); 115 : : ArithVar request() override; 116 : : void release(ArithVar v) override; 117 : : }; 118 : : 119 : : class RaiseConflict 120 : : { 121 : : private: 122 : : TheoryArithPrivate& d_ta; 123 : : 124 : : public: 125 : : RaiseConflict(TheoryArithPrivate& ta); 126 : : 127 : : /** Calls d_ta.raiseConflict(c) */ 128 : : void raiseConflict(ConstraintCP c, InferenceId id) const; 129 : : }; 130 : : 131 : : class FarkasConflictBuilder 132 : : { 133 : : private: 134 : : RationalVector d_farkas; 135 : : ConstraintCPVec d_constraints; 136 : : ConstraintCP d_consequent; 137 : : bool d_consequentSet; 138 : : bool d_produceProofs; 139 : : 140 : : public: 141 : : /** 142 : : * Constructs a new FarkasConflictBuilder. 143 : : */ 144 : : FarkasConflictBuilder(bool produceProofs); 145 : : 146 : : /** 147 : : * Adds an antecedent constraint to the conflict under construction 148 : : * with the farkas coefficient fc * mult. 149 : : * 150 : : * The value mult is either 1 or -1. 151 : : */ 152 : : void addConstraint(ConstraintCP c, const Rational& fc, const Rational& mult); 153 : : 154 : : /** 155 : : * Adds an antecedent constraint to the conflict under construction 156 : : * with the farkas coefficient fc. 157 : : */ 158 : : void addConstraint(ConstraintCP c, const Rational& fc); 159 : : 160 : : /** 161 : : * Makes the last constraint added the consequent. 162 : : * Can be done exactly once per reset(). 163 : : */ 164 : : void makeLastConsequent(); 165 : : 166 : : /** 167 : : * Turns the antecendents into a proof of the negation of one of the 168 : : * antecedents. 169 : : * 170 : : * The buffer is no longer underConstruction afterwards. 171 : : * 172 : : * precondition: 173 : : * - At least two constraints have been asserted. 174 : : * - makeLastConsequent() has been called. 175 : : * 176 : : * postcondition: The returned constraint is in conflict. 177 : : */ 178 : : ConstraintCP commitConflict(NodeManager* nm); 179 : : 180 : : /** Returns true if a conflict has been pushed back since the last reset. */ 181 : : bool underConstruction() const; 182 : : 183 : : /** Returns true if the consequent has been set since the last reset. */ 184 : : bool consequentIsSet() const; 185 : : 186 : : /** Resets the state of the buffer. */ 187 : : void reset(); 188 : : }; 189 : : 190 : : class RaiseEqualityEngineConflict 191 : : { 192 : : private: 193 : : TheoryArithPrivate& d_ta; 194 : : 195 : : public: 196 : : RaiseEqualityEngineConflict(TheoryArithPrivate& ta); 197 : : 198 : : /* If you are not an equality engine, don't use this! 199 : : * 200 : : * The proof should prove that `n` is a conflict. 201 : : * */ 202 : : void raiseEEConflict(Node n, std::shared_ptr<ProofNode> pf) const; 203 : : }; 204 : : 205 : : class BoundCountingLookup 206 : : { 207 : : private: 208 : : TheoryArithPrivate& d_ta; 209 : : 210 : : public: 211 : : BoundCountingLookup(TheoryArithPrivate& ta); 212 : : const BoundsInfo& boundsInfo(ArithVar basic) const; 213 : : BoundCounts atBounds(ArithVar basic) const; 214 : : BoundCounts hasBounds(ArithVar basic) const; 215 : : }; 216 : : 217 : : } // namespace arith::linear 218 : : } // namespace theory 219 : : } // namespace cvc5::internal