3 * @author YOUR NAME <YOUR EMAIL ADDRESS>
6 * Created on 2018-03-09.
9 #include "GBPPModule.h"
11 #include <carl-arith/poly/umvpoly/functions/Complexity.h>
15 template<class Settings>
16 GBPPModule<Settings>::GBPPModule(const ModuleInput* _formula, Conditionals& _conditionals, Manager* _manager):
17 PModule( _formula, _conditionals, _manager, Settings::moduleName )
19 simplifyInequalityFunction = std::bind(&GBPPModule<Settings>::simplifyInequality, this, std::placeholders::_1);
22 template<class Settings>
23 GBPPModule<Settings>::~GBPPModule()
26 template<class Settings>
27 void GBPPModule<Settings>::updateModel() const
30 if( solverState() == Answer::SAT )
36 template<class Settings>
37 Answer GBPPModule<Settings>::checkCore()
40 mEqualityComplexity = 0;
43 // Extract top-level Equalities
44 for (const auto& f: rReceivedFormula()) {
45 if (f.formula().type() == carl::FormulaType::CONSTRAINT) {
46 if (f.formula().constraint().relation() == carl::Relation::EQ) {
47 SMTRAT_LOG_DEBUG("smtrat.gbpp", "Found equality " << f.formula().constraint());
48 mEqualities.emplace(f.formula().constraint());
49 mEqualityComplexity += carl::complexity(f.formula().constraint().lhs());
55 for (const auto& eq: mEqualities) {
56 SMTRAT_LOG_DEBUG("smtrat.gbpp", "Adding to Gröbner Basis: " << gpoly(eq.constraint().lhs().normalize()));
57 mBasis.addPolynomial(gpoly(eq.constraint().lhs().normalize()));
60 SMTRAT_LOG_DEBUG("smtrat.gbpp", "Constructed Gröbner Basis:" << std::endl << mBasis.getIdeal());
62 // Simplify all inequalities w.r.t. GBasis and forward to backend
63 for (const auto& f: rReceivedFormula()) {
64 if (mEqualities.find(f.formula()) != mEqualities.end()) continue;
65 auto res = carl::visit_result(f.formula(), simplifyInequalityFunction);
67 if (res != f.formula()) {
68 SMTRAT_LOG_INFO("smtrat.gbpp", "Reduced " << f.formula() << " to " << res);
71 addSubformulaToPassedFormula(res, f.formula());
75 // Forward basis to backend
76 std::size_t basisComplexity = 0;
77 for (const auto& p: mBasis.getIdeal().getGenerators()) {
78 basisComplexity += carl::complexity(p);
80 if (basisComplexity >= mEqualityComplexity) {
81 for (const auto& f: mEqualities) {
82 addSubformulaToPassedFormula(f, f);
85 for (const auto& p: mBasis.getIdeal().getGenerators()) {
86 addSubformulaToPassedFormula(FormulaT(ConstraintT(Poly(p), carl::Relation::EQ)));
90 Answer ans = runBackends();
92 generateTrivialInfeasibleSubset();
97 template<typename Settings>
98 FormulaT GBPPModule<Settings>::simplifyInequality(const FormulaT& formula) const {
99 if (formula.type() != carl::FormulaType::CONSTRAINT) return formula;
100 // This case should be catched by ESModule...
101 if (mEqualities.find(formula) != mEqualities.end()) return formula;
102 const auto& c = formula.constraint();
104 typename Settings::Reductor reductor(mBasis.getIdeal(), gpoly(c.lhs()));
105 auto reduced = reductor.fullReduce();
106 SMTRAT_LOG_DEBUG("smtrat.gbpp", "Reduced " << c.lhs() << " to " << reduced);
108 if (reduced.nr_terms() >= c.lhs().nr_terms()) return formula;
109 return FormulaT(ConstraintT(Poly(reduced), c.relation()));