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 : : * SAT Solver. 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__PROP__SAT_SOLVER_H 16 : : #define CVC5__PROP__SAT_SOLVER_H 17 : : 18 : : #include "proof/clause_id.h" 19 : : #include "prop/prop_proof_manager.h" 20 : : #include "prop/sat_solver_types.h" 21 : : 22 : : namespace cvc5::internal { 23 : : namespace prop { 24 : : 25 : : class SatSolverFactory; 26 : : class SatProofManager; 27 : : class TheoryProxy; 28 : : 29 : : class SatSolver 30 : : { 31 : : friend class SatSolverFactory; 32 : : 33 : : public: 34 : : /** Virtual destructor */ 35 : 48699 : virtual ~SatSolver() = default; 36 : : 37 : : /** 38 : : * Add clause to SAT solver. 39 : : * @param clause The clause to add. 40 : : * @param removable True to indicate that this clause is not irredundant. 41 : : */ 42 : : virtual ClauseId addClause(const SatClause& clause, bool removable) = 0; 43 : : 44 : : /** 45 : : * Create a new boolean variable in the solver. 46 : : * @param isTheoryAtom is this a theory atom that needs to be asserted to 47 : : * theory 48 : : * @param canErase whether the sat solver can safely eliminate this variable 49 : : */ 50 : : virtual SatVariable newVar(bool isTheoryAtom, bool canErase) = 0; 51 : : 52 : : /** 53 : : * Create a new (or return an existing) boolean variable representing the 54 : : * constant `true`. 55 : : * @return The variable representing true. 56 : : */ 57 : : virtual SatVariable trueVar() = 0; 58 : : 59 : : /** 60 : : * Create a new (or return an existing) boolean variable representing the 61 : : * constant false. 62 : : * @return The variable representing false. 63 : : */ 64 : : virtual SatVariable falseVar() = 0; 65 : : 66 : : /** Check the satisfiability of the added clauses */ 67 : : virtual SatValue solve() = 0; 68 : : 69 : : /** Check the satisfiability of the added clauses */ 70 : : virtual SatValue solve(long unsigned int&) = 0; 71 : : 72 : : /** Check satisfiability under assumptions */ 73 : : virtual SatValue solve(const std::vector<SatLiteral>& assumptions) = 0; 74 : : 75 : : /** 76 : : * Tell SAT solver to only do propagation on next solve(). 77 : : * 78 : : * @return true if feature is supported, otherwise false. 79 : : */ 80 : 0 : virtual bool setPropagateOnly() { return false; } 81 : : 82 : : /** Interrupt the solver */ 83 : : virtual void interrupt() = 0; 84 : : 85 : : /** Call value() during the search.*/ 86 : : virtual SatValue value(SatLiteral l) = 0; 87 : : 88 : : /** Call modelValue() when the search is done.*/ 89 : : virtual SatValue modelValue(SatLiteral l) = 0; 90 : : 91 : : /** Check if the solver is in an inconsistent state */ 92 : : virtual bool ok() const = 0; 93 : : 94 : : /** 95 : : * Get list of unsatisfiable assumptions. 96 : : * 97 : : * The returned assumptions are a subset of the assumptions provided to 98 : : * the solve method. 99 : : * Can only be called if satisfiability check under assumptions was used and 100 : : * if it returned SAT_VALUE_FALSE. 101 : : */ 102 : : virtual void getUnsatAssumptions( 103 : : std::vector<SatLiteral>& unsat_assumptions) = 0; 104 : : 105 : : private: 106 : : /** Is called by the SatSolverFactory right after construction. */ 107 : : virtual void initialize() = 0; 108 : : }; 109 : : 110 : : class CDCLTSatSolver : public SatSolver 111 : : { 112 : : friend class SatSolverFactory; 113 : : 114 : : public: 115 : : /** Virtual destructor */ 116 : 48678 : ~CDCLTSatSolver() override = default; 117 : : 118 : : virtual void attachProofManager(PropPfManager* ppm) = 0; 119 : : 120 : : /** Get the current assertion level */ 121 : : virtual uint32_t getAssertionLevel() const = 0; 122 : : 123 : : virtual void push() = 0; 124 : : 125 : : virtual void pop() = 0; 126 : : 127 : : /** 128 : : * Reset the decisions in the DPLL(T) SAT solver at the current assertion 129 : : * level. 130 : : */ 131 : : virtual void resetTrail() = 0; 132 : : 133 : : /** 134 : : * Configure the preferred phase for a decision literal. 135 : : * 136 : : * @note This phase is always enforced when the SAT solver decides to make a 137 : : * decision on this variable on its own. If a decision is injected into 138 : : * the SAT solver via TheoryProxy::getNextDecisionRequest(), the 139 : : * preferred phase will only be considered if the decision was derived 140 : : * by the decision engine. It will be ignored if the decision was 141 : : * derived from a theory (the phase enforced by the theory overrides 142 : : * the preferred phase). 143 : : * 144 : : * @param lit The literal. 145 : : */ 146 : : virtual void preferPhase(SatLiteral lit) = 0; 147 : : 148 : : virtual bool isDecision(SatVariable decn) const = 0; 149 : : 150 : : /** 151 : : * Return whether variable has a fixed assignment. 152 : : */ 153 : : virtual bool isFixed(SatVariable var) const = 0; 154 : : 155 : : /** 156 : : * Return the current list of decisions made by the SAT solver. 157 : : */ 158 : : virtual std::vector<SatLiteral> getDecisions() const = 0; 159 : : 160 : : /** 161 : : * Return the order heap of the SAT solver, which is a priority queueue 162 : : * of literals ordered with respect to variable activity. 163 : : */ 164 : : virtual std::vector<Node> getOrderHeap() const = 0; 165 : : 166 : : /** 167 : : * Get proof, which is used if option prop-proof-mode is PROOF. 168 : : * @return a complete proof computed by this SAT solver. 169 : : */ 170 : : virtual std::shared_ptr<ProofNode> getProof() = 0; 171 : : 172 : : private: 173 : : /** 174 : : * Regular initialization to generate a solver that does not have 175 : : * CDCLT features. To be called by SatSolverFactory. 176 : : */ 177 : : void initialize() override = 0; 178 : : 179 : : /** 180 : : * Used instead of initialize() to initializes the solver to act as 181 : : * CDCLT solver. To be called by SatSolverFactory. 182 : : */ 183 : : virtual void initialize(TheoryProxy* theoryProxy) = 0; 184 : : 185 : : }; /* class CDCLTSatSolver */ 186 : : 187 : : } // namespace prop 188 : : } // namespace cvc5::internal 189 : : 190 : : #endif /* CVC5__PROP__SAT_SOLVER_H */