3 * @author YOUR NAME <YOUR EMAIL ADDRESS>
6 * Created on 2017-11-29.
9 #include "CoCoAGBModule.h"
11 #include <carl-arith/poly/umvpoly/CoCoAAdaptor.h>
13 #include <carl-common/config.h>
20 template<class Settings>
21 CoCoAGBModule<Settings>::CoCoAGBModule(const ModuleInput* _formula, Conditionals& _conditionals, Manager* _manager):
22 Module( _formula, _conditionals, _manager )
25 template<class Settings>
26 CoCoAGBModule<Settings>::~CoCoAGBModule()
29 template<class Settings>
30 bool CoCoAGBModule<Settings>::informCore( const FormulaT& )
33 return true; // This should be adapted according to your implementation.
36 template<class Settings>
37 void CoCoAGBModule<Settings>::init()
40 template<class Settings>
41 bool CoCoAGBModule<Settings>::addCore( ModuleInput::const_iterator _subformula )
43 assert(_subformula->formula().type() == carl::FormulaType::CONSTRAINT);
44 auto p = getPoly(_subformula->formula().constraint());
46 mGBPolys.emplace(_subformula->formula().constraint(), *p);
49 addReceivedSubformulaToPassedFormula(_subformula);
54 template<class Settings>
55 void CoCoAGBModule<Settings>::removeCore( ModuleInput::const_iterator _subformula )
57 assert(_subformula->formula().type() == carl::FormulaType::CONSTRAINT);
58 auto it = mGBPolys.find(_subformula->formula().constraint());
59 if (it != mGBPolys.end()) {
65 template<class Settings>
66 void CoCoAGBModule<Settings>::updateModel() const
69 if( solverState() == Answer::SAT )
75 template<class Settings>
76 Answer CoCoAGBModule<Settings>::checkCore()
78 if (Settings::always_return_unknown) return Answer::UNKNOWN;
79 if (mGBPolys.empty()) return Answer::UNKNOWN;
80 if (mLastBasis.empty()) {
81 std::vector<Poly> polys;
82 for (const auto& p: mGBPolys) {
83 polys.emplace_back(p.second);
87 VariableOrdering vo(polys);
88 carl::CoCoAAdaptor<Poly> cocoa(polys);
89 cocoa.resetVariableOrdering(vo.getOrdering());
90 SMTRAT_LOG_DEBUG("smtrat.cocoagb", "Ordering: " << vo.getOrdering());
91 SMTRAT_LOG_DEBUG("smtrat.cocoagb", "Computing GB of " << polys);
92 mLastBasis = cocoa.GBasis(polys);
93 SMTRAT_LOG_DEBUG("smtrat.cocoagb", "-> " << mLastBasis);
94 } catch (const CoCoA::ErrorInfo& e) {
95 std::cerr << e << std::endl;
98 SMTRAT_LOG_DEBUG("smtrat.cocoagb", "Reusing basis from last call.");
101 if (mLastBasis.size() == 1 && carl::is_one(mLastBasis[0])) {
102 SMTRAT_LOG_DEBUG("smtrat.cocoagb", "Returning UNSAT");
103 generateTrivialInfeasibleSubset();
104 return Answer::UNSAT;
106 SMTRAT_LOG_DEBUG("smtrat.cocoagb", "Returning Unknown");
107 return Answer::UNKNOWN;