LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/prop/minisat - minisat.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 2 100.0 %
Date: 2026-08-06 10:35:32 Functions: 2 2 100.0 %
Branches: 0 0 -

           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                 :            :  * Implementation of the minisat interface for cvc5.
      13                 :            :  */
      14                 :            : 
      15                 :            : #pragma once
      16                 :            : 
      17                 :            : #include "prop/minisat/simp/SimpSolver.h"
      18                 :            : #include "prop/sat_solver.h"
      19                 :            : #include "smt/env_obj.h"
      20                 :            : #include "util/statistics_registry.h"
      21                 :            : 
      22                 :            : namespace cvc5::internal {
      23                 :            : 
      24                 :            : template <class Solver>
      25                 :            : prop::SatLiteral toSatLiteral(typename Solver::TLit lit);
      26                 :            : 
      27                 :            : template <class Solver>
      28                 :            : void toSatClause(const typename Solver::TClause& minisat_cl,
      29                 :            :                  prop::SatClause& sat_cl);
      30                 :            : 
      31                 :            : namespace prop {
      32                 :            : 
      33                 :            : class MinisatSatSolver : public CDCLTSatSolver, protected EnvObj
      34                 :            : {
      35                 :            :  public:
      36                 :            :   MinisatSatSolver(Env& env, StatisticsRegistry& registry);
      37                 :            :   ~MinisatSatSolver() override;
      38                 :            : 
      39                 :            :   static SatVariable toSatVariable(Minisat::Var var);
      40                 :            :   static Minisat::Lit toMinisatLit(SatLiteral lit);
      41                 :            :   static SatLiteral toSatLiteral(Minisat::Lit lit);
      42                 :            :   static SatValue toSatLiteralValue(Minisat::lbool res);
      43                 :            :   static Minisat::lbool toMinisatlbool(SatValue val);
      44                 :            :   //(Commented because not in use) static bool            tobool(SatValue val);
      45                 :            : 
      46                 :            :   static void toMinisatClause(const SatClause& clause,
      47                 :            :                               Minisat::vec<Minisat::Lit>& minisat_clause);
      48                 :            :   static void toSatClause(const Minisat::Clause& clause, SatClause& sat_clause);
      49                 :            : 
      50                 :            :   void initialize() override;
      51                 :            :   void initialize(TheoryProxy* theoryProxy) override;
      52                 :            :   void attachProofManager(PropPfManager* ppm) override;
      53                 :            : 
      54                 :            :   ClauseId addClause(const SatClause& clause, bool removable) override;
      55                 :            : 
      56                 :            :   SatVariable newVar(bool isTheoryAtom, bool canErase) override;
      57                 :      25995 :   SatVariable trueVar() override { return d_minisat->trueVar(); }
      58                 :      16843 :   SatVariable falseVar() override { return d_minisat->falseVar(); }
      59                 :            : 
      60                 :            :   SatValue solve() override;
      61                 :            :   SatValue solve(long unsigned int&) override;
      62                 :            :   SatValue solve(const std::vector<SatLiteral>& assumptions) override;
      63                 :            :   void getUnsatAssumptions(std::vector<SatLiteral>& unsat_assumptions) override;
      64                 :            : 
      65                 :            :   bool ok() const override;
      66                 :            : 
      67                 :            :   void interrupt() override;
      68                 :            : 
      69                 :            :   SatValue value(SatLiteral l) override;
      70                 :            : 
      71                 :            :   SatValue modelValue(SatLiteral l) override;
      72                 :            : 
      73                 :            :   /** Incremental interface */
      74                 :            : 
      75                 :            :   uint32_t getAssertionLevel() const override;
      76                 :            : 
      77                 :            :   void push() override;
      78                 :            : 
      79                 :            :   void pop() override;
      80                 :            : 
      81                 :            :   void resetTrail() override;
      82                 :            : 
      83                 :            :   void preferPhase(SatLiteral lit) override;
      84                 :            : 
      85                 :            :   bool isDecision(SatVariable decn) const override;
      86                 :            : 
      87                 :            :   bool isFixed(SatVariable var) const override;
      88                 :            : 
      89                 :            :   /** Return the list of current list of decisions that have been made by the
      90                 :            :    * solver at the point when this function is called.
      91                 :            :    */
      92                 :            :   std::vector<SatLiteral> getDecisions() const override;
      93                 :            : 
      94                 :            :   /** Return the order heap.
      95                 :            :    */
      96                 :            :   std::vector<Node> getOrderHeap() const override;
      97                 :            : 
      98                 :            :   /** Retrieve a pointer to the underlying solver. */
      99                 :            :   Minisat::SimpSolver* getSolver() { return d_minisat; }
     100                 :            : 
     101                 :            :   /** Retrieve the refutation proof of this SAT solver. */
     102                 :            :   std::shared_ptr<ProofNode> getProof() override;
     103                 :            : 
     104                 :            :  private:
     105                 :            :   /** The SatSolver used */
     106                 :            :   Minisat::SimpSolver* d_minisat;
     107                 :            : 
     108                 :            :   /** Context we will be using to synchronize the sat solver */
     109                 :            :   context::Context* d_context;
     110                 :            : 
     111                 :            :   /**
     112                 :            :    * Stores assumptions passed via last solve() call.
     113                 :            :    *
     114                 :            :    * It is used in getUnsatAssumptions() to determine which of the literals in
     115                 :            :    * the final conflict clause are assumptions.
     116                 :            :    */
     117                 :            :   std::unordered_set<SatLiteral, SatLiteralHashFunction> d_assumptions;
     118                 :            : 
     119                 :            :   void setupOptions();
     120                 :            : 
     121                 :            :   class Statistics
     122                 :            :   {
     123                 :            :    private:
     124                 :            :     ReferenceStat<int64_t> d_statStarts, d_statDecisions;
     125                 :            :     ReferenceStat<int64_t> d_statRndDecisions, d_statPropagations;
     126                 :            :     ReferenceStat<int64_t> d_statConflicts, d_statClausesLiterals;
     127                 :            :     ReferenceStat<int64_t> d_statLearntsLiterals, d_statMaxLiterals;
     128                 :            :     ReferenceStat<int64_t> d_statTotLiterals;
     129                 :            : 
     130                 :            :    public:
     131                 :            :     Statistics(StatisticsRegistry& registry);
     132                 :            :     void init(Minisat::SimpSolver* d_minisat);
     133                 :            :     void deinit();
     134                 :            :   }; /* class MinisatSatSolver::Statistics */
     135                 :            :   Statistics d_statistics;
     136                 :            : 
     137                 :            : }; /* class MinisatSatSolver */
     138                 :            : 
     139                 :            : }  // namespace prop
     140                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14