SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
FPPModule.tpp
Go to the documentation of this file.
1 /**
2  * @file FPPModule.tpp
3  * @author YOUR NAME <YOUR EMAIL ADDRESS>
4  *
5  * @version 2015-09-10
6  * Created on 2015-09-10.
7  */
8 
9 #include "FPPModule.h"
10 
11 namespace smtrat
12 {
13  template<class Settings>
14  FPPModule<Settings>::FPPModule( const ModuleInput* _formula, Conditionals& _conditionals, Manager* _manager ):
15  PModule( _formula, _conditionals, _manager, Settings::moduleName )
16  {}
17 
18  template<class Settings>
19  FPPModule<Settings>::~FPPModule()
20  {}
21 
22  template<class Settings>
23  bool FPPModule<Settings>::informCore( const FormulaT& _constraint )
24  {
25  return mPreprocessor.inform( _constraint );
26  }
27 
28  template<class Settings>
29  void FPPModule<Settings>::init()
30  {
31  }
32 
33  template<class Settings>
34  bool FPPModule<Settings>::addCore( ModuleInput::const_iterator )
35  {
36  return true;
37  }
38 
39  template<class Settings>
40  void FPPModule<Settings>::removeCore( ModuleInput::const_iterator )
41  {
42  }
43 
44  template<class Settings>
45  void FPPModule<Settings>::updateModel() const
46  {
47  mModel.clear();
48  if( solverState() != UNSAT )
49  {
50  getBackendsModel();
51  mModel.update(mPartialModel);
52  excludeNotReceivedVariablesFromModel();
53  }
54  }
55 
56  template<class Settings>
57  Answer FPPModule<Settings>::checkCore()
58  {
59  // set the objective for all preprocessing modules. Each module has to check
60  // whether it is sound to perform the preprocessing on optimizing solver calls.
61  mPreprocessor.setObjectiveVariable(objective());
62 
63  std::size_t iterations = 0;
64  Answer answer = UNKNOWN;
65  FormulaT formulaBeforePreprocessing = FormulaT(rReceivedFormula());
66  mPartialModel.clear();
67  while (Settings::max_iterations < 0 || iterations < (std::size_t)Settings::max_iterations) {
68  iterations++;
69  // call the preprocessing on the current formula
70  mPreprocessor.push();
71  mPreprocessor.add(formulaBeforePreprocessing);
72  answer = mPreprocessor.check(mFullCheck);
73  // preprocessing detects satisfiability or unsatisfiability
74  if (answer != UNKNOWN) {
75  mPreprocessor.pop();
76  break;
77  }
78  SMTRAT_LOG_INFO("smtrat.fpp", "Retrieving simplified input and partial model...");
79  std::pair<bool,FormulaT> res = mPreprocessor.getInputSimplified();
80  SMTRAT_LOG_INFO("smtrat.fpp", "Curent model:" << mPartialModel);
81  SMTRAT_LOG_INFO("smtrat.fpp", "Preprocessor model:" << mPreprocessor.model());
82  mPartialModel.update(mPreprocessor.model());
83  SMTRAT_LOG_INFO("smtrat.fpp", "Backtracking");
84  mPreprocessor.pop();
85  if (res.first && (formulaBeforePreprocessing != res.second)) {
86  SMTRAT_LOG_INFO("smtrat.fpp", "Formula has been simplified from\n\t" << formulaBeforePreprocessing << std::endl << "to\n\t" << res.second);
87  SMTRAT_LOG_INFO("smtrat.fpp", "Current partial model:" << std::endl << mPartialModel);
88  assert(formulaBeforePreprocessing != res.second);
89  mFormulaAfterPreprocessing = res.second;
90  }
91  else {
92  mFormulaAfterPreprocessing = formulaBeforePreprocessing;
93  break;
94  }
95  // after preprocessing is before preprocessing
96  formulaBeforePreprocessing = mFormulaAfterPreprocessing;
97  }
98 
99  if (answer == UNKNOWN) {
100  // run the backends on the fix point of the iterative application of preprocessing
101  // TODO: make this incremental
102  SMTRAT_LOG_INFO("smtrat.fpp", "Calling backend with\n\t" << mFormulaAfterPreprocessing);
103  clearPassedFormula();
104  addSubformulaToPassedFormula(mFormulaAfterPreprocessing);
105  answer = runBackends();
106  }
107  // obtain an infeasible subset, if the received formula is unsatisfiable
108  if (answer == UNSAT) {
109  generateTrivialInfeasibleSubset(); // TODO: compute a better infeasible subset
110  }
111  return answer;
112  }
113 }
114 
115