dlinear
0.0.1
Delta-complete SMT solver for linear programming
|
Context class that holds the set of constraints and provide Assert/Push/Pop/CheckSat functionalities. More...
#include <Context.h>
Classes | |
class | Impl |
The context juggles between the SAT solver and the theory solver, in order to produce a model. More... | |
Public Member Functions | |
Context (Config &config, SmtSolverOutput *=nullptr) | |
Construct a context with config . | |
void | Assert (const Formula &f) |
Assert a formula f . | |
void | AssertPiecewiseLinearFunction (const Variable &var, const Formula &cond, const Expression &active, const Expression &inactive) |
Assert a piecewise linear function with two possible branches. | |
SatResult | CheckSat (mpq_class *actual_precision) |
Check the satisfiability of the asserted formulas, and sets actual_precision to the actual max infeasibility where appropriate. | |
LpResult | CheckOpt (mpq_class *obj_lo, mpq_class *obj_up) |
Check the satisfiability of the asserted formulas, and (where possible) optimizes an objective function over them. | |
void | DeclareVariable (const Variable &v, bool is_model_variable=true) |
Declare a variable v . | |
void | DeclareVariable (const Variable &v, const Expression &lb, const Expression &ub, bool is_model_variable=true) |
Declare a variable v which is bounded by an interval \( [lb, ub] \). | |
void | Exit () |
Exit the context. | |
void | Minimize (const Expression &f) |
Assert a formula minimizing a cost function f . | |
void | Maximize (const Expression &f) |
Assert a formula maximizing a cost function f . | |
void | Pop (int n) |
Pop n stacks. | |
void | Push (int n) |
Push n stacks. | |
void | SetInfo (const std::string &key, const std::string &val) |
Set an info key with a value val . | |
std::string | GetInfo (const std::string &key) const |
Get the info key . | |
void | SetInterval (const Variable &v, const mpq_class &lb, const mpq_class &ub) |
Set the interval of v to \( [lb, ub] \) in the current box (top one in boxes_). | |
void | SetLogic (Logic logic) |
Set the current logic to logic . | |
void | SetOption (const std::string &key, const std::string &val) |
Set an option key with a value val . | |
std::string | GetOption (const std::string &key) const |
Get the option key . | |
const Config & | config () const |
Get read-only access to the configuration of the context. | |
const ScopedVector< Formula > & | assertions () const |
Get the the asserted formulas. | |
const Box & | box () const |
Get the current active box from the top of the stack of boxes. | |
const Box & | model () const |
Get a representation of a model computed by the solver in response to the last invocation of the check-sat. | |
bool | have_objective () const |
Check whether or not there is an objective function (which may be zero) to optimize. | |
const PredicateAbstractor & | predicate_abstractor () const |
Get read-only access to the predicate_abstractor of the context. | |
bool | is_max () const |
Check whether or not the objective function (if present) is a maximization. | |
bool | Verify (const Box &model) const |
Check whether the model satisfies all the assertions loaded in the context. | |
Private Attributes | |
std::unique_ptr< Impl > | impl_ |
Pointer to the implementation of the context. | |
Context class that holds the set of constraints and provide Assert/Push/Pop/CheckSat functionalities.
|
explicit |
Construct a context with config
.
If smt_solver_output
is not null, it will be used to store the output of the SMT solver as well as some statistics.
config | the configuration of the context |
Definition at line 22 of file Context.cpp.
void dlinear::Context::Assert | ( | const Formula & | f | ) |
Assert a formula f
.
The new formula is added to the box.
f | the formula to be asserted |
Definition at line 24 of file Context.cpp.
|
nodiscard |
Get the the asserted formulas.
x <= 5
is asserted, box() is updated to have this information and the formula is thrown away. Definition at line 71 of file Context.cpp.
void dlinear::Context::AssertPiecewiseLinearFunction | ( | const Variable & | var, |
const Formula & | cond, | ||
const Expression & | active, | ||
const Expression & | inactive ) |
Assert a piecewise linear function with two possible branches.
Consider a piecewise linear function that assigns either active
or inactive
to var
depending on cond
\[ \text{var} =\begin{cases} \text{active} & \text{if } cond \newline \text{inactive} & \text{otherwise} \end{cases} \]
Assigning \( \mathcal{A} = (\text{active} = \text{var}) \) and \( \mathcal{B} = (\text{var} = \text{inactive}) \), we introduce the following assertions:
\[ (\mathcal{A} \lor \neg cond) \land (\mathcal{B} \lor cond) \land (cond \lor \neg cond) \]
Note that the last clause is a tautology, but it forces the sat solver to assign a boolean value to cond and hopefully skip either \( \mathcal{A} \) or \( \mathcal{B} \).
var | the variable to be assigned |
cond | the condition to be checked |
active | the value of the variable if the condition is true |
inactive | the value of the variable if the condition is false |
Definition at line 25 of file Context.cpp.
|
nodiscard |
Get the current active box from the top of the stack of boxes.
Definition at line 66 of file Context.cpp.
LpResult dlinear::Context::CheckOpt | ( | mpq_class * | obj_lo, |
mpq_class * | obj_up ) |
Check the satisfiability of the asserted formulas, and (where possible) optimizes an objective function over them.
If a solution is found, the obj_lo
and obj_up
store the lower and upper bounds of the objective function.
[out] | obj_lo | the lower bound of the objective function |
[out] | obj_up | the upper bound of the objective function |
Definition at line 30 of file Context.cpp.
SatResult dlinear::Context::CheckSat | ( | mpq_class * | actual_precision | ) |
Check the satisfiability of the asserted formulas, and sets actual_precision
to the actual max infeasibility where appropriate.
[out] | actual_precision | initialized with the desired precision, it will be set to the lowest possible precision below the given one that satisfies the constraints. |
Definition at line 29 of file Context.cpp.
|
nodiscard |
Get read-only access to the configuration of the context.
Definition at line 65 of file Context.cpp.
void dlinear::Context::DeclareVariable | ( | const Variable & | v, |
bool | is_model_variable = true ) |
Declare a variable v
.
By default v
is considered as a model variable. If IsModelVariable
is false, it is declared as a non-model variable and will not appear in the model.
v | the variable to be declared |
is_model_variable | whether or not the variable is a model variable |
Definition at line 31 of file Context.cpp.
void dlinear::Context::DeclareVariable | ( | const Variable & | v, |
const Expression & | lb, | ||
const Expression & | ub, | ||
bool | is_model_variable = true ) |
Declare a variable v
which is bounded by an interval \( [lb, ub] \).
By default v
is considered as a model variable. If is_model_variable
is false, it is declared as a non-model variable and will not appear in the model.
v | the variable to be declared |
lb | the lower bound of the variable |
ub | the upper bound of the variable |
is_model_variable | whether or not the variable is a model variable |
Definition at line 34 of file Context.cpp.
void dlinear::Context::Exit | ( | ) |
Exit the context.
Does nothing but prints a debug message.
Definition at line 42 of file Context.cpp.
|
nodiscard |
Get the info key
.
key | the key of the info |
Definition at line 58 of file Context.cpp.
|
nodiscard |
Get the option key
.
key | the key of the option |
Definition at line 64 of file Context.cpp.
|
nodiscard |
Check whether or not there is an objective function (which may be zero) to optimize.
Definition at line 72 of file Context.cpp.
|
nodiscard |
Check whether or not the objective function (if present) is a maximization.
Definition at line 73 of file Context.cpp.
void dlinear::Context::Maximize | ( | const Expression & | f | ) |
Assert a formula maximizing a cost function f
.
f | the cost function to be maximized |
Definition at line 44 of file Context.cpp.
void dlinear::Context::Minimize | ( | const Expression & | f | ) |
Assert a formula minimizing a cost function f
.
f | the cost function to be minimized |
Definition at line 43 of file Context.cpp.
|
nodiscard |
Get a representation of a model computed by the solver in response to the last invocation of the check-sat.
Definition at line 67 of file Context.cpp.
void dlinear::Context::Pop | ( | int | n | ) |
Pop n
stacks.
n | the number of stacks to be popped |
Definition at line 46 of file Context.cpp.
const PredicateAbstractor & dlinear::Context::predicate_abstractor | ( | ) | const |
Get read-only access to the predicate_abstractor of the context.
Definition at line 70 of file Context.cpp.
void dlinear::Context::Push | ( | int | n | ) |
void dlinear::Context::SetInfo | ( | const std::string & | key, |
const std::string & | val ) |
Set an info key
with a value val
.
key | the key of the info |
val | the value of the info |
Definition at line 57 of file Context.cpp.
void dlinear::Context::SetInterval | ( | const Variable & | v, |
const mpq_class & | lb, | ||
const mpq_class & | ub ) |
Set the interval of v
to \( [lb, ub] \) in the current box (top one in boxes_).
v | the variable to be set |
lb | the lower bound of the variable |
ub | the upper bound of the variable |
Definition at line 59 of file Context.cpp.
void dlinear::Context::SetLogic | ( | Logic | logic | ) |
Set the current logic to logic
.
logic | the logic to be set |
Definition at line 62 of file Context.cpp.
void dlinear::Context::SetOption | ( | const std::string & | key, |
const std::string & | val ) |
Set an option key
with a value val
.
key | the key of the option |
val | the value of the option |
Definition at line 63 of file Context.cpp.
|
nodiscard |
Check whether the model
satisfies all the assertions loaded in the context.
In other words, verifies if it is a SAT assignment for the input variables.
model | assignment to check |
model
satisfies all assignments model
Definition at line 74 of file Context.cpp.