dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
PiecewiseLinearConstraint.h
1
7#pragma once
8
9#include <istream>
10#include <optional>
11
12#include "dlinear/libs/libgmp.h"
13#include "dlinear/solver/BoundPreprocessor.h"
14#include "dlinear/solver/PiecewiseConstraintState.h"
15#include "dlinear/symbolic/literal.h"
16#include "dlinear/symbolic/symbolic.h"
17
18namespace dlinear {
19
36 public:
37 static const Expression zero_soi;
38
50 explicit PiecewiseLinearConstraint(const mpq_class* lb = nullptr, const mpq_class* ub = nullptr,
51 Variable active_var = {}, Variable inactive_var = {}, Variable theory_var = {},
52 Expression active_soi = {0}, Expression inactive_soi = {0},
54 virtual ~PiecewiseLinearConstraint() = default;
55
62 virtual std::set<LiteralSet> TightenBounds(BoundPreprocessor& preprocessor) = 0;
63
69 virtual std::ostream& Print(std::ostream& os) const = 0;
70
75 [[nodiscard]] virtual LiteralSet Assumptions() const = 0;
81 [[nodiscard]] virtual LiteralSet LearnedClauses() const = 0;
82
91 void UpdateBounds(const mpq_class& lb, const mpq_class& ub);
102 void UpdateBounds(const mpq_class* lb, const mpq_class* ub);
108 virtual void UpdateLowerBound(const mpq_class* lb);
114 virtual void UpdateUpperBound(const mpq_class* ub);
115
125 [[nodiscard]] mpq_class Cost(const Environment& env) const;
135 [[nodiscard]] mpq_class Cost(const Environment& env, bool active) const;
136
138 [[nodiscard]] bool has_lower_bound() const { return lower_bound_ != nullptr; }
140 [[nodiscard]] bool has_upper_bound() const { return upper_bound_ != nullptr; }
142 [[nodiscard]] bool fixed() const {
144 }
146 [[nodiscard]] const mpq_class& lower_bound() const;
148 [[nodiscard]] const mpq_class& upper_bound() const;
150 [[nodiscard]] const Variable& active_var() const { return active_var_; }
152 [[nodiscard]] const Variable& inactive_var() const { return inactive_var_; }
154 [[nodiscard]] const Variable& theory_var() const { return theory_var_; }
156 [[nodiscard]] const Expression& active_soi() const { return active_soi_; }
158 [[nodiscard]] const Expression& inactive_soi() const { return inactive_soi_; }
163 [[nodiscard]] const Expression& soi() const;
165 [[nodiscard]] PiecewiseConstraintState state() const { return state_; }
166
167 protected:
168 const mpq_class* lower_bound_;
169 const mpq_class* upper_bound_;
170
172 const Variable
175
178
180};
181
182std::ostream& operator<<(std::ostream& os, const PiecewiseLinearConstraint& gc);
183
184} // namespace dlinear
185
186#ifdef DLINEAR_INCLUDE_FMT
187
188#include "dlinear/util/logging.h"
189
190OSTREAM_FORMATTER(dlinear::PiecewiseLinearConstraint)
191
192#endif
This class uses some basic algebraic operations to preprocess the constraints and identify violations...
A piecewise linear constraint is a constraint that assumes different linear functions depending on th...
virtual void UpdateLowerBound(const mpq_class *lb)
Update the lower bounds of the constraint.
virtual void UpdateUpperBound(const mpq_class *ub)
Update the upper bounds of the constraint.
bool fixed() const
Check whether the constraint is fixed.
PiecewiseLinearConstraint(const mpq_class *lb=nullptr, const mpq_class *ub=nullptr, Variable active_var={}, Variable inactive_var={}, Variable theory_var={}, Expression active_soi={0}, Expression inactive_soi={0}, PiecewiseConstraintState state=PiecewiseConstraintState::NOT_FIXED)
Construct a new Piecewise Linear Constraint object.
bool has_lower_bound() const
Check whether the constraint is lower bounded.
const Variable & inactive_var() const
Get read-only access to the boolean variable associated with the theory literal of the constraint.
const Variable & active_var() const
Get read-only access to the boolean variable associated with the theory literal of the constraint.
const Variable & theory_var() const
Get read-only access to the theory variable of the constraint.
void UpdateBounds(const mpq_class &lb, const mpq_class &ub)
Update the bounds of the constraint.
const mpq_class * lower_bound_
Lower bound of the constraint.
const Variable theory_var_
Theory variable .
static const Expression zero_soi
Expression used as a soi if the constraint is not fixed yet.
virtual std::ostream & Print(std::ostream &os) const =0
Print the constraint on the standard output.
const Variable active_var_
Boolean variable associated with the theory literal.
mpq_class Cost(const Environment &env) const
Calculate the cost of the violation of the constraint.
virtual LiteralSet Assumptions() const =0
The assumptions used to guide the SAT solver towards the most promising sub-problems.
PiecewiseConstraintState state_
State of the constraint.
bool has_upper_bound() const
Check whether the constraint is upper bounded.
const Expression & active_soi() const
Get read-only access to the expression of the constraint.
PiecewiseConstraintState state() const
Get read-only access to the state of the constraint.
const Expression & inactive_soi() const
Get read-only access to the expression of the constraint.
const mpq_class & lower_bound() const
Get read-only access to the lower bound of the constraint.
virtual LiteralSet LearnedClauses() const =0
Produce some learned clauses the SAT solver will use to prune the sub-problems this piecewise constra...
const mpq_class * upper_bound_
Upper bound of the constraint.
virtual std::set< LiteralSet > TightenBounds(BoundPreprocessor &preprocessor)=0
Use the preprocessor to tighten the bounds of the constraint and hopefully fix its state to either ac...
const Variable inactive_var_
Boolean variable associated with the theory literal.
const mpq_class & upper_bound() const
Get read-only access to the upper bound of the constraint.
Represents a symbolic environment (mapping from a variable to a value).
Represents a symbolic form of an expression.
Represents a symbolic variable.
Global namespace for the dlinear library.
PiecewiseConstraintState
State a piecewise constraint can be in.
@ ACTIVE
The constraint is active.
@ INACTIVE
The constraint is inactive.
@ NOT_FIXED
The constraint is not fixed yet.
std::set< Literal > LiteralSet
A set of literals.
Definition literal.h:28