12#include <unordered_map>
13#include <unordered_set>
18#include "dlinear/libs/libgmp.h"
19#include "dlinear/solver/Context.h"
20#include "dlinear/solver/Logic.h"
21#include "dlinear/solver/LpResult.h"
22#include "dlinear/solver/PiecewiseLinearConstraint.h"
23#include "dlinear/solver/SatResult.h"
24#include "dlinear/solver/SatSolver.h"
25#include "dlinear/solver/SmtSolverOutput.h"
26#include "dlinear/solver/TheorySolver.h"
27#include "dlinear/symbolic/IfThenElseEliminator.h"
28#include "dlinear/symbolic/PredicateAbstractor.h"
29#include "dlinear/symbolic/literal.h"
30#include "dlinear/symbolic/symbolic.h"
31#include "dlinear/util/Box.h"
32#include "dlinear/util/Config.h"
33#include "dlinear/util/ScopedVector.hpp"
51 Impl &operator=(
const Impl &) =
delete;
141 void SetInfo(
const std::string &key,
const std::string &val);
147 [[nodiscard]] std::string
GetInfo(
const std::string &key)
const;
165 void SetOption(
const std::string &key,
const std::string &val);
171 [[nodiscard]] std::string
GetOption(
const std::string &key)
const;
285 void MinimizeCore(
const Expression &obj_expr);
325 std::unordered_map<std::string, std::string>
info_;
326 std::unordered_map<std::string, std::string>
option_;
337 std::vector<std::unique_ptr<PiecewiseLinearConstraint>>
Collection of variables with associated intervals.
Simple dataclass used to store the configuration of the program.
The context juggles between the SAT solver and the theory solver, in order to produce a model.
const Config & config() const
Get the configuration of the context.
void Assert(const Formula &f)
Assert a formula f.
std::unordered_map< std::string, std::string > option_
Key-value pairs of options.
Box ExtractModel(const Box &box) const
Extract a model from the box.
Box model_
Stores the result of the latest checksat. If the checksat result was UNSAT, the model is empty.
std::unordered_set< Variable::Id > model_variables_
Set of model variables.
void Push()
Push the current set of assertions to the stack.
void SetDomain(const Variable &v, const Expression &lb, const Expression &ub)
Set a domain for the variable v, restricting it to the interval .
SatResult CheckSat(mpq_class *precision)
Check the satisfiability of the asserted formulas, and sets actual_precision to the actual max infeas...
void UpdateAndPrintOutput(SmtResult smt_result) const
Update the output_ with the last smt_result .
bool have_objective_
Keeps track of whether or not there is an objective function.
bool have_objective() const
Check whether or not there is an objective function (which may be zero) to optimize.
SmtSolverOutput *const output_
Output of the SMT solver. Stores the result of the checksat and some statistics.
void SetOption(const std::string &key, const std::string &val)
Set an option key with a value val.
const std::unique_ptr< TheorySolver > theory_solver_
Theory solver.
const Box & get_model()
Get a representation of a model computed by the solver in response to the last invocation of the chec...
void LearnExplanations(const TheorySolver::Explanations &explanations)
The TheorySolver found a number of conflicts and the explanations are the set of literals that are re...
void SetInterval(const Variable &v, const mpq_class &lb, const mpq_class &ub)
Set the interval of v to in the current box (top one in boxes_).
bool Verify(const Box &model) const
Check whether the model satisfies all the assertions loaded in the context.
void SetLogic(Logic logic)
Set the current logic to logic.
const PredicateAbstractor & predicate_abstractor() const
Get read-only access to the predicate_abstractor of the context.
const ScopedVector< Formula > & assertions() const
Get the the asserted formulas.
std::unordered_map< std::string, std::string > info_
Key-value pairs of information.
Box & box()
Get the current active box from the top of the stack_ of boxes.
void MarkModelVariable(const Variable &v)
Mark the variable v as a model variable.
std::optional< Logic > logic_
SMT Logic of the context. Must be among the supported logics.
std::vector< std::unique_ptr< PiecewiseLinearConstraint > > pl_constraints_
Special constraints that can be used to guide the SAT solver towards a possible SAT assignment.
ScopedVector< Formula > stack_
Stack of asserted formulas.
std::string GetInfo(const std::string &key) const
Get the info key.
void DeclareVariable(const Variable &v, bool is_model_variable)
Declare a variable v.
IfThenElseEliminator ite_eliminator_
Eliminates if-then-else expressions from the formula.
std::string GetOption(const std::string &key) const
Get the option key.
void SetInfo(const std::string &key, const std::string &val)
Set an info key with a value val.
bool is_max() const
Check whether or not the objective function (if present) is a maximization.
void Minimize(const Expression &obj_function)
Assert a formula minimizing a cost function f.
void AddToBox(const Variable &v)
Add the variable v to the current box.
void LearnExplanation(const LiteralSet &explanation)
The TheorySolver found a conflict and the explanation is the set of literals that are responsible.
SatResult CheckSatCore(mpq_class *actual_precision)
Check the satisfiability of the current set of assertions.
ScopedVector< Box > boxes_
Stack of boxes. The top one is the current box.
LpResult CheckOpt(mpq_class *obj_lo, mpq_class *obj_up)
Check the satisfiability of the asserted formulas, and (where possible) optimizes an objective functi...
const std::unique_ptr< SatSolver > sat_solver_
SAT solver.
void Maximize(const Expression &obj_function)
Assert a formula maximizing a cost function f.
std::unique_ptr< SatSolver > GetSatSolver()
Get the correct sat solver subclass based on the configuration.
const Box & box() const
Get the current active box from the top of the stack_ of boxes.
bool IsModelVariable(const Variable &v) const
Check if the variable v is a model variable.
Impl(Config &config, SmtSolverOutput *output=nullptr)
Construct a context with config.
void Pop()
Pop the top of the stack of assertions.
void AssertPiecewiseLinearFunction(const Variable &var, const Formula &cond, const Expression &active, const Expression &inactive)
Assert a piecewise linear function with two possible branches.
LpResult CheckOptCore(mpq_class *obj_lo, mpq_class *obj_up)
Check the satisfiability of the asserted formulas, and (where possible) optimizes an objective functi...
std::set< LiteralSet > explanations_so_far
Set of explanations that have been learned so far.
PredicateAbstractor predicate_abstractor_
Converts the theory literals to boolean variables.
Config & config_
Configuration of the context. It could be modified by the problem instance.
bool is_max_
Keeps track of whether or not the objective function is being maximized.
std::unique_ptr< TheorySolver > GetTheorySolver()
Get the correct theory solver subclass based on the configuration.
const Box & model() const
Get a representation of a model computed by the solver in response to the last invocation of the chec...
IfThenElseEliminator class.
A piecewise linear constraint is a constraint that assumes different linear functions depending on th...
Predicate abstraction is a method to convert a first-order logic formula into a Boolean formula.
std::set< LiteralSet > Explanations
Set of explanations of the conflict.
Represents a symbolic form of an expression.
Represents a symbolic variable.
Global namespace for the dlinear library.
SatResult
Result of running the theory solver over the literals decided by the SAT solver.
Logic
The SMT-LIB logic the SMT2 file is using.
SmtResult
SmtSolver Result based on the result of the solver.
LpResult
Result of running the LP solver over the input problem.
std::set< Literal > LiteralSet
A set of literals.
Data struct containing the output of the solver, such as the result of the computation as well as som...