SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
cnf_conversion.cpp
Go to the documentation of this file.
1 #include "cnf_conversion.h"
2 
3 #include "config.h"
5 
6 #ifdef CLI_ENABLE_CNF_CONVERSION
7 
8 #include "parser_smtlib_utils.h"
9 #include "execute_smtlib.h"
10 
11 #include <carl-formula/formula/functions/CNF.h>
12 #include <carl-io/DIMACSExporter.h>
13 #include <carl-io/SMTLIBStream.h>
14 
15 namespace smtrat {
16 
17 int convert_to_cnf_dimacs(const std::string& filename, const std::string& outfile) {
18  auto e = parseformula::FormulaCollector();
19  executeFile(filename, e);
20 
21  carl::io::DIMACSExporter<Poly> exporter;
22  exporter(carl::to_cnf(e.getFormula()));
23 
24  if (outfile.empty()) {
25  e.regular() << exporter;
26  } else {
27  std::ofstream file(outfile);
28  file << exporter;
29  file.close();
30  }
31 
32  return 0;
33 }
34 
35 int convert_to_cnf_smtlib(const std::string& filename, const std::string& outfile) {
36  auto e = parseformula::FormulaCollector();
37  executeFile(filename, e);
38 
39  auto f_in_cnf = carl::to_cnf(e.getFormula());
40 
41  if (outfile.empty()) {
42  e.regular() << carl::io::outputSMTLIB(e.getLogic(), { f_in_cnf });
43  } else {
44  std::ofstream file(outfile);
45  file << carl::io::outputSMTLIB(e.getLogic(), { f_in_cnf });
46  file.close();
47  }
48 
49  return 0;
50 }
51 
52 }
53 
54 #else
55 
56 namespace smtrat {
57 
58 int convert_to_cnf_dimacs(const std::string&, const std::string&) {
59  SMTRAT_LOG_ERROR("smtrat", "This version of SMT-RAT was compiled without support for stand-alone CNF conversion. Please enable it by setting the corresponding CMake option.");
60  return 0;
61 }
62 
63 int convert_to_cnf_smtlib(const std::string&, const std::string&) {
64  SMTRAT_LOG_ERROR("smtrat", "This version of SMT-RAT was compiled without support for stand-alone CNF conversion. Please enable it by setting the corresponding CMake option.");
65  return 0;
66 }
67 
68 }
69 
70 #endif
Class to create the formulas for axioms.
int convert_to_cnf_dimacs(const std::string &, const std::string &)
int convert_to_cnf_smtlib(const std::string &, const std::string &)
int executeFile(const std::string &pathToInputFile, Executor &e)
Parse the file and save it in formula.
#define SMTRAT_LOG_ERROR(channel, msg)
Definition: logging.h:32