11#include "dlinear/parser/mps/Driver.h"
12#include "dlinear/parser/onnx/Driver.h"
13#include "dlinear/parser/smt2/Driver.h"
14#include "dlinear/parser/vnnlib/Driver.h"
15#include "dlinear/solver/SmtSolverOutput.h"
16#include "dlinear/symbolic/symbolic.h"
17#include "dlinear/util/OptionValue.hpp"
18#include "dlinear/util/Timer.h"
19#include "dlinear/util/concepts.h"
20#include "dlinear/util/exception.h"
21#include "dlinear/util/logging.h"
26template <IsAnyOf<smt2::Smt2Driver, mps::MpsDriver, onnx::OnnxDriver, vnnlib::VnnlibDriver> T>
27inline bool ParseInputCore(
const Config &config, Context &context) {
28 DLINEAR_DEBUG(
"SmtSolver::ParseSmt2");
30 return config.read_from_stdin() ? driver.ParseStream(std::cin,
"(stdin)") : driver.ParseFile(config.filename());
34inline bool ParseInputCore<onnx::OnnxDriver>(
const Config &config, Context &context) {
35 DLINEAR_DEBUG(
"SmtSolver::ParseOnnx");
36 onnx::OnnxDriver driver{context};
37 return driver.ParseFile(config.onnx_file());
45 DLINEAR_TRACE(
"SmtSolver::CheckSat");
54 DLINEAR_INFO(
"SmtSolver::CheckSat: Already solved");
74 DLINEAR_TRACE(
"SmtSolver::Parse");
77 DLINEAR_INFO(
"SmtSolver::CheckSat: Already solved");
81 if (!
ParseInput()) DLINEAR_RUNTIME_ERROR(
"Error parsing the input");
85std::string SmtSolver::GetInfo(
const std::string &key)
const {
return context_.
GetInfo(key); }
86std::string SmtSolver::GetOption(
const std::string &key)
const {
return context_.
GetOption(key); }
95 DLINEAR_TRACE_FMT(
"SmtSolver::Assert: {}", f);
102 DLINEAR_TRACE(
"SmtSolver::ParseInput");
104 DLINEAR_INFO(
"SmtSolver::ParseInput: No input file provided");
107 DLINEAR_INFO(
"SmtSolver::ParseInput: Reading from stdin");
109 DLINEAR_INFO_FMT(
"SmtSolver::ParseInput: Reading from file: {}",
config_.
filename());
119 if (!ParseInputCore<onnx::OnnxDriver>(
config_,
context_))
return false;
122 DLINEAR_UNREACHABLE();
Collection of variables with associated intervals.
Simple dataclass used to store the configuration of the program.
OptionValue< std::string > & m_filename()
Get read-write access to the filename extension of the configuration.
OptionValue< bool > & m_read_from_stdin()
Get read-only access to the read_from_stdin parameter of the configuration.
Format actual_format() const
Get read-only access to the actual format parameter of the configuration.
const bool & skip_check_sat() const
Get read-write access to the skip_check_sat parameter of the configuration.
const bool & read_from_stdin() const
Get read-write access to the read_from_stdin parameter of the configuration.
std::string filename() const
Get read-only access to the filename parameter of the configuration.
bool have_objective() const
Check whether or not there is an objective function (which may be zero) to optimize.
std::string GetInfo(const std::string &key) const
Get the info key.
void Assert(const Formula &f)
Assert a formula f.
std::string GetOption(const std::string &key) const
Get the option key.
bool Verify(const Box &model) const
Check whether the model satisfies all the assertions loaded in the context.
void DeclareVariable(const Variable &v, bool is_model_variable=true)
Declare a variable v.
LpResult CheckOpt(mpq_class *obj_lo, mpq_class *obj_up)
Check the satisfiability of the asserted formulas, and (where possible) optimizes an objective functi...
SatResult CheckSat(mpq_class *actual_precision)
Check the satisfiability of the asserted formulas, and sets actual_precision to the actual max infeas...
This class provides an easy interface for using the underling solver.
SmtSolver(Config config=Config{})
Construct a new SmtSolver object with the given config .
const SmtSolverOutput & Parse()
Parse the problem from the input indicated in the configuration.
Context context_
Context obtained from the input file and passed to the SAT and SMT solvers.
SmtSolverOutput output_
Output of the solver.
const SmtSolverOutput & CheckSat()
Check the satisfiability of the current context.
bool ParseInput()
Parse the problem from the input indicated in the configuration.
void Assert(const Formula &f)
Assert a formula to the current context.
bool Verify(const Box &model) const
Check whether the model satisfies all the assertions loaded in the context.
Config config_
Configuration of the solver.
The TimeGuard wraps a timer object and pauses it when the guard object is destructed.
Represents a symbolic variable.
Global namespace for the dlinear library.
SmtResult
SmtSolver Result based on the result of the solver.
@ UNSAT
The problem is unsatisfiable.
@ SAT
The problem is satisfiable.
@ UNKNOWN
Could not determine satisfiability.
@ SKIP_SAT
The user asked to skip the satisfiability check.
@ UNSOLVED
The solver has not yet been run.
Data struct containing the output of the solver, such as the result of the computation as well as som...
mpq_class lower_bound
Lower bound of the result.
mpq_class upper_bound
Upper bound of the result.
mpq_class actual_precision
Actual precision of the computation. Always <= than precision.
Timer smt_solver_timer
Timer keeping track of the time spent in the SMT solver.
SmtResult result
Result of the computation.