GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/prop/minisat/minisat.h Lines: 3 5 60.0 %
Date: 2021-05-22 Branches: 0 6 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Mathias Preiner, Haniel Barbosa, Liana Hadarean
4
 *
5
 * This file is part of the cvc5 project.
6
 *
7
 * Copyright (c) 2009-2021 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
 * SAT Solver.
14
 *
15
 * Implementation of the minisat interface for cvc5.
16
 */
17
18
#pragma once
19
20
#include "prop/sat_solver.h"
21
#include "prop/minisat/simp/SimpSolver.h"
22
#include "util/statistics_registry.h"
23
24
namespace cvc5 {
25
26
template <class Solver>
27
prop::SatLiteral toSatLiteral(typename Solver::TLit lit);
28
29
template <class Solver>
30
void toSatClause(const typename Solver::TClause& minisat_cl,
31
                 prop::SatClause& sat_cl);
32
33
namespace prop {
34
35
class MinisatSatSolver : public CDCLTSatSolverInterface
36
{
37
 public:
38
  MinisatSatSolver(StatisticsRegistry& registry);
39
  ~MinisatSatSolver() override;
40
41
  static SatVariable     toSatVariable(Minisat::Var var);
42
  static Minisat::Lit    toMinisatLit(SatLiteral lit);
43
  static SatLiteral      toSatLiteral(Minisat::Lit lit);
44
  static SatValue        toSatLiteralValue(Minisat::lbool res);
45
  static Minisat::lbool  toMinisatlbool(SatValue val);
46
  //(Commented because not in use) static bool            tobool(SatValue val);
47
48
  static void  toMinisatClause(SatClause& clause, Minisat::vec<Minisat::Lit>& minisat_clause);
49
  static void  toSatClause    (const Minisat::Clause& clause, SatClause& sat_clause);
50
  void initialize(context::Context* context,
51
                  TheoryProxy* theoryProxy,
52
                  cvc5::context::UserContext* userContext,
53
                  ProofNodeManager* pnm) override;
54
55
  ClauseId addClause(SatClause& clause, bool removable) override;
56
  ClauseId addXorClause(SatClause& clause, bool rhs, bool removable) override
57
  {
58
    Unreachable() << "Minisat does not support native XOR reasoning";
59
  }
60
61
  SatVariable newVar(bool isTheoryAtom,
62
                     bool preRegister,
63
                     bool canErase) override;
64
9494
  SatVariable trueVar() override { return d_minisat->trueVar(); }
65
9494
  SatVariable falseVar() override { return d_minisat->falseVar(); }
66
67
  SatValue solve() override;
68
  SatValue solve(long unsigned int&) override;
69
  SatValue solve(const std::vector<SatLiteral>& assumptions) override;
70
  void getUnsatAssumptions(std::vector<SatLiteral>& unsat_assumptions) override;
71
72
  bool ok() const override;
73
74
  void interrupt() override;
75
76
  SatValue value(SatLiteral l) override;
77
78
  SatValue modelValue(SatLiteral l) override;
79
80
  bool properExplanation(SatLiteral lit, SatLiteral expl) const override;
81
82
  /** Incremental interface */
83
84
  unsigned getAssertionLevel() const override;
85
86
  void push() override;
87
88
  void pop() override;
89
90
  void resetTrail() override;
91
92
  void requirePhase(SatLiteral lit) override;
93
94
  bool isDecision(SatVariable decn) const override;
95
96
  int32_t getDecisionLevel(SatVariable v) const override;
97
98
  int32_t getIntroLevel(SatVariable v) const override;
99
100
  /** Retrieve a pointer to the unerlying solver. */
101
  Minisat::SimpSolver* getSolver() { return d_minisat; }
102
103
  /** Retrieve the proof manager of this SAT solver. */
104
  SatProofManager* getProofManager();
105
106
  /** Retrieve the refutation proof of this SAT solver. */
107
  std::shared_ptr<ProofNode> getProof() override;
108
109
 private:
110
111
  /** The SatSolver used */
112
  Minisat::SimpSolver* d_minisat;
113
114
  /** Context we will be using to synchronize the sat solver */
115
  context::Context* d_context;
116
117
  /**
118
   * Stores assumptions passed via last solve() call.
119
   *
120
   * It is used in getUnsatAssumptions() to determine which of the literals in
121
   * the final conflict clause are assumptions.
122
   */
123
  std::unordered_set<SatLiteral, SatLiteralHashFunction> d_assumptions;
124
125
  void setupOptions();
126
127
9494
  class Statistics {
128
  private:
129
   ReferenceStat<int64_t> d_statStarts, d_statDecisions;
130
   ReferenceStat<int64_t> d_statRndDecisions, d_statPropagations;
131
   ReferenceStat<int64_t> d_statConflicts, d_statClausesLiterals;
132
   ReferenceStat<int64_t> d_statLearntsLiterals, d_statMaxLiterals;
133
   ReferenceStat<int64_t> d_statTotLiterals;
134
135
  public:
136
   Statistics(StatisticsRegistry& registry);
137
   void init(Minisat::SimpSolver* d_minisat);
138
   void deinit();
139
  };/* class MinisatSatSolver::Statistics */
140
  Statistics d_statistics;
141
142
}; /* class MinisatSatSolver */
143
144
}  // namespace prop
145
}  // namespace cvc5