Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * Top contributors (to current version): 3 : : * Mudathir Mohamed, Andrew Reynolds, Aina Niemetz 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 : : * Bags theory. 14 : : */ 15 : : 16 : : #include "cvc5_private.h" 17 : : 18 : : #ifndef CVC5__THEORY__BAGS__THEORY_BAGS_H 19 : : #define CVC5__THEORY__BAGS__THEORY_BAGS_H 20 : : 21 : : #include "theory/bags/bag_reduction.h" 22 : : #include "theory/bags/bag_solver.h" 23 : : #include "theory/bags/bags_rewriter.h" 24 : : #include "theory/bags/bags_statistics.h" 25 : : #include "theory/bags/inference_generator.h" 26 : : #include "theory/bags/inference_manager.h" 27 : : #include "theory/bags/solver_state.h" 28 : : #include "theory/bags/strategy.h" 29 : : #include "theory/bags/term_registry.h" 30 : : #include "theory/care_pair_argument_callback.h" 31 : : #include "theory/theory.h" 32 : : #include "theory/theory_eq_notify.h" 33 : : 34 : : namespace cvc5::internal { 35 : : namespace theory { 36 : : namespace bags { 37 : : 38 : : class TheoryBags : public Theory 39 : : { 40 : : public: 41 : : /** Constructs a new instance of TheoryBags w.r.t. the provided contexts. */ 42 : : TheoryBags(Env& env, OutputChannel& out, Valuation valuation); 43 : : ~TheoryBags() override; 44 : : 45 : : //--------------------------------- initialization 46 : : /** get the official theory rewriter of this theory */ 47 : : TheoryRewriter* getTheoryRewriter() override; 48 : : /** get the proof checker of this theory */ 49 : : ProofRuleChecker* getProofChecker() override; 50 : : /** 51 : : * Returns true if we need an equality engine. If so, we initialize the 52 : : * information regarding how it should be setup. For details, see the 53 : : * documentation in Theory::needsEqualityEngine. 54 : : */ 55 : : bool needsEqualityEngine(EeSetupInfo& esi) override; 56 : : /** finish initialization */ 57 : : void finishInit() override; 58 : : /** preprocess rewrite */ 59 : : TrustNode ppRewrite(TNode atom, std::vector<SkolemLemma>& lems) override; 60 : : //--------------------------------- end initialization 61 : : 62 : : /** 63 : : * initialize bag and count terms 64 : : */ 65 : : void initialize(); 66 : : /** 67 : : * collect bags' representatives and all count terms. 68 : : */ 69 : : void collectBagsAndCountTerms(); 70 : : 71 : : //--------------------------------- standard check 72 : : /** Post-check, called after the fact queue of the theory is processed. */ 73 : : void postCheck(Effort effort) override; 74 : : /** Notify fact */ 75 : : void notifyFact(TNode atom, bool pol, TNode fact, bool isInternal) override; 76 : : //--------------------------------- end standard check 77 : : /** Collect model values in m based on the relevant terms given by termSet */ 78 : : bool collectModelValues(TheoryModel* m, 79 : : const std::set<Node>& termSet) override; 80 : : TrustNode explain(TNode) override; 81 : : Node getCandidateModelValue(TNode) override; 82 : 0 : std::string identify() const override { return "THEORY_BAGS"; } 83 : : void preRegisterTerm(TNode n) override; 84 : : 85 : : void presolve() override; 86 : : void computeCareGraph() override; 87 : : void processCarePairArgs(TNode a, TNode b) override; 88 : : bool isCareArg(Node n, unsigned a); 89 : : /** run strategy for effort e */ 90 : : void runStrategy(Theory::Effort e); 91 : : /** run the given inference step */ 92 : : bool runInferStep(InferStep s, int effort); 93 : : 94 : : private: 95 : : /** Functions to handle callbacks from equality engine */ 96 : : class NotifyClass : public TheoryEqNotifyClass 97 : : { 98 : : public: 99 : 51389 : NotifyClass(TheoryBags& theory, TheoryInferenceManager& inferenceManager) 100 : : 101 : 51389 : : TheoryEqNotifyClass(inferenceManager), d_theory(theory) 102 : : { 103 : 51389 : } 104 : : void eqNotifyNewClass(TNode n) override; 105 : : void eqNotifyMerge(TNode n1, TNode n2) override; 106 : : void eqNotifyDisequal(TNode n1, TNode n2, TNode reason) override; 107 : : 108 : : private: 109 : : TheoryBags& d_theory; 110 : : }; 111 : : 112 : : /** expand the definition of the bag.choose operator */ 113 : : TrustNode expandChooseOperator(const Node& node, 114 : : std::vector<SkolemLemma>& lems); 115 : : 116 : : /** The state of the bags solver at full effort */ 117 : : SolverState d_state; 118 : : /** The inference manager */ 119 : : InferenceManager d_im; 120 : : /** The inference generator */ 121 : : InferenceGenerator d_ig; 122 : : /** Instance of the above class */ 123 : : NotifyClass d_notify; 124 : : /** Statistics for the theory of bags. */ 125 : : BagsStatistics d_statistics; 126 : : /** The theory rewriter for this theory. */ 127 : : BagsRewriter d_rewriter; 128 : : /** The term registry for this theory */ 129 : : TermRegistry d_termReg; 130 : : /** the main solver for bags */ 131 : : BagSolver d_solver; 132 : : 133 : : /** The care pair argument callback, used for theory combination */ 134 : : CarePairArgumentCallback d_cpacb; 135 : : /** map kinds to their terms. It is cleared during post check */ 136 : : std::map<Kind, std::vector<Node>> d_opMap; 137 : : 138 : : /** The representation of the strategy */ 139 : : Strategy d_strat; 140 : : 141 : : void eqNotifyNewClass(TNode n); 142 : : void eqNotifyMerge(TNode n1, TNode n2); 143 : : void eqNotifyDisequal(TNode t1, TNode t2, TNode reason); 144 : : }; /* class TheoryBags */ 145 : : 146 : : } // namespace bags 147 : : } // namespace theory 148 : : } // namespace cvc5::internal 149 : : 150 : : #endif /* CVC5__THEORY__BAGS__THEORY_BAGS_H */