SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
smtratSolver.cpp
Go to the documentation of this file.
1 /**
2  * @file smtratSolver.cpp
3  * @author Florian Corzilius
4  * @author Sebastian Junges
5  *
6  * Created on May 04, 2012, 2:40 PM
7  */
8 
10 
11 #include <iostream>
12 #include <fstream>
14 #include "ExitCodes.h"
15 
16 #include "config.h"
18 
19 #ifndef __WIN
20 #include <sys/resource.h>
21 #endif
22 
23 #ifdef SMTRAT_DEVOPTION_Statistics
24 #include <carl-statistics/StatisticsCollector.h>
25 #include <carl-statistics/StatisticsPrinter.h>
27 #endif //SMTRAT_DEVOPTION_Statistics
28 
29 #ifdef SMTRAT_DEVOPTION_Validation
32 #endif //SMTRAT_DEVOPTION_Validation
33 
34 
37 
38 #include "handle_options.h"
39 #include "parser/ParserWrapper.h"
40 #include "parser/ParserSettings.h"
41 #include <carl-io/SMTLIBStream.h>
42 #include <carl-logging/logging-internals.h>
43 #include "tools/config.h"
44 #include "tools/cnf_conversion.h"
45 #include "tools/execute_smtlib.h"
46 #include "tools/Executor.h"
47 #include "tools/formula_analyzer.h"
48 #include "tools/parser_dimacs.h"
49 #include "tools/parser_opb.h"
50 #include "tools/parser_smtlib.h"
51 #include "tools/preprocessor.h"
52 
53 
55 #ifdef SMTRAT_DEVOPTION_Statistics
56  carl::statistics::StatisticsCollector::getInstance().collect();
57  if (smtrat::settings_statistics().print_as_smtlib) {
58  std::cout << carl::statistics::statistics_as_smtlib() << std::endl;
59  }
60  if (smtrat::settings_statistics().export_as_xml) {
61  carl::statistics::statistics_to_xml_file(smtrat::settings_statistics().xml_filename);
62  }
63 #endif
64 }
65 
67 #ifdef SMTRAT_DEVOPTION_Validation
68  if (smtrat::settings_validation().export_as_smtlib) {
70  }
71 #endif
72 }
73 
74 void setup_logging() {
75 #ifdef LOGGING
76  if (!carl::logging::logger().has("smtrat")) {
77  carl::logging::logger().configure("smtrat", "smtrat.log");
78  }
79  if (!carl::logging::logger().has("stdout")) {
80  carl::logging::logger().configure("stdout", std::cout);
81  }
82  //carl::logging::logger().formatter("stdout")->printInformation = false;
83  carl::logging::logger().filter("smtrat")
84  ("smtrat", carl::logging::LogLevel::LVL_INFO)
85  ;
86  carl::logging::logger().filter("stdout")
87  ("smtrat", carl::logging::LogLevel::LVL_DEBUG)
88  ("smtrat.module", carl::logging::LogLevel::LVL_DEBUG)
89  ("smtrat.parser", carl::logging::LogLevel::LVL_INFO)
90  ("smtrat.strategygraph", carl::logging::LogLevel::LVL_INFO)
91  // ("smtrat.covering_ng", carl::logging::LogLevel::LVL_TRACE)
92  // ("smtrat.cadcells", carl::logging::LogLevel::LVL_TRACE)
93  // ("smtrat.mcsat.onecell", carl::logging::LogLevel::LVL_TRACE)
94  ;
95  carl::logging::logger().formatter("stdout")->printInformation = true;
96 #endif
97 }
98 
99 void signal_handler(int) {
101  std::quick_exit(143);
102 }
103 
104 int main( int argc, char* argv[] )
105 {
106  setup_logging();
107  SMTRAT_LOG_DEBUG("smtrat", "Starting smtrat.");
108 
109  auto& parser = smtrat::SettingsParser::getInstance();
111  #ifdef SMTRAT_DEVOPTION_Statistics
113  #endif
114  #ifdef SMTRAT_DEVOPTION_Validation
116  #endif
117  #ifdef CLI_ENABLE_ANALYZER
119  #endif
120  smtrat::SettingsComponents::getInstance().add_to_parser(parser);
121  parser.finalize();
122  parser.parse_options(argc, argv);
123 
124  {
125  // handle easy options of CoreSettings
126  int basic_exitcode = smtrat::handle_basic_options(parser);
127  if (basic_exitcode != SMTRAT_EXIT_UNDEFINED) {
128  return basic_exitcode;
129  }
130  }
131 
132  int exitCode = 0;
133 
135  exitCode = smtrat::preprocess_file(smtrat::settings_parser().input_file, smtrat::settings_solver().preprocess_output_file);
136  } else if (smtrat::settings_analyzer().enabled) {
137  exitCode = smtrat::analyze_file(smtrat::settings_parser().input_file);
139  exitCode = smtrat::convert_to_cnf_dimacs(smtrat::settings_parser().input_file, smtrat::settings_solver().preprocess_output_file);
141  exitCode = smtrat::convert_to_cnf_smtlib(smtrat::settings_parser().input_file, smtrat::settings_solver().preprocess_output_file);
142  } else {
143  SMTRAT_LOG_INFO("smtrat", "Constructing strategy.");
144 
145  CMakeStrategySolver strategy;
146 
147  if (smtrat::settings_core().show_strategy) {
148  strategy.printStrategyGraph();
149  }
150  if (smtrat::settings_parser().read_dimacs) {
151  exitCode = smtrat::run_dimacs_file(strategy, smtrat::settings_parser().input_file);
152  } else if (smtrat::settings_parser().read_opb) {
153  exitCode = smtrat::run_opb_file(strategy, smtrat::settings_parser().input_file);
154  } else {
155  // Parse input.
156  std::signal(SIGTERM, &signal_handler);
157  smtrat::resource::Limiter::getInstance().setTimeoutHandler(&print_statistics);
158  try {
159 
160  auto e = smtrat::Executor<CMakeStrategySolver>(strategy);
161  exitCode = smtrat::executeFile(smtrat::settings_parser().input_file, e);
162 
163  if (is_sat(e.lastAnswer)) {
164  if (smtrat::settings_solver().print_all_models) {
165  strategy.printAllAssignments(std::cout);
166  } else if (smtrat::settings_solver().print_model) {
167  strategy.printAssignment();
168  }
169  }
170 
171  } catch (const std::bad_alloc& e) {
172  std::raise(ENOMEM);
173  }
174  }
175  }
176 
179 
180  return exitCode;
181 }
constexpr int SMTRAT_EXIT_UNDEFINED
Definition: ExitCodes.h:10
void registerAnalyzerSettings(T &parser)
Definition: settings.h:19
FormulaT preprocess(const FormulaT &f)
void registerParserSettings(T &parser)
void registerStatisticsSettings(T &parser)
void validation_formulas_to_smtlib_file(const std::string &filename)
void registerValidationSettings(T &parser)
const auto & settings_validation()
int handle_basic_options(const SettingsParser &parser)
bool is_sat(Answer a)
Definition: types.h:58
const auto & settings_core()
Definition: Settings.h:100
int preprocess_file(const std::string &, const std::string &)
Loads the smt2 file specified in filename and runs the preprocessing strategy.
int convert_to_cnf_dimacs(const std::string &, const std::string &)
int analyze_file(const std::string &)
int convert_to_cnf_smtlib(const std::string &, const std::string &)
const auto & settings_solver()
Definition: Settings.h:104
int executeFile(const std::string &pathToInputFile, Executor &e)
Parse the file and save it in formula.
const auto & settings_analyzer()
Definition: settings.h:33
int run_dimacs_file(Strategy &, const std::string &)
Definition: parser_dimacs.h:51
int run_opb_file(Strategy &, const std::string &)
Definition: parser_opb.h:72
const auto & settings_parser()
const auto & settings_statistics()
#define SMTRAT_LOG_INFO(channel, msg)
Definition: logging.h:34
#define SMTRAT_LOG_DEBUG(channel, msg)
Definition: logging.h:35
#define CMakeStrategySolver
Definition: config.h:4
int main(int argc, char *argv[])
void print_statistics()
void signal_handler(int)
void store_validation_formulas()
void setup_logging()