3 * @author YOUR NAME <YOUR EMAIL ADDRESS>
6 * Created on 2016-02-23.
9 #include "NewCADModule.h"
10 #include <smtrat-cad/projection/Projection.h>
11 #include <smtrat-cad/variableordering/triangular_ordering.h>
15 template<class Settings>
16 NewCADModule<Settings>::NewCADModule(const ModuleInput* _formula, Conditionals& _conditionals, Manager* _manager):
17 Module( _formula, _conditionals, _manager ),
19 mPreprocessor(mCAD.getVariables())
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;
26 if (Settings::pp_disable_resultants) {
27 SMTRAT_LOG_DEBUG("smtrat.cad", "Disable pp.resultants from settings");
28 pps.disable_resultants = true;
32 template<class Settings>
33 NewCADModule<Settings>::~NewCADModule()
36 template<class Settings>
37 bool NewCADModule<Settings>::informCore( const FormulaT& _constraint )
39 mPolynomials.emplace_back(_constraint.constraint().lhs());
40 carl::variables(_constraint,mVariables);
41 return true; // This should be adapted according to your implementation.
44 template<class Settings>
45 void NewCADModule<Settings>::init()
49 template<class Settings>
50 bool NewCADModule<Settings>::addCore( ModuleInput::const_iterator _subformula )
52 assert(_subformula->formula().type() == carl::FormulaType::CONSTRAINT);
53 if (!Settings::force_nonincremental) {
54 addConstraint(_subformula->formula().constraint());
59 template<class Settings>
60 void NewCADModule<Settings>::removeCore( ModuleInput::const_iterator _subformula )
62 assert(_subformula->formula().type() == carl::FormulaType::CONSTRAINT);
63 if (!Settings::force_nonincremental) {
64 removeConstraint(_subformula->formula().constraint());
68 template<class Settings>
69 void NewCADModule<Settings>::updateModel() const
72 if( solverState() == SAT ) {
73 carl::carlVariables vars;
74 for (const auto& f: rReceivedFormula()) {
75 carl::variables(f.formula(),vars);
77 for (const auto var : vars) {
78 mModel.assign(var, mLastModel.at(var));
83 template<class Settings>
84 Answer NewCADModule<Settings>::checkCore()
86 if (mCAD.dim() != mVariables.size()) {
87 SMTRAT_LOG_DEBUG("smtrat.cad", "Init with " << mPolynomials);
88 mCAD.reset(cad::variable_ordering::triangular_ordering(mPolynomials));
90 #ifdef SMTRAT_DEVOPTION_Statistics
93 if (Settings::force_nonincremental) {
94 SMTRAT_LOG_DEBUG("smtrat.cad", "Enforce non-incremental behaviour");
95 removeConstraintsFromReplacer();
96 pushConstraintsToReplacer();
98 if (!mPreprocessor.preprocess()) {
99 SMTRAT_LOG_DEBUG("smtrat.cad", "Found unsat in preprocessor");
100 mInfeasibleSubsets.emplace_back(mPreprocessor.getConflict());
101 return Answer::UNSAT;
103 auto update = mPreprocessor.result(mCAD.getConstraintMap());
104 for (const auto& c: update.toAdd) {
105 mCAD.addConstraint(c);
107 for (const auto& c: update.toRemove) {
108 mCAD.removeConstraint(c);
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());
115 if (answer == Answer::UNSAT) {
116 SMTRAT_LOG_DEBUG("smtrat.cad", "Found to be unsat");
117 for (auto& mis : mInfeasibleSubsets) {
118 mPreprocessor.postprocessConflict(mis);
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);
125 mLastModel.update(mPreprocessor.model(), false);
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);
135 assert(it->second.isRAN());
136 const auto& r = it->second.asRAN();
137 if (carl::is_integer(r)) continue;
139 branchAt(v, branching_point(r), true, true, true);
140 SMTRAT_LOG_DEBUG("smtrat.cad", "Branching on " << v << " at " << branching_point(r));