SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
AssignmentFinder.cpp
Go to the documentation of this file.
1 #include "AssignmentFinder.h"
2 
4 //#include "AssignmentFinder_ctx.h"
5 
6 namespace smtrat {
7 namespace mcsat {
8 namespace arithmetic {
9 
10 std::optional<AssignmentOrConflict> AssignmentFinder::operator()(const mcsat::Bookkeeping& data, carl::Variable var) const {
11  SMTRAT_LOG_DEBUG("smtrat.mcsat.arithmetic", "Looking for an assignment for " << var);
12  #ifdef SMTRAT_DEVOPTION_Statistics
13  mStatistics.called();
14  #endif
15  // auto var_order = data.assignedVariables();
16  // var_order.push_back(var);
17  // AssignmentFinder_ctx af(var_order, var, data.model());
18  AssignmentFinder_detail af(var, data.model());
19  FormulasT conflict;
20  for (const auto& c: data.constraints()) {
21  if (!active(data, c)) {
22  SMTRAT_LOG_TRACE("smtrat.mcsat.arithmetic", "Skipping inactive Constraint " << c);
23  continue;
24  }
25  assert(c.type() == carl::FormulaType::CONSTRAINT);
26  SMTRAT_LOG_TRACE("smtrat.mcsat.arithmetic", "Adding Constraint " << c);
27  if(!af.addConstraint(c)){
28  conflict.push_back(c);
29  SMTRAT_LOG_DEBUG("smtrat.mcsat.arithmetic", "No Assignment, built conflicting core " << conflict << " under model " << data.model());
30  return AssignmentOrConflict(conflict);
31  }
32  }
33  for (const auto& b: data.mvBounds()) {
34  if (!active(data, b)) {
35  SMTRAT_LOG_TRACE("smtrat.mcsat.arithmetic", "Skipping inactive MVBound " << b);
36  continue;
37  }
38  SMTRAT_LOG_TRACE("smtrat.mcsat.arithmetic", "Adding MVBound " << b);
39  if (!af.addMVBound(b)) {
40  conflict.push_back(b);
41  SMTRAT_LOG_DEBUG("smtrat.mcsat.arithmetic", "No Assignment, built conflicting core " << conflict << " under model " << data.model());
42  return AssignmentOrConflict(conflict);
43  }
44  }
45  SMTRAT_LOG_DEBUG("smtrat.mcsat.arithmetic", "Calling AssignmentFinder...");
46  #ifdef SMTRAT_DEVOPTION_Statistics
47  mStatistics.success();
48  #endif
49  return af.findAssignment();
50 }
51 
52 bool AssignmentFinder::active(const mcsat::Bookkeeping& data, const FormulaT& f) const {
53  if(f.type() != carl::FormulaType::VARCOMPARE)
54  return true;
55 
56  const auto& val = f.variable_comparison().value();
57  if (std::holds_alternative<VariableComparisonT::RAN>(val)) {
58  return true;
59  } else {
60  if (data.model().find(f.variable_comparison().var()) == data.model().end()) {
61  return true;
62  } else {
63  const auto& mvroot = std::get<MultivariateRootT>(val);
64  auto vars = carl::variables(mvroot.poly()).as_set();
65  vars.erase(mvroot.var());
66  for (auto iter = data.assignedVariables().begin(); iter != data.assignedVariables().end(); iter++) {
67  if (*iter == f.variable_comparison().var()) {
68  break;
69  }
70  vars.erase(*iter);
71  }
72  return vars.size() == 0;
73  }
74  }
75  }
76 
77 }
78 }
79 }
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
const auto & mvBounds() const
Definition: Bookkeeping.h:46
int var(Lit p)
Definition: SolverTypes.h:64
std::variant< ModelValues, FormulasT > AssignmentOrConflict
Definition: smtrat-mcsat.h:13
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:43
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
bool active(const mcsat::Bookkeeping &data, const FormulaT &f) const
std::optional< AssignmentOrConflict > operator()(const mcsat::Bookkeeping &data, carl::Variable var) const