SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
ClauseChecker.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "SolverTypes.h"
5 
6 namespace smtrat {
7 namespace sat {
8 namespace detail {
9 
10 struct ClauseChecker {
11  Model buildModel() const {
12  const auto& vp = carl::VariablePool::getInstance();
13  Model model;
14  model.emplace(vp.find_variable_with_name("X"), Rational(1)/2);
15  model.emplace(vp.find_variable_with_name("Y"), Rational(-2));
16  model.emplace(vp.find_variable_with_name("Z"), Rational(2));
17  return model;
18  }
19 
20  void operator()(const FormulaT& formula) const {
21  if (formula.type() == carl::FormulaType::OR) {
22  (*this)(formula.subformulas());
23  } else {
24  (*this)(FormulasT({formula}));
25  }
26  }
27  void operator()(const FormulasT& formulas) const {
28  auto model = buildModel();
29  bool allFalse = true;
30  SMTRAT_LOG_DEBUG("smtrat.sat.clausechecker", "Model: " << model);
31  for (const auto& f: formulas) {
32  ModelValue res = carl::evaluate(f, model);
33  SMTRAT_LOG_DEBUG("smtrat.sat.clausechecker", f << " -> " << res);
34  if (res.isBool()) {
35  allFalse = allFalse && !res.asBool();
36  } else return;
37  }
38  //if (allFalse) std::quick_exit(66);
39  assert(!allFalse);
40  }
41  template<typename VM, typename BCM>
42  void operator()(const Minisat::Clause& c, const VM& vm, const BCM& bcm) const {
43  FormulasT f;
44  for (int i = 0; i < c.size(); i++) {
45  auto v = var(c[i]);
46  // Check whether this literal is a boolean variable
47  auto it = vm.find(v);
48  if (it != vm.end()) {
49  if (sign(c[i])) {
50  f.emplace_back(carl::FormulaType::NOT, FormulaT(it->second));
51  } else {
52  f.emplace_back(it->second);
53  }
54  }
55  // Check whether this literal is a constraint abstraction
56  if (v >= bcm.size()) continue;
57  if (bcm[v].first == nullptr) continue;
58  if (sign(c[i])) {
59  f.emplace_back(bcm[v].second->reabstraction);
60  } else {
61  f.emplace_back(bcm[v].first->reabstraction);
62  }
63  }
64  (*this)(f);
65  }
66 };
67 
68 template<typename T>
69 void validateClause(const T& t, bool enabled) {
70  if (enabled) ClauseChecker()(t);
71 }
72 
73 template<typename T, typename VM, typename BCM>
74 void validateClause(const T& t, const VM& vm, const BCM& bcm, bool enabled) {
75  if (enabled) ClauseChecker()(t, vm, bcm);
76 }
77 
78 }
79 }
80 }
int var(Lit p)
Definition: SolverTypes.h:64
bool sign(Lit p)
Definition: SolverTypes.h:63
Rational evaluate(carl::Variable v, const Poly &p, const Rational &r)
Definition: utils.h:11
void validateClause(const T &t, bool enabled)
Definition: ClauseChecker.h:69
Class to create the formulas for axioms.
carl::ModelValue< Rational, Poly > ModelValue
Definition: model.h:12
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::Model< Rational, Poly > Model
Definition: model.h:13
carl::Formulas< Poly > FormulasT
Definition: types.h:39
mpq_class Rational
Definition: types.h:19
#define SMTRAT_LOG_DEBUG(channel, msg)
Definition: logging.h:35
void operator()(const Minisat::Clause &c, const VM &vm, const BCM &bcm) const
Definition: ClauseChecker.h:42
void operator()(const FormulasT &formulas) const
Definition: ClauseChecker.h:27
void operator()(const FormulaT &formula) const
Definition: ClauseChecker.h:20