SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
parser_opb.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "config.h"
4 
7 
8 #ifdef CLI_ENABLE_OPB_PARSER
9 
10 #include <carl-io/OPBImporter.h>
11 
12 
13 namespace smtrat {
14 
15 template<typename Strategy>
16 int run_opb_file(Strategy& strategy, const std::string& filename) {
17  Optimization<Strategy> optimization(strategy);
18  carl::io::OPBImporter<Poly> opb(filename);
19  SMTRAT_LOG_INFO("smtrat", "Parsing " << filename << " using OPB");
20  int exitCode = 0;
21  auto input = opb.parse();
22  if (!input) {
23  SMTRAT_LOG_ERROR("smtrat", "Parsing " << filename << " failed.");
24  exitCode = SMTRAT_EXIT_UNKNOWN;
25  } else {
26  SMTRAT_LOG_INFO("smtrat", "Parsed " << input->first);
27  SMTRAT_LOG_INFO("smtrat", "with objective " << input->second);
28  strategy.add(input->first);
29  if (!input->second.is_constant()) {
30  optimization.add_objective(input->second, true);
31  exitCode = handleAnswer(std::get<0>(optimization.compute()));
32  } else {
33  exitCode = handleAnswer(strategy.check());
34  }
35  }
36  return exitCode;
37 }
38 
39 int handleAnswer(Answer a) {
40  switch (a) {
43  std::cout << "sat" << std::endl;
44  return SMTRAT_EXIT_SAT;
45  break;
46  }
47  case smtrat::Answer::UNSAT: {
48  std::cout << "unsat" << std::endl;
49  return SMTRAT_EXIT_UNSAT;
50  break;
51  }
53  std::cout << "unknown" << std::endl;
54  return SMTRAT_EXIT_UNKNOWN;
55  break;
56  }
57  default: {
58  std::cerr << "unexpected output!";
60  break;
61  }
62  }
63 }
64 
65 }
66 
67 #else
68 
69 namespace smtrat {
70 
71 template<typename Strategy>
72 int run_opb_file(Strategy&, const std::string&) {
73  SMTRAT_LOG_ERROR("smtrat", "This version of SMT-RAT was compiled without support for OPB parsing. Please enable it by setting the corresponding CMake option.");
74  return 0;
75 }
76 
77 }
78 
79 #endif
constexpr int SMTRAT_EXIT_UNEXPECTED_ANSWER
Definition: ExitCodes.h:18
constexpr int SMTRAT_EXIT_UNKNOWN
Definition: ExitCodes.h:15
constexpr int SMTRAT_EXIT_SAT
Definition: ExitCodes.h:13
constexpr int SMTRAT_EXIT_UNSAT
Definition: ExitCodes.h:14
Class to create the formulas for axioms.
Answer
An enum with the possible answers a Module can give.
Definition: types.h:57
@ OPTIMAL
Definition: types.h:57
@ UNKNOWN
Definition: types.h:57
int run_opb_file(Strategy &, const std::string &)
Definition: parser_opb.h:72
#define SMTRAT_LOG_INFO(channel, msg)
Definition: logging.h:34
#define SMTRAT_LOG_ERROR(channel, msg)
Definition: logging.h:32