SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
preprocessor.cpp
Go to the documentation of this file.
1 #include "preprocessor.h"
2 
3 #include "config.h"
5 
6 #ifdef CLI_ENABLE_PREPROCESSOR
7 
8 #include "execute_smtlib.h"
9 #include "../parser/InstructionHandler.h"
10 
11 #include <carl-io/SMTLIBStream.h>
13 
14 namespace smtrat {
15 namespace preprocessor {
16 
17 class PPStrategy: public Manager {
18 public:
19  PPStrategy(): Manager() {
20  setStrategy({
21  addBackend<FPPModule<FPPSettings1>>()
22  });
23  }
24 };
25 
26 
27 class Preprocessor : public smtrat::parser::InstructionHandler {
28 public:
29  PPStrategy solver;
30  carl::io::SMTLIBStream mOutput;
31  void add(const smtrat::FormulaT& f) {
32  solver.add(f);
33  }
34  void addSoft(const smtrat::FormulaT& f, Rational, const std::string&) {
35  solver.add(f);
36  }
37  void annotateName(const smtrat::FormulaT&, const std::string&) {
38  SMTRAT_LOG_WARN("smtrat.preprocessor", "Preprocessor does not supprt named annotations.")
39  }
40  void check() {
41  solver.check();
42  carl::carlVariables vars;
43  carl::variables(solver.getInputSimplified().second,vars);
44  mOutput.declare(vars);
45  mOutput.assertFormula(solver.getInputSimplified().second);
46  mOutput << "(check-sat)" << std::endl;
47  }
48  void declareFun(const carl::Variable&) {}
49  void declareSort(const std::string&, const unsigned&) {}
50  void defineSort(const std::string&, const std::vector<std::string>&, const carl::Sort&) {}
51  void qe() {}
52  void exit() {
53  mOutput << "(exit)" << std::endl;
54  }
55  void getAssertions() {}
56  void getAllModels() {
57  mOutput << "(get-all-models)" << std::endl;
58  }
59  void getAssignment() {}
60  void getModel() {
61  mOutput << "(get-model)" << std::endl;
62  }
63  void getObjectives() {}
64  void getProof() {}
65  void getUnsatCore() {}
66  void getValue(const std::vector<carl::Variable>&) {}
67  void addObjective(const smtrat::Poly&, smtrat::parser::OptimizationType) {}
68  void pop(std::size_t n) {
69 
70  solver.pop(n);
71  mOutput << "(pop " << n << ")" << std::endl;
72  }
73  void push(std::size_t n) {
74  for (; n > 0; n--) this->solver.push();
75  mOutput << "(push " << n << ")" << std::endl;
76  }
77  void reset() {
78  solver.reset();
79  mOutput << "(reset)" << std::endl;
80  }
81  void resetAssertions() {
82  auto logic = solver.logic();
83  solver.reset();
84  solver.rLogic() = logic;
85  mOutput << "(reset-assertions)" << std::endl;
86  }
87  void setLogic(const carl::Logic& logic) {
88  solver.rLogic() = logic;
89  mOutput << "(set-logic " << logic << ")" << std::endl;
90  }
91  int getExitCode() const {
92  return 0;
93  }
94 };
95 }
96 
97 int preprocess_file(const std::string& filename, const std::string& outfile) {
98  auto e = preprocessor::Preprocessor();
99  int exitCode = executeFile(filename, e);
100 
101  if (outfile.empty()) {
102  e.regular() << e.mOutput;
103  } else {
104  std::ofstream file(outfile);
105  file << e.mOutput;
106  file.close();
107  }
108  if (smtrat::settings_solver().print_model) {
109  e.solver.printAssignment();
110  }
111 
112  return exitCode;
113 }
114 
115 }
116 
117 #else
118 
119 namespace smtrat {
120 
121 int preprocess_file(const std::string&, const std::string&) {
122  SMTRAT_LOG_ERROR("smtrat", "This version of SMT-RAT was compiled without support for stand-alone preprocessing. Please enable it by setting the corresponding CMake option.");
123  return 0;
124 }
125 
126 }
127 
128 #endif
std::optional< FormulaT > qe(const FormulaT &input)
Definition: qe.cpp:14
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:43
Class to create the formulas for axioms.
carl::Formula< Poly > FormulaT
Definition: types.h:37
carl::MultivariatePolynomial< Rational > Poly
Definition: types.h:25
int preprocess_file(const std::string &, const std::string &)
Loads the smt2 file specified in filename and runs the preprocessing strategy.
const auto & settings_solver()
Definition: Settings.h:104
mpq_class Rational
Definition: types.h:19
int executeFile(const std::string &pathToInputFile, Executor &e)
Parse the file and save it in formula.
#define SMTRAT_LOG_WARN(channel, msg)
Definition: logging.h:33
#define SMTRAT_LOG_ERROR(channel, msg)
Definition: logging.h:32