SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
EMModule.tpp
Go to the documentation of this file.
1 /**
2  * @file EMModule.tpp
3  * @author Gereon Kremer <gereon.kremer@cs.rwth-aachen.de>
4  * @author Florian Corzilius <corzilius@cs.rwth-aachen.de>
5  *
6  * @version 2015-09-10
7  * Created on 2015-09-10.
8  */
9 
10 #include "EMModule.h"
11 
12 namespace smtrat
13 {
14  template<class Settings>
15  EMModule<Settings>::EMModule( const ModuleInput* _formula, Conditionals& _conditionals, Manager* _manager ):
16  PModule( _formula, _conditionals, _manager, Settings::moduleName )
17  {
18  eliminateEquationFunction = std::bind(&EMModule<Settings>::eliminateEquation, this, std::placeholders::_1);
19  }
20 
21  template<class Settings>
22  EMModule<Settings>::~EMModule()
23  {}
24 
25  template<class Settings>
26  Answer EMModule<Settings>::checkCore()
27  {
28  auto receivedFormula = firstUncheckedReceivedSubformula();
29  while (receivedFormula != rReceivedFormula().end()) {
30  FormulaT formula = receivedFormula->formula();
31  if (receivedFormula->formula().property_holds(carl::PROP_CONTAINS_NONLINEAR_POLYNOMIAL)) {
32  formula = carl::visit_result(receivedFormula->formula(), eliminateEquationFunction);
33  }
34  if (formula.is_false()) {
35  receivedFormulasAsInfeasibleSubset(receivedFormula);
36  return UNSAT;
37  }
38  if (!formula.is_true()) {
39  addSubformulaToPassedFormula(formula, receivedFormula->formula());
40  }
41  ++receivedFormula;
42  }
43  Answer ans = runBackends();
44  if (ans == UNSAT)
45  getInfeasibleSubsets();
46  return ans;
47  }
48 
49  template<typename Settings>
50  FormulaT EMModule<Settings>::eliminateEquation(const FormulaT& formula) {
51  if (formula.type() != carl::FormulaType::CONSTRAINT) return formula;
52  carl::Relation rel = formula.constraint().relation();
53  switch (rel) {
54  case carl::Relation::EQ:
55  case carl::Relation::NEQ: {
56  auto& factors = formula.constraint().lhs_factorization();
57  FormulasT res;
58  for (const auto& factor: factors) {
59  res.emplace_back(factor.first, rel);
60  }
61  carl::FormulaType ft = (rel == carl::Relation::EQ) ? carl::FormulaType::OR : carl::FormulaType::AND;
62  FormulaT result(ft, std::move(res));
63  if (result != formula) {
64  SMTRAT_LOG_INFO("smtrat.em", "Translated\n\t" << formula << "\nto\n\t" << result);
65  }
66  return result;
67  }
68  default:
69  return formula;
70  }
71  }
72 }
73 
74