SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
AssignmentFinder.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "AssignmentFinder_SMT.h"
4 #include "SMTAFStatistics.h"
5 
8 
9 #include <variant>
10 
11 namespace smtrat {
12 namespace mcsat {
13 namespace smtaf {
14 
15 template<class Settings>
17 
18 #ifdef SMTRAT_DEVOPTION_Statistics
19  SMTAFStatistics& mStatistics = statistics_get<SMTAFStatistics>("mcsat-assignment-smt");
20 #endif
21 
22  std::optional<AssignmentOrConflict> operator()(const mcsat::Bookkeeping& data, carl::Variable var) const {
23  SMTRAT_LOG_DEBUG("smtrat.mcsat.smtaf", "Looking for an assignment for " << var << " with assignAllVariables = " << Settings::assignAllVariables);
24 
25  #ifdef SMTRAT_DEVOPTION_Statistics
26  mStatistics.called();
27  #endif
28 
29  /*
30  VariablePos varPos = std::find(data.variableOrder().begin(), data.variableOrder().end(), var);
31  VariablePos varPosEnd = varPos;
32  for (int i = 0; i < Settings::lookahead && varPosEnd != data.variableOrder().end(); i++) ++varPosEnd;
33  */
34  std::vector<carl::Variable> varsToAssign;
35  if (Settings::assignAllVariables) {
36  carl::Variables unassignedVars(data.variables());
37  for (const auto& v : data.assignedVariables()) {
38  unassignedVars.erase(v);
39  }
40  assert(unassignedVars.find(var) != unassignedVars.end());
41  varsToAssign.insert(varsToAssign.begin(), unassignedVars.begin(), unassignedVars.end());
42  } else {
43  varsToAssign.push_back(var);
44  }
45  VariablePos varPos = std::find(varsToAssign.begin(), varsToAssign.end(), var);
46  assert(varPos != varsToAssign.end());
47  VariablePos varPosEnd = varsToAssign.end();
48 
49  assert(varPos != varPosEnd);
50  AssignmentFinder_SMT af(std::make_pair(varPos, varPosEnd), data.model());
51 
52  for (const auto& c: data.constraints()) {
53  SMTRAT_LOG_TRACE("smtrat.mcsat.smtaf", "Adding Constraint " << c);
54  boost::tribool res = af.addConstraint(c);
55  if (indeterminate(res)) {
56  SMTRAT_LOG_TRACE("smtrat.mcsat.smtaf", "Constraint " << c << " cannot be handled!");
57  return std::nullopt;
58  } else if(!res){
59  SMTRAT_LOG_DEBUG("smtrat.mcsat.smtaf", "No Assignment, built conflicting core " << c << " under model " << data.model());
60  return AssignmentOrConflict(FormulasT({c}));
61  }
62  }
63 
64  for (const auto& c: data.mvBounds()) {
65  SMTRAT_LOG_TRACE("smtrat.mcsat.smtaf", "Adding MVBound " << c);
66  boost::tribool res = af.addMVBound(c);
67  if (indeterminate(res)) {
68  SMTRAT_LOG_TRACE("smtrat.mcsat.smtaf", "MVBound " << c << " cannot be handled!");
69  return std::nullopt;
70  } else if(!res){
71  SMTRAT_LOG_DEBUG("smtrat.mcsat.smtaf", "No Assignment, built conflicting core " << c << " under model " << data.model());
72  return AssignmentOrConflict(FormulasT({c}));
73  }
74  }
75 
76  SMTRAT_LOG_DEBUG("smtrat.mcsat.smtaf", "Calling AssignmentFinder...");
77  std::optional<AssignmentOrConflict> result;
78  if (Settings::advance_level_by_level) {
79  result = af.findAssignment();
80  } else {
81  result = af.findAssignment(varPosEnd);
82  }
83  #ifdef SMTRAT_DEVOPTION_Statistics
84  if (result) {
85  mStatistics.success();
86  }
87  #endif
88  return result;
89  assert(false);
90  }
91 
92  bool active(const mcsat::Bookkeeping&, const FormulaT&) const {
93  return true;
94  }
95 };
96 
98  static constexpr unsigned int assignAllVariables = true;
99 
100  /**
101  * If set to true, a conflict on the lowest possible level is returned.
102  *
103  * Got more or less irrelevant as unassigned variables are not ordered
104  * anymore.
105  */
106  static constexpr bool advance_level_by_level = false;
107 };
108 
109 }
110 }
111 }
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 & variables() const
Definition: Bookkeeping.h:49
const auto & model() const
Definition: Bookkeeping.h:34
const auto & mvBounds() const
Definition: Bookkeeping.h:46
boost::tribool addConstraint(const FormulaT &f)
std::optional< AssignmentOrConflict > findAssignment(const VariablePos excludeVar) const
boost::tribool addMVBound(const FormulaT &f)
int var(Lit p)
Definition: SolverTypes.h:64
static bool find(V &ts, const T &t)
Definition: Alg.h:47
std::vector< carl::Variable >::const_iterator VariablePos
std::variant< ModelValues, FormulasT > AssignmentOrConflict
Definition: smtrat-mcsat.h:13
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_TRACE(channel, msg)
Definition: logging.h:36
#define SMTRAT_LOG_DEBUG(channel, msg)
Definition: logging.h:35
std::optional< AssignmentOrConflict > operator()(const mcsat::Bookkeeping &data, carl::Variable var) const
bool active(const mcsat::Bookkeeping &, const FormulaT &) const
static constexpr bool advance_level_by_level
If set to true, a conflict on the lowest possible level is returned.
static constexpr unsigned int assignAllVariables