SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
CoCoAGBModule.tpp
Go to the documentation of this file.
1 /**
2  * @file CoCoAGB.cpp
3  * @author YOUR NAME <YOUR EMAIL ADDRESS>
4  *
5  * @version 2017-11-29
6  * Created on 2017-11-29.
7  */
8 
9 #include "CoCoAGBModule.h"
10 
11 #include <carl-arith/poly/umvpoly/CoCoAAdaptor.h>
12 
13 #include <carl-common/config.h>
14 
15 
16 #ifdef USE_COCOA
17 
18 namespace smtrat
19 {
20  template<class Settings>
21  CoCoAGBModule<Settings>::CoCoAGBModule(const ModuleInput* _formula, Conditionals& _conditionals, Manager* _manager):
22  Module( _formula, _conditionals, _manager )
23  {}
24 
25  template<class Settings>
26  CoCoAGBModule<Settings>::~CoCoAGBModule()
27  {}
28 
29  template<class Settings>
30  bool CoCoAGBModule<Settings>::informCore( const FormulaT& )
31  {
32  // Your code.
33  return true; // This should be adapted according to your implementation.
34  }
35 
36  template<class Settings>
37  void CoCoAGBModule<Settings>::init()
38  {}
39 
40  template<class Settings>
41  bool CoCoAGBModule<Settings>::addCore( ModuleInput::const_iterator _subformula )
42  {
43  assert(_subformula->formula().type() == carl::FormulaType::CONSTRAINT);
44  auto p = getPoly(_subformula->formula().constraint());
45  if (p) {
46  mGBPolys.emplace(_subformula->formula().constraint(), *p);
47  mLastBasis.clear();
48  } else {
49  addReceivedSubformulaToPassedFormula(_subformula);
50  }
51  return true;
52  }
53 
54  template<class Settings>
55  void CoCoAGBModule<Settings>::removeCore( ModuleInput::const_iterator _subformula )
56  {
57  assert(_subformula->formula().type() == carl::FormulaType::CONSTRAINT);
58  auto it = mGBPolys.find(_subformula->formula().constraint());
59  if (it != mGBPolys.end()) {
60  mGBPolys.erase(it);
61  mLastBasis.clear();
62  }
63  }
64 
65  template<class Settings>
66  void CoCoAGBModule<Settings>::updateModel() const
67  {
68  mModel.clear();
69  if( solverState() == Answer::SAT )
70  {
71  // Your code.
72  }
73  }
74 
75  template<class Settings>
76  Answer CoCoAGBModule<Settings>::checkCore()
77  {
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);
84  };
85 
86  try {
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;
96  }
97  } else {
98  SMTRAT_LOG_DEBUG("smtrat.cocoagb", "Reusing basis from last call.");
99  }
100 
101  if (mLastBasis.size() == 1 && carl::is_one(mLastBasis[0])) {
102  SMTRAT_LOG_DEBUG("smtrat.cocoagb", "Returning UNSAT");
103  generateTrivialInfeasibleSubset();
104  return Answer::UNSAT;
105  }
106  SMTRAT_LOG_DEBUG("smtrat.cocoagb", "Returning Unknown");
107  return Answer::UNKNOWN;
108  }
109 }
110 
111 #endif
112 
113