dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
Context.cpp
1
6#include "Context.h"
7
8#include <memory>
9#include <utility>
10
11#include "dlinear/solver/ContextImpl.h"
12#include "dlinear/solver/ReluConstraint.h"
13#include "dlinear/util/exception.h"
14#include "dlinear/util/logging.h"
15
16namespace dlinear {
17
18Context::Context(Context &&context) noexcept : impl_{std::move(context.impl_)} {}
19
20Context::~Context() = default;
21
22Context::Context(Config &config, SmtSolverOutput *const output) : impl_{std::make_unique<Impl>(config, output)} {}
23
24void Context::Assert(const Formula &f) { impl_->Assert(f); }
25void Context::AssertPiecewiseLinearFunction(const Variable &var, const Formula &cond, const Expression &active,
26 const Expression &inactive) {
27 impl_->AssertPiecewiseLinearFunction(var, cond, active, inactive);
28}
29SatResult Context::CheckSat(mpq_class *actual_precision) { return impl_->CheckSat(actual_precision); }
30LpResult Context::CheckOpt(mpq_class *obj_lo, mpq_class *obj_up) { return impl_->CheckOpt(obj_lo, obj_up); }
31void Context::DeclareVariable(const Variable &v, const bool is_model_variable) {
32 impl_->DeclareVariable(v, is_model_variable);
33}
34void Context::DeclareVariable(const Variable &v, const Expression &lb, const Expression &ub,
35 const bool is_model_variable) {
36 impl_->DeclareVariable(v, is_model_variable);
37 impl_->SetDomain(v, lb, ub);
38}
39const PiecewiseLinearConstraint &Context::AddGuidedConstraint(std::unique_ptr<PiecewiseLinearConstraint> &&constraint) {
40 return impl_->AddGuidedConstraint(std::move(constraint));
41}
42void Context::Exit() { DLINEAR_DEBUG("Context::Exit()"); }
43void Context::Minimize(const Expression &f) { impl_->Minimize(f); }
44void Context::Maximize(const Expression &f) { impl_->Maximize(f); }
45
46void Context::Pop(int n) {
47 DLINEAR_DEBUG_FMT("Context::Pop({})", n);
48 if (n <= 0) DLINEAR_RUNTIME_ERROR_FMT("Context::Pop(n) called with n = {} which is not positive.", n);
49 while (n-- > 0) impl_->Pop();
50}
51void Context::Push(int n) {
52 DLINEAR_DEBUG_FMT("Context::Push({})", n);
53 if (n <= 0) DLINEAR_RUNTIME_ERROR_FMT("Context::Push(n) called with n = {} which is not positive.", n);
54 while (n-- > 0) impl_->Push();
55}
56
57void Context::SetInfo(const std::string &key, const std::string &val) { impl_->SetInfo(key, val); }
58std::string Context::GetInfo(const std::string &key) const { return impl_->GetInfo(key); }
59void Context::SetInterval(const Variable &v, const mpq_class &lb, const mpq_class &ub) {
60 impl_->SetInterval(v, lb, ub);
61}
62void Context::SetLogic(const Logic logic) { impl_->SetLogic(logic); }
63void Context::SetOption(const std::string &key, const std::string &val) { impl_->SetOption(key, val); }
64std::string Context::GetOption(const std::string &key) const { return impl_->GetOption(key); }
65const Config &Context::config() const { return impl_->config(); }
66const Box &Context::box() const { return impl_->box(); }
67const Box &Context::model() const { return impl_->get_model(); }
68const SmtSolverOutput *Context::solver_output() const { return impl_->solver_output(); }
69SmtSolverOutput *Context::m_solver_output() { return impl_->m_solver_output(); }
70const PredicateAbstractor &Context::predicate_abstractor() const { return impl_->predicate_abstractor(); }
71const ScopedVector<Formula> &Context::assertions() const { return impl_->assertions(); }
72bool Context::have_objective() const { return impl_->have_objective(); }
73bool Context::is_max() const { return impl_->is_max(); }
74bool Context::Verify(const Box &model) const { return impl_->Verify(model); }
75
76} // namespace dlinear
Collection of variables with associated intervals.
Definition Box.h:31
Simple dataclass used to store the configuration of the program.
Definition Config.h:38
The context juggles between the SAT solver and the theory solver, in order to produce a model.
Definition ContextImpl.h:42
void Assert(const Formula &f)
Assert a formula f.
Context(Config &config, SmtSolverOutput *=nullptr)
Construct a context with config.
Definition Context.cpp:22
bool have_objective() const
Check whether or not there is an objective function (which may be zero) to optimize.
Definition Context.cpp:72
void Push(int n)
Push n stacks.
Definition Context.cpp:51
const Config & config() const
Get read-only access to the configuration of the context.
Definition Context.cpp:65
void SetInfo(const std::string &key, const std::string &val)
Set an info key with a value val.
Definition Context.cpp:57
std::string GetInfo(const std::string &key) const
Get the info key.
Definition Context.cpp:58
void Assert(const Formula &f)
Assert a formula f.
Definition Context.cpp:24
std::unique_ptr< Impl > impl_
Pointer to the implementation of the context.
Definition Context.h:238
void SetLogic(Logic logic)
Set the current logic to logic.
Definition Context.cpp:62
void Minimize(const Expression &f)
Assert a formula minimizing a cost function f.
Definition Context.cpp:43
std::string GetOption(const std::string &key) const
Get the option key.
Definition Context.cpp:64
bool is_max() const
Check whether or not the objective function (if present) is a maximization.
Definition Context.cpp:73
bool Verify(const Box &model) const
Check whether the model satisfies all the assertions loaded in the context.
Definition Context.cpp:74
const PredicateAbstractor & predicate_abstractor() const
Get read-only access to the predicate_abstractor of the context.
Definition Context.cpp:70
void Maximize(const Expression &f)
Assert a formula maximizing a cost function f.
Definition Context.cpp:44
void DeclareVariable(const Variable &v, bool is_model_variable=true)
Declare a variable v.
Definition Context.cpp:31
void SetOption(const std::string &key, const std::string &val)
Set an option key with a value val.
Definition Context.cpp:63
const ScopedVector< Formula > & assertions() const
Get the the asserted formulas.
Definition Context.cpp:71
LpResult CheckOpt(mpq_class *obj_lo, mpq_class *obj_up)
Check the satisfiability of the asserted formulas, and (where possible) optimizes an objective functi...
Definition Context.cpp:30
void Pop(int n)
Pop n stacks.
Definition Context.cpp:46
void Exit()
Exit the context.
Definition Context.cpp:42
void AssertPiecewiseLinearFunction(const Variable &var, const Formula &cond, const Expression &active, const Expression &inactive)
Assert a piecewise linear function with two possible branches.
Definition Context.cpp:25
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_).
Definition Context.cpp:59
SatResult CheckSat(mpq_class *actual_precision)
Check the satisfiability of the asserted formulas, and sets actual_precision to the actual max infeas...
Definition Context.cpp:29
const Box & model() const
Get a representation of a model computed by the solver in response to the last invocation of the chec...
Definition Context.cpp:67
const Box & box() const
Get the current active box from the top of the stack of boxes.
Definition Context.cpp:66
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.
Represents a symbolic form of an expression.
Represents a symbolic form of a first-order logic formula.
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.
Definition SatResult.h:17
Logic
The SMT-LIB logic the SMT2 file is using.
Definition Logic.h:17
LpResult
Result of running the LP solver over the input problem.
Definition LpResult.h:14
STL namespace.
Data struct containing the output of the solver, such as the result of the computation as well as som...