dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
Context.h
1
7#pragma once
8
9#include <memory>
10#include <string>
11
12#include "dlinear/libs/libgmp.h"
13#include "dlinear/solver/Logic.h"
14#include "dlinear/solver/LpResult.h"
15#include "dlinear/solver/PiecewiseLinearConstraint.h"
16#include "dlinear/solver/SatResult.h"
17#include "dlinear/solver/SmtSolverOutput.h"
18#include "dlinear/symbolic/PredicateAbstractor.h"
19#include "dlinear/symbolic/literal.h"
20#include "dlinear/symbolic/symbolic.h"
21#include "dlinear/util/Box.h"
22#include "dlinear/util/Config.h"
23#include "dlinear/util/ScopedVector.hpp"
24
25namespace dlinear {
26
31class Context {
32 public:
39 explicit Context(Config &config, SmtSolverOutput * = nullptr);
40 Context(const Context &context) = delete;
41 Context(Context &&context) noexcept;
42 Context &operator=(const Context &) = delete;
43 Context &operator=(Context &&) = delete;
44 ~Context();
45
52 void Assert(const Formula &f);
75 void AssertPiecewiseLinearFunction(const Variable &var, const Formula &cond, const Expression &active,
76 const Expression &inactive);
77
86 SatResult CheckSat(mpq_class *actual_precision);
94 LpResult CheckOpt(mpq_class *obj_lo, mpq_class *obj_up);
95
104 void DeclareVariable(const Variable &v, bool is_model_variable = true);
115 void DeclareVariable(const Variable &v, const Expression &lb, const Expression &ub, bool is_model_variable = true);
116
117 const PiecewiseLinearConstraint &AddGuidedConstraint(std::unique_ptr<PiecewiseLinearConstraint> &&constraint);
118
124 void Exit();
125
130 void Minimize(const Expression &f);
131
136 void Maximize(const Expression &f);
137
142 void Pop(int n);
147 void Push(int n);
153 void SetInfo(const std::string &key, const std::string &val);
159 [[nodiscard]] std::string GetInfo(const std::string &key) const;
166 void SetInterval(const Variable &v, const mpq_class &lb, const mpq_class &ub);
171 void SetLogic(Logic logic);
177 void SetOption(const std::string &key, const std::string &val);
183 [[nodiscard]] std::string GetOption(const std::string &key) const;
184
186 [[nodiscard]] const Config &config() const;
192 [[nodiscard]] const ScopedVector<Formula> &assertions() const;
197 [[nodiscard]] const Box &box() const;
202 [[nodiscard]] const Box &model() const;
208 [[nodiscard]] bool have_objective() const;
209 [[nodiscard]] const SmtSolverOutput *solver_output() const;
210 SmtSolverOutput *m_solver_output();
213
219 [[nodiscard]] bool is_max() const;
220
229 [[nodiscard]] bool Verify(const Box &model) const;
230
231 private:
236 class Impl;
237
238 std::unique_ptr<Impl> impl_;
239};
240
241} // 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
Context class that holds the set of constraints and provide Assert/Push/Pop/CheckSat functionalities.
Definition Context.h:31
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
Data struct containing the output of the solver, such as the result of the computation as well as som...