SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Tools.cpp
Go to the documentation of this file.
1 #include "Tools.h"
2 
3 #include "MathSAT.h"
4 #include "Minisat.h"
5 #include "Minisatp.h"
6 #include "SMTRAT.h"
7 #include "SMTRAT_OPB.h"
8 #include "SMTRAT_Analyzer.h"
9 #include "Z3.h"
10 
12 #include <benchmax/logging.h>
13 #include <regex>
14 
15 namespace benchmax {
16 
17 template<typename T>
18 void createTools(const std::vector<std::filesystem::path>& arguments, Tools& tools) {
19  std::regex r("([^ ]+) *(.*)");
20  for (const auto& arg: arguments) {
21  std::smatch matches;
22  if (std::regex_match(arg.native(), matches, r)) {
23  fs::path path = std::filesystem::canonical(fs::path(matches[1]));
24  if (!fs::is_regular_file(path)) {
25  BENCHMAX_LOG_WARN("benchmax", "The tool " << path << " does not seem to be a file. We skip it.");
26  continue;
27  }
28  const fs::perms executable = fs::perms::others_exec | fs::perms::group_exec | fs::perms::owner_exec;
29  if ((fs::status(path).permissions() & executable) == fs::perms::none) {
30  BENCHMAX_LOG_WARN("benchmax", "The tool " << path << " does not seem to be executable. We skip it.");
31  continue;
32  }
33  BENCHMAX_LOG_DEBUG("benchmax.tools", "Adding tool " << path << " with arguments \"" << matches[2] << "\".");
34  tools.emplace_back(std::make_unique<T>(path, matches[2]));
35  }
36  }
37 }
38 
40  Tools tools;
41  createTools<Tool>(settings_tools().tools_generic, tools);
42  createTools<MathSAT>(settings_tools().tools_mathsat, tools);
43  createTools<Minisat>(settings_tools().tools_minisat, tools);
44  createTools<Minisatp>(settings_tools().tools_minisatp, tools);
45  createTools<SMTRAT>(settings_tools().tools_smtrat, tools);
46  createTools<SMTRAT_OPB>(settings_tools().tools_smtrat_opb, tools);
47  createTools<SMTRAT_Analyzer>(settings_tools().tools_smtrat_analyzer, tools);
48  createTools<Z3>(settings_tools().tools_z3, tools);
49  return tools;
50 }
51 
52 namespace settings {
53 
54 /// Postprocess settings to compute common prefix.
55 bool finalize_tool_settings(ToolSettings& s, const boost::program_options::variables_map&) {
59  });
60  BENCHMAX_LOG_DEBUG("benchmax.tools", "Common tool prefix is " << s.tools_common_prefix);
61  return false;
62 }
63 
65  namespace po = boost::program_options;
66  auto& settings = settings::Settings::getInstance();
67  auto& s = settings.get<settings::ToolSettings>("tools");
68 
69  parser->add_finalizer([&s](const auto& values){
70  return finalize_tool_settings(s, values);
71  });
72  parser->add("Tool settings").add_options()
73  ("statistics,s", po::bool_switch(&s.collect_statistics), "run tools with statistics")
74  ("tool", po::value<std::vector<std::filesystem::path>>(&s.tools_generic), "a generic tool")
75  ("mathsat", po::value<std::vector<std::filesystem::path>>(&s.tools_mathsat), "MathSAT with SMT-LIB interface")
76  ("minisat", po::value<std::vector<std::filesystem::path>>(&s.tools_minisat), "Minisat with DIMACS interface")
77  ("minisatp", po::value<std::vector<std::filesystem::path>>(&s.tools_minisatp), "Minisatp with OPB interface")
78  ("smtrat,S", po::value<std::vector<std::filesystem::path>>(&s.tools_smtrat), "SMT-RAT with SMT-LIB interface")
79  ("smtrat-opb,O", po::value<std::vector<std::filesystem::path>>(&s.tools_smtrat_opb), "SMT-RAT with OPB interface")
80  ("smtrat-analyzer,A", po::value<std::vector<std::filesystem::path>>(&s.tools_smtrat_analyzer), "SMT-RAT formula analyzer")
81  ("z3,Z", po::value<std::vector<std::filesystem::path>>(&s.tools_z3), "z3 with SMT-LIB interface")
82  ;
83 }
84 }
85 
86 }
#define BENCHMAX_LOG_DEBUG(channel, msg)
Log debug messages.
Definition: logging.h:55
#define BENCHMAX_LOG_WARN(channel, msg)
Log warnings.
Definition: logging.h:51
Generic class to manage settings parsing using boost::program_options.
bool finalize_tool_settings(ToolSettings &s, const boost::program_options::variables_map &)
Postprocess settings to compute common prefix.
Definition: Tools.cpp:55
void registerToolSettings(SettingsParser *parser)
Registers tool settings with the settings parser.
Definition: Tools.cpp:64
std::filesystem::path common_prefix(const std::filesystem::path &p1, const std::filesystem::path &p2)
Computes the common prefix of two paths.
Definition: filesystem.h:12
Tools loadTools()
Load all tools from the tool settings.
Definition: Tools.cpp:39
std::vector< ToolPtr > Tools
A vector of ToolPtr.
Definition: Tools.h:17
const auto & settings_tools()
Returns the tool settings.
Definition: Tools.h:59
void createTools(const std::vector< std::filesystem::path > &arguments, Tools &tools)
Create tools of a given type T from a list of binaries and store them in tools.
Definition: Tools.cpp:18
Tool-related settings.
Definition: Tools.h:31
std::vector< std::filesystem::path > tools_z3
z3 with SMT-LIB interface.
Definition: Tools.h:49
std::filesystem::path tools_common_prefix
Common prefix of tool binaries to simplify output.
Definition: Tools.h:51
std::vector< std::filesystem::path > tools_smtrat
SMT-RAT with SMT-LIB interface.
Definition: Tools.h:43
std::vector< std::filesystem::path > tools_smtrat_analyzer
SMT-RAT formula analyzer.
Definition: Tools.h:47
std::vector< std::filesystem::path > tools_minisatp
Minisatp with OPB interface.
Definition: Tools.h:41
std::vector< std::filesystem::path > tools_smtrat_opb
SMT-RAT with OPB interface.
Definition: Tools.h:45
std::vector< std::filesystem::path > tools_generic
Generic tools.
Definition: Tools.h:35