GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/prop/minisat/minisat.h Lines: 3 5 60.0 %
Date: 2021-11-07 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/minisat/simp/SimpSolver.h"
21
#include "prop/sat_solver.h"
22
#include "smt/env_obj.h"
23
#include "util/statistics_registry.h"
24
25
namespace cvc5 {
26
27
template <class Solver>
28
prop::SatLiteral toSatLiteral(typename Solver::TLit lit);
29
30
template <class Solver>
31
void toSatClause(const typename Solver::TClause& minisat_cl,
32
                 prop::SatClause& sat_cl);
33
34
namespace prop {
35
36
class MinisatSatSolver : public CDCLTSatSolverInterface, protected EnvObj
37
{
38
 public:
39
  MinisatSatSolver(Env& env, StatisticsRegistry& registry);
40
  ~MinisatSatSolver() override;
41
42
  static SatVariable     toSatVariable(Minisat::Var var);
43
  static Minisat::Lit    toMinisatLit(SatLiteral lit);
44
  static SatLiteral      toSatLiteral(Minisat::Lit lit);
45
  static SatValue        toSatLiteralValue(Minisat::lbool res);
46
  static Minisat::lbool  toMinisatlbool(SatValue val);
47
  //(Commented because not in use) static bool            tobool(SatValue val);
48
49
  static void  toMinisatClause(SatClause& clause, Minisat::vec<Minisat::Lit>& minisat_clause);
50
  static void  toSatClause    (const Minisat::Clause& clause, SatClause& sat_clause);
51
  void initialize(context::Context* context,
52
                  TheoryProxy* theoryProxy,
53
                  cvc5::context::UserContext* userContext,
54
                  ProofNodeManager* pnm) override;
55
56
  ClauseId addClause(SatClause& clause, bool removable) override;
57
  ClauseId addXorClause(SatClause& clause, bool rhs, bool removable) override
58
  {
59
    Unreachable() << "Minisat does not support native XOR reasoning";
60
  }
61
62
  SatVariable newVar(bool isTheoryAtom,
63
                     bool preRegister,
64
                     bool canErase) override;
65
15340
  SatVariable trueVar() override { return d_minisat->trueVar(); }
66
15340
  SatVariable falseVar() override { return d_minisat->falseVar(); }
67
68
  SatValue solve() override;
69
  SatValue solve(long unsigned int&) override;
70
  SatValue solve(const std::vector<SatLiteral>& assumptions) override;
71
  void getUnsatAssumptions(std::vector<SatLiteral>& unsat_assumptions) override;
72
73
  bool ok() const override;
74
75
  void interrupt() override;
76
77
  SatValue value(SatLiteral l) override;
78
79
  SatValue modelValue(SatLiteral l) override;
80
81
  bool properExplanation(SatLiteral lit, SatLiteral expl) const override;
82
83
  /** Incremental interface */
84
85
  unsigned getAssertionLevel() const override;
86
87
  void push() override;
88
89
  void pop() override;
90
91
  void resetTrail() override;
92
93
  void requirePhase(SatLiteral lit) override;
94
95
  bool isDecision(SatVariable decn) const override;
96
97
  /** Return decision level at which `lit` was decided on. */
98
  int32_t getDecisionLevel(SatVariable v) const override;
99
100
  /**
101
   * Return user level at which `lit` was introduced.
102
   *
103
   * Note: The user level is tracked independently in the SAT solver and does
104
   * not query the user-context for the user level. The user level in the SAT
105
   * solver starts at level 0 and does not include the global push/pop in
106
   * the SMT engine.
107
   */
108
  int32_t getIntroLevel(SatVariable v) const override;
109
110
  /** Retrieve a pointer to the underlying solver. */
111
  Minisat::SimpSolver* getSolver() { return d_minisat; }
112
113
  /** Retrieve the proof manager of this SAT solver. */
114
  SatProofManager* getProofManager();
115
116
  /** Retrieve the refutation proof of this SAT solver. */
117
  std::shared_ptr<ProofNode> getProof() override;
118
119
 private:
120
121
  /** The SatSolver used */
122
  Minisat::SimpSolver* d_minisat;
123
124
  /** Context we will be using to synchronize the sat solver */
125
  context::Context* d_context;
126
127
  /**
128
   * Stores assumptions passed via last solve() call.
129
   *
130
   * It is used in getUnsatAssumptions() to determine which of the literals in
131
   * the final conflict clause are assumptions.
132
   */
133
  std::unordered_set<SatLiteral, SatLiteralHashFunction> d_assumptions;
134
135
  void setupOptions();
136
137
15335
  class Statistics {
138
  private:
139
   ReferenceStat<int64_t> d_statStarts, d_statDecisions;
140
   ReferenceStat<int64_t> d_statRndDecisions, d_statPropagations;
141
   ReferenceStat<int64_t> d_statConflicts, d_statClausesLiterals;
142
   ReferenceStat<int64_t> d_statLearntsLiterals, d_statMaxLiterals;
143
   ReferenceStat<int64_t> d_statTotLiterals;
144
145
  public:
146
   Statistics(StatisticsRegistry& registry);
147
   void init(Minisat::SimpSolver* d_minisat);
148
   void deinit();
149
  };/* class MinisatSatSolver::Statistics */
150
  Statistics d_statistics;
151
152
}; /* class MinisatSatSolver */
153
154
}  // namespace prop
155
}  // namespace cvc5