SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Explanation.cpp
Go to the documentation of this file.
1 #include "Explanation.h"
2 #include "ConflictGenerator.h"
3 
4 namespace smtrat {
5 namespace mcsat {
6 namespace fm {
7 
8 template<class Settings>
9 std::optional<mcsat::Explanation> Explanation<Settings>::operator()(const mcsat::Bookkeeping& data, carl::Variable var, const FormulasT& reason, bool force_use_core) const {
10  #ifdef SMTRAT_DEVOPTION_Statistics
11  mStatistics.explanationCalled();
12  #endif
13 
14  carl::Variables allowedVars(data.assignedVariables().begin(), data.assignedVariables().end());
15  allowedVars.insert(var);
16 
17  std::vector<ConstraintT> bounds;
18 
19  if (!Settings::use_all_constraints || force_use_core) {
20  SMTRAT_LOG_DEBUG("smtrat.mcsat.fm", "Explain conflict " << reason);
21 
22  for (const auto& b : reason) {
23  if (b.type() != carl::FormulaType::CONSTRAINT) {
24  SMTRAT_LOG_DEBUG("smtrat.mcsat.fm", "Discarding non-constraint bound " << b);
25  continue;
26  }
27  // Note that FM can only eliminate one variable. Thus, only syntactically univariate bounds can be handled!
28  if (!isSubset(b.variables(), allowedVars)) {
29  SMTRAT_LOG_DEBUG("smtrat.mcsat.fm", "Discarding non-univariate bound " << b);
30  continue;
31  }
32  assert(b.type() == carl::FormulaType::CONSTRAINT);
33  bounds.emplace_back(b.constraint());
34  }
35  } else {
36  SMTRAT_LOG_DEBUG("smtrat.mcsat.fm", "Explain conflict " << data.constraints());
37 
38  for (const auto& b : data.constraints()) {
39  if (!isSubset(b.variables(), allowedVars)) {
40  SMTRAT_LOG_DEBUG("smtrat.mcsat.fm", "Discarding non-univariate bound " << b);
41  continue;
42  }
43  assert(b.type() == carl::FormulaType::CONSTRAINT);
44  bounds.emplace_back(b.constraint());
45  }
46  }
47 
48  std::optional<FormulasT> res = std::nullopt;
49  // TODO add choice of Comparator to settings ...
51  res = expl;
52  return true; // stop searching for conflicts after first conflict has been found
53  });
54 
55  if (res) {
56  SMTRAT_LOG_DEBUG("smtrat.mcsat.fm", "Found conflict " << *res);
57  #ifdef SMTRAT_DEVOPTION_Statistics
58  mStatistics.explanationSuccess();
59  #endif
60  return mcsat::Explanation(FormulaT(carl::FormulaType::OR, std::move(*res)));
61  }
62  else {
63  SMTRAT_LOG_DEBUG("smtrat.mcsat.fm", "Did not find a conflict");
64  return std::nullopt;
65  }
66 }
67 
68 // Instantiations
69 template struct Explanation<DefaultSettings>;
70 template struct Explanation<IgnoreCoreSettings>;
71 
72 }
73 }
74 }
Represent the trail, i.e.
Definition: Bookkeeping.h:19
const auto & assignedVariables() const
Definition: Bookkeeping.h:37
const auto & constraints() const
Definition: Bookkeeping.h:43
const auto & model() const
Definition: Bookkeeping.h:34
int var(Lit p)
Definition: SolverTypes.h:64
bool isSubset(const carl::Variables &subset, const carl::Variables &superset)
std::variant< FormulaT, ClauseChain > Explanation
Definition: smtrat-mcsat.h:14
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::Formulas< Poly > FormulasT
Definition: types.h:39
#define SMTRAT_LOG_DEBUG(channel, msg)
Definition: logging.h:35
void generateExplanation(Callback &&callback)
std::optional< mcsat::Explanation > operator()(const mcsat::Bookkeeping &data, carl::Variable var, const FormulasT &reason, bool force_use_core) const
Definition: Explanation.cpp:9