dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
Config.h
1
11#pragma once
12
13#include <iosfwd>
14#include <string>
15#include <string_view>
16
17#include "dlinear/util/OptionValue.hpp"
18
19namespace dlinear {
20
21#define DLINEAR_PARAMETER(param_name, type, default_value, help) \
22 public: \
23 \
24 OptionValue<type> &m_##param_name() { return param_name##_; } \
25 \
26 [[nodiscard]] const type &param_name() const { return param_name##_.get(); } \
27 static constexpr type default_##param_name{default_value}; \
28 static constexpr const char *const help_##param_name{help}; \
29 \
30 private: \
31 OptionValue<type> param_name##_{default_value};
32
38class Config {
39 public:
41 enum class LPSolver {
42 SOPLEX = 0,
43 QSOPTEX = 1,
44 };
46 enum class SatSolver {
47 CADICAL = 0,
48 PICOSAT = 1,
49 };
51 enum class SatDefaultPhase {
52 False = 0,
53 True = 1,
54 JeroslowWang = 2,
56 };
58 enum class Format {
59 AUTO,
60 SMT2,
61 MPS,
62 VNNLIB
63 };
65 enum class LPMode {
66 AUTO = 0,
69 HYBRID = 3,
70 };
73 AUTO = 0,
74 EQ_BINOMIAL = 1,
75 EQ_POLYNOMIAL = 2,
77 };
80 AUTO,
81 NEVER,
82 ON_FIXED,
84 ALWAYS
85 };
86
88 Config() = default;
93 explicit Config(std::string filename);
98 explicit Config(bool read_from_stdin);
99
100 public:
101 static constexpr std::string_view help_onnx_file{"ONNX file name"};
102 static constexpr std::string_view help_filename{"Input file name"};
103
105 [[nodiscard]] std::string filename() const { return filename_.get(); }
107 [[nodiscard]] std::string filename_extension() const;
109 OptionValue<std::string> &m_filename() { return filename_; }
111 [[nodiscard]] std::string onnx_file() const { return onnx_file_.get(); }
113 OptionValue<std::string> &m_onnx_file() { return onnx_file_; }
118 [[nodiscard]] bool needs_expansion() const;
123 [[nodiscard]] LPMode actual_lp_mode() const;
128 [[nodiscard]] Format actual_format() const;
147
148 private:
149 OptionValue<std::string> filename_{""};
150 OptionValue<std::string> onnx_file_{""};
151
153 "The type of bound propagation to apply in the preprocessing phase.\n"
154 "\t\tEach of the options is more complete and expensive than the previous one.\n"
155 "\t\tOne of: auto (1), eq-binomial (2), eq-polynomial (3), bound-polynomial (4)")
157 "How often to run the generic bound propagation preprocessing.\n"
158 "\t\tOne of: auto (1), never (2), on-fixed (3), on-iteration (4), always (5)")
160 "How often to run the bound implication preprocessing.\n"
161 "\t\tOne of: auto (1), never (2), always (3)")
162 DLINEAR_PARAMETER(complete, bool, false,
163 "Run the solver in complete mode.\n"
164 "\t\tThe precision will be set to 0 and strict inequalities will be taken into account")
165 DLINEAR_PARAMETER(continuous_output, bool, false, "Continuous output")
166 DLINEAR_PARAMETER(csv, bool, false, "Produce CSV output. Must also specify --with-timings to get the time stats")
167 DLINEAR_PARAMETER(debug_parsing, bool, false, "Debug parsing")
168 DLINEAR_PARAMETER(debug_scanning, bool, false, "Debug scanning/lexing")
169 DLINEAR_PARAMETER(disable_expansion, bool, false,
170 "Disable formula expansion.\n"
171 "\t\tMakes the parser faster, "
172 "but may create issues if an intermediate formula of the input becomes non linear")
173 DLINEAR_PARAMETER(
174 enforce_check_sat, bool, false,
175 "Perform a satisfiability check at the end of parsing if the input does not contain a (check-sat) directive")
176 DLINEAR_PARAMETER(format, Format, dlinear::Config::Format::AUTO,
177 "Input file format\n"
178 "\t\tOne of: auto (1), smt2 (2), mps (3), vnnlib (4)")
179 DLINEAR_PARAMETER(lp_mode, LPMode, dlinear::Config::LPMode::AUTO,
180 "LP mode used by the LP solver.\n"
181 "\t\tOne of: auto (1), pure-precision-boosting (2), pure-iterative-refinement (3), hybrid (4)")
182 DLINEAR_PARAMETER(lp_solver, LPSolver, dlinear::Config::LPSolver::SOPLEX,
183 "Underlying LP solver used by the theory solver.\n"
184 "\t\tOne of: soplex (1), qsoptex (2)")
185 DLINEAR_PARAMETER(number_of_jobs, unsigned int, 1u, "Number of jobs")
186 DLINEAR_PARAMETER(optimize, bool, false, "Whether to optimize the objective function. Only affects the MPS format")
187 DLINEAR_PARAMETER(precision, double, 9.999999999999996e-4,
188 "Delta precision used by the LP solver solver.\n"
189 "\t\tEven when set to 0, a positive infinitesimal value will be considered.\n"
190 "\t\twhile the LP solver will yield an exact solution, strict inequalities will still be relaxed\n"
191 "\t\tUse the --complete flag if you are looking for a complete solution")
192 DLINEAR_PARAMETER(produce_models, bool, false,
193 "Produce models, showing a valid assignment.\n"
194 "\t\tOnly applicable if the result is sat or delta-sat")
195 DLINEAR_PARAMETER(random_seed, unsigned int, 0u,
196 "Set the random seed. 0 means that the seed will be generated on the fly")
197 DLINEAR_PARAMETER(read_from_stdin, bool, false, "Read the input from the standard input")
199 "set default initial phase for SAT solver.\n"
200 "\t\tOne of: false (0), true (1), Jeroslow-Wang (2), random initial phase (3)")
201 DLINEAR_PARAMETER(sat_solver, SatSolver, dlinear::Config::SatSolver::PICOSAT,
202 "Underlying SAT solver used by the SAT solver.\n"
203 "\t\tOne of: cadical (1), picosat (2)")
204 DLINEAR_PARAMETER(silent, bool, false, "Silent mode. Nothing will be printed on the standard output")
205 DLINEAR_PARAMETER(simplex_sat_phase, int, 1, "What phase to use to verify the feasibility of the LP problem")
206 DLINEAR_PARAMETER(skip_check_sat, bool, false, "Parse the input, but does not run the solver")
207 DLINEAR_PARAMETER(verbose_dlinear, int, 2, "Verbosity level for dlinear. In the range [0, 5]")
208 DLINEAR_PARAMETER(verbose_simplex, int, 0, "Verbosity level for simplex. In the range [0, 5]")
209 DLINEAR_PARAMETER(verify, bool, false, "If the input produces a SAT output, verify the assignment against the input")
210 DLINEAR_PARAMETER(with_timings, bool, false, "Report timings alongside results")
211};
212
213std::ostream &operator<<(std::ostream &os, const Config &config);
214std::ostream &operator<<(std::ostream &os, const Config::SatDefaultPhase &sat_default_phase);
215std::ostream &operator<<(std::ostream &os, const Config::LPSolver &lp_solver);
216std::ostream &operator<<(std::ostream &os, const Config::SatSolver &mode);
217std::ostream &operator<<(std::ostream &os, const Config::Format &format);
218std::ostream &operator<<(std::ostream &os, const Config::LPMode &mode);
219std::ostream &operator<<(std::ostream &os, const Config::BoundPropagationType &type);
220std::ostream &operator<<(std::ostream &os, const Config::PreprocessingRunningFrequency &frequency);
221
222} // namespace dlinear
223
224#ifdef DLINEAR_INCLUDE_FMT
225#include "dlinear/util/logging.h"
226
227OSTREAM_FORMATTER(dlinear::Config);
228OSTREAM_FORMATTER(dlinear::Config::SatDefaultPhase);
229OSTREAM_FORMATTER(dlinear::Config::LPSolver);
230OSTREAM_FORMATTER(dlinear::Config::SatSolver);
231OSTREAM_FORMATTER(dlinear::Config::Format);
232OSTREAM_FORMATTER(dlinear::Config::LPMode);
235
236#endif
Simple dataclass used to store the configuration of the program.
Definition Config.h:38
const int & verbose_simplex() const
Get read-write access to the verbose_simplex parameter of the configuration.
Definition Config.h:208
const PreprocessingRunningFrequency & bound_propagation_frequency() const
Get read-write access to the bound_propagation_frequency parameter of the configuration.
Definition Config.h:158
const LPMode & lp_mode() const
Get read-write access to the lp_mode parameter of the configuration.
Definition Config.h:181
const bool & continuous_output() const
Get read-write access to the continuous_output parameter of the configuration.
Definition Config.h:165
const unsigned int & number_of_jobs() const
Get read-write access to the number_of_jobs parameter of the configuration.
Definition Config.h:185
const PreprocessingRunningFrequency & bound_implication_frequency() const
Get read-write access to the bound_implication_frequency parameter of the configuration.
Definition Config.h:161
SatSolver
Underlying SAT solver used by the abstract SAT solver.
Definition Config.h:46
@ CADICAL
Cadical Solver. Default option.
@ PICOSAT
Picosat Solver.
LPMode
LP mode used by the LP solver.
Definition Config.h:65
@ HYBRID
Use both modes, if available.
@ PURE_PRECISION_BOOSTING
Use the precision boosting mode, if available.
@ PURE_ITERATIVE_REFINEMENT
Use the iterative refinement mode, if available.
Format
Format of the input file.
Definition Config.h:58
@ VNNLIB
VNNLIB format.
@ AUTO
Automatically detect the input format based on the file extension. Default option.
const bool & complete() const
Get read-write access to the complete parameter of the configuration.
Definition Config.h:164
BoundPropagationType actual_bound_propagation_type() const
Get read-only access to the actual actual_bound_propagation_type parameter of the configuration.
Definition Config.cpp:48
const bool & optimize() const
Get read-write access to the optimize parameter of the configuration.
Definition Config.h:186
BoundPropagationType
Types of bound propagation supported by the bound propagator.
Definition Config.h:72
@ EQ_POLYNOMIAL
Only propagate bound in theory formulae in the form .
@ EQ_BINOMIAL
Only propagate bounds in theory formulas in the form .
@ BOUND_POLYNOMIAL
Propagate all possible constraints.
@ AUTO
Automatically select the best configuration based on expected performance. Default option.
PreprocessingRunningFrequency actual_bound_implication_frequency() const
Get read-only access to the actual bound_implication_frequency parameter of the configuration.
Definition Config.cpp:82
const bool & produce_models() const
Get read-write access to the produce_models parameter of the configuration.
Definition Config.h:194
OptionValue< std::string > & m_filename()
Get read-write access to the filename extension of the configuration.
Definition Config.h:109
const bool & enforce_check_sat() const
Get read-write access to the enforce_check_sat parameter of the configuration.
Definition Config.h:175
const bool & csv() const
Get read-write access to the csv parameter of the configuration.
Definition Config.h:166
std::string onnx_file() const
Get read-only access to the onnx_file parameter of the configuration.
Definition Config.h:111
LPSolver
Underlying LP solver used by the theory solver.
Definition Config.h:41
@ QSOPTEX
Qsoptex Solver.
@ SOPLEX
Soplex Solver. Default option.
Format actual_format() const
Get read-only access to the actual format parameter of the configuration.
Definition Config.cpp:33
const Format & format() const
Get read-write access to the format parameter of the configuration.
Definition Config.h:178
const BoundPropagationType & bound_propagation_type() const
Get read-write access to the bound_propagation_type parameter of the configuration.
Definition Config.h:155
const LPSolver & lp_solver() const
Get read-write access to the lp_solver parameter of the configuration.
Definition Config.h:184
const bool & with_timings() const
Get read-write access to the with_timings parameter of the configuration.
Definition Config.h:210
const bool & silent() const
Get read-write access to the silent parameter of the configuration.
Definition Config.h:204
const bool & debug_scanning() const
Get read-write access to the debug_scanning parameter of the configuration.
Definition Config.h:168
const bool & debug_parsing() const
Get read-write access to the debug_parsing parameter of the configuration.
Definition Config.h:167
PreprocessingRunningFrequency
Frequency at which the preprocessors will run.
Definition Config.h:79
@ ON_ITERATION
Run this preprocess only at every iteration.
@ NEVER
Never run this preprocess, effectively disabling it.
@ ON_FIXED
Run this preprocess only once, on fixed literals, before all iterations.
@ ALWAYS
Run this preprocess at every chance it gets. Usually combines ON_FIXED and ON_ITERATION.
const bool & skip_check_sat() const
Get read-write access to the skip_check_sat parameter of the configuration.
Definition Config.h:206
PreprocessingRunningFrequency actual_bound_propagation_frequency() const
Get read-only access to the actual bound_propagation_frequency parameter of the configuration.
Definition Config.cpp:65
const bool & read_from_stdin() const
Get read-write access to the read_from_stdin parameter of the configuration.
Definition Config.h:197
Config()=default
Construct a new Config object.
const bool & verify() const
Get read-write access to the verify parameter of the configuration.
Definition Config.h:209
const unsigned int & random_seed() const
Get read-write access to the random_seed parameter of the configuration.
Definition Config.h:196
std::string filename_extension() const
Get read-only access to the filename extension of the configuration.
Definition Config.cpp:18
const int & verbose_dlinear() const
Get read-write access to the verbose_dlinear parameter of the configuration.
Definition Config.h:207
const SatDefaultPhase & sat_default_phase() const
Get read-write access to the sat_default_phase parameter of the configuration.
Definition Config.h:200
const bool & disable_expansion() const
Get read-write access to the disable_expansion parameter of the configuration.
Definition Config.h:172
const int & simplex_sat_phase() const
Get read-write access to the simplex_sat_phase parameter of the configuration.
Definition Config.h:205
OptionValue< std::string > & m_onnx_file()
Get read-write access to the onnx_file parameter of the configuration.
Definition Config.h:113
SatDefaultPhase
Phase for the SAT solver.
Definition Config.h:51
@ RandomInitialPhase
Randomly assign a value to non fixed decision literals.
@ True
Assign true to non fixed decision literals.
@ False
Assign false to non fixed decision literals.
LPMode actual_lp_mode() const
Get read-only access to the actual lp_mode parameter of the configuration.
Definition Config.cpp:25
bool needs_expansion() const
Definition Config.cpp:20
const double & precision() const
Get read-write access to the precision parameter of the configuration.
Definition Config.h:191
std::string filename() const
Get read-only access to the filename parameter of the configuration.
Definition Config.h:105
const SatSolver & sat_solver() const
Get read-write access to the sat_solver parameter of the configuration.
Definition Config.h:203
Represents an optional value in dLinear.
const T & get() const
Get read-only access to the internal stored value of the optional value.
Global namespace for the dlinear library.
@ SAT
The problem is satisfiable.
STL namespace.