SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
NewCADModule.tpp
Go to the documentation of this file.
1 /**
2  * @file NewCAD.cpp
3  * @author YOUR NAME <YOUR EMAIL ADDRESS>
4  *
5  * @version 2016-02-23
6  * Created on 2016-02-23.
7  */
8 
9 #include "NewCADModule.h"
10 #include <smtrat-cad/projection/Projection.h>
11 #include <smtrat-cad/variableordering/triangular_ordering.h>
12 
13 namespace smtrat
14 {
15  template<class Settings>
16  NewCADModule<Settings>::NewCADModule(const ModuleInput* _formula, Conditionals& _conditionals, Manager* _manager):
17  Module( _formula, _conditionals, _manager ),
18  mCAD(),
19  mPreprocessor(mCAD.getVariables())
20  {
21  auto& pps = settings::Settings::getInstance().get<cad::PreprocessorSettings>("cad-pp2");
22  if (Settings::pp_disable_variable_elimination) {
23  SMTRAT_LOG_DEBUG("smtrat.cad", "Disable pp.variable-elimination from settings");
24  pps.disable_variable_elimination = true;
25  }
26  if (Settings::pp_disable_resultants) {
27  SMTRAT_LOG_DEBUG("smtrat.cad", "Disable pp.resultants from settings");
28  pps.disable_resultants = true;
29  }
30  }
31 
32  template<class Settings>
33  NewCADModule<Settings>::~NewCADModule()
34  {}
35 
36  template<class Settings>
37  bool NewCADModule<Settings>::informCore( const FormulaT& _constraint )
38  {
39  mPolynomials.emplace_back(_constraint.constraint().lhs());
40  carl::variables(_constraint,mVariables);
41  return true; // This should be adapted according to your implementation.
42  }
43 
44  template<class Settings>
45  void NewCADModule<Settings>::init()
46  {
47  }
48 
49  template<class Settings>
50  bool NewCADModule<Settings>::addCore( ModuleInput::const_iterator _subformula )
51  {
52  assert(_subformula->formula().type() == carl::FormulaType::CONSTRAINT);
53  if (!Settings::force_nonincremental) {
54  addConstraint(_subformula->formula().constraint());
55  }
56  return true;
57  }
58 
59  template<class Settings>
60  void NewCADModule<Settings>::removeCore( ModuleInput::const_iterator _subformula )
61  {
62  assert(_subformula->formula().type() == carl::FormulaType::CONSTRAINT);
63  if (!Settings::force_nonincremental) {
64  removeConstraint(_subformula->formula().constraint());
65  }
66  }
67 
68  template<class Settings>
69  void NewCADModule<Settings>::updateModel() const
70  {
71  mModel.clear();
72  if( solverState() == SAT ) {
73  carl::carlVariables vars;
74  for (const auto& f: rReceivedFormula()) {
75  carl::variables(f.formula(),vars);
76  }
77  for (const auto var : vars) {
78  mModel.assign(var, mLastModel.at(var));
79  }
80  }
81  }
82 
83  template<class Settings>
84  Answer NewCADModule<Settings>::checkCore()
85  {
86  if (mCAD.dim() != mVariables.size()) {
87  SMTRAT_LOG_DEBUG("smtrat.cad", "Init with " << mPolynomials);
88  mCAD.reset(cad::variable_ordering::triangular_ordering(mPolynomials));
89  }
90 #ifdef SMTRAT_DEVOPTION_Statistics
91  mStatistics.called();
92 #endif
93  if (Settings::force_nonincremental) {
94  SMTRAT_LOG_DEBUG("smtrat.cad", "Enforce non-incremental behaviour");
95  removeConstraintsFromReplacer();
96  pushConstraintsToReplacer();
97  }
98  if (!mPreprocessor.preprocess()) {
99  SMTRAT_LOG_DEBUG("smtrat.cad", "Found unsat in preprocessor");
100  mInfeasibleSubsets.emplace_back(mPreprocessor.getConflict());
101  return Answer::UNSAT;
102  }
103  auto update = mPreprocessor.result(mCAD.getConstraintMap());
104  for (const auto& c: update.toAdd) {
105  mCAD.addConstraint(c);
106  }
107  for (const auto& c: update.toRemove) {
108  mCAD.removeConstraint(c);
109  }
110  SMTRAT_LOG_DEBUG("smtrat.cad", "Performing actual check");
111  auto answer = mCAD.check(mLastAssignment, mInfeasibleSubsets);
112 #ifdef SMTRAT_DEVOPTION_Statistics
113  mStatistics.currentProjectionSize(mCAD.getProjection().size());
114 #endif
115  if (answer == Answer::UNSAT) {
116  SMTRAT_LOG_DEBUG("smtrat.cad", "Found to be unsat");
117  for (auto& mis : mInfeasibleSubsets) {
118  mPreprocessor.postprocessConflict(mis);
119  }
120  SMTRAT_LOG_INFO("smtrat.cad", "Infeasible subset: " << mInfeasibleSubsets);
121  } else if (answer == Answer::SAT) {
122  for (const auto& a: mLastAssignment) {
123  mLastModel.assign(a.first, a.second);
124  }
125  mLastModel.update(mPreprocessor.model(), false);
126  }
127  if (answer == Answer::SAT && Settings::split_for_integers) {
128  for (auto v: mCAD.getVariables()) {
129  if (v.type() != carl::VariableType::VT_INT) continue;
130  auto it = mLastModel.find(v);
131  if (it == mLastModel.end()) {
132  SMTRAT_LOG_WARN("smtrat.cad", "Variable " << v << " was not found in last assignment " << mLastModel);
133  continue;
134  }
135  assert(it->second.isRAN());
136  const auto& r = it->second.asRAN();
137  if (carl::is_integer(r)) continue;
138  if (mFinalCheck) {
139  branchAt(v, branching_point(r), true, true, true);
140  SMTRAT_LOG_DEBUG("smtrat.cad", "Branching on " << v << " at " << branching_point(r));
141  answer = UNKNOWN;
142  }
143  }
144  }
145  return answer;
146  }
147 }
148 
149