dlinear
0.0.1
Delta-complete SMT solver for linear programming
|
Data structure to store the LP solver bounds in a sorted vector to determine the active lower and upper bound for the column. More...
#include <BoundVector.h>
Public Types | |
using | Bounds = SortedVector<Bound> |
Sorted vector of bounds. | |
Public Member Functions | |
BoundVector (const mpq_class &inf_l, const mpq_class &inf_u) | |
Construct a new BoundVector using inf_l as the the lower bound and inf_u as the upper bound. | |
BoundIterator | AddBound (const Bound &bound) |
Add a new bound to the vector. | |
BoundIterator | AddBound (const mpq_class &value, LpColBound lp_bound, const Literal &theory_lit, const LiteralSet &explanation={}) |
Add a new bound to the vector. | |
bool | RemoveBound (const Bound &bound) |
Remove bound from the vector if it is present. | |
bool | RemoveBound (const mpq_class &value, LpColBound lp_bound, const Literal &theory_lit, const LiteralSet &explanation={}) |
Remove the bound with the given value , lp_bound , theory_lit and explanation from the vector if it is present. | |
void | SetLowerBound (const mpq_class &value) |
Manually set the active lower bound to value . | |
void | SetUpperBound (const mpq_class &value) |
Manually set the active upper bound to value . | |
void | SetBounds (const mpq_class &lb, const mpq_class &ub) |
Manually set the active bounds to lb and ub . | |
void | Clear () |
Clear the vector and reset the active bounds. | |
int | n_lower_bounds () const |
Return the number of lower bounds in the vector, both strict and non-strict. | |
int | n_upper_bounds () const |
Return the number of upper bounds in the vector, both strict and non-strict. | |
BoundIterator | GetActiveBound () const |
Return a BoundIterator containing a minimal set of bounds enclosing the interval [active_lower_bound_, active_upper_bound_] as well as all the not-equal constraints in that interval. | |
BoundIterator | GetActiveBound (const mpq_class &value) const |
Return a BoundIterator containing a minimal set of bounds enclosing the interval [value , value ] as well as all the not-equal constraints in that interval. | |
BoundIterator | GetActiveBounds () const |
Return a BoundIterator containing a set of bounds enclosing the interval [active_lower_bound_, active_upper_bound_] as well as all the not-equal constraints in that interval. | |
BoundIterator | GetActiveBounds (const mpq_class &value) const |
Return a BoundIterator containing a set of bounds enclosing the interval [value , value ] as well as all the not-equal constraints in that interval. | |
void | GetActiveExplanation (LiteralSet &explanation) const |
Produce a LiteralSet containing all the active bounds that can be used as an explanation. | |
LiteralSet | GetActiveExplanation () const |
Produce a LiteralSet containing all the active bounds that can be used as an explanation. | |
void | GetActiveEqExplanation (LiteralSet &explanation) const |
Produce a LiteralSet containing all the active bounds that can be used as an explanation, only if the variable presents an equality active bound. | |
LiteralSet | GetActiveEqExplanation () const |
Produce a LiteralSet containing all the active bounds that can be used as an explanation, only if the variable presents an equality active bound. | |
std::pair< const mpq_class &, const mpq_class & > | GetActiveBoundsValue () const |
Return a pair containing the active lower and upper bound. | |
const Bounds & | bounds () const |
Get read-only access to the bounds vector of the BoundVector. | |
const Bounds & | nq_bounds () const |
Get read-only access to the non-equal-to bounds vector of the BoundVector. | |
const mpq_class & | inf_l () const |
Get read-only access to the negative lower bound of the BoundVector. | |
const mpq_class & | inf_u () const |
Get read-only access to the positive infinity bound of the BoundVector. | |
const mpq_class & | active_lower_bound () const |
Get read-only access to the active_lower_bound of the BoundVector. | |
const mpq_class & | active_upper_bound () const |
Get read-only access to the active_upper_bound of the BoundVector. | |
const mpq_class * | GetActiveEqualityBound () const |
Return the active equality bound. | |
BoundIterator | ViolatedBounds (const mpq_class &value, LpColBound lp_bound) const |
Check if the combination of value and lp_bound violates any of the existing bounds. | |
bool | ViolatedNqBounds () const |
Check if the active bounds violate any of the existing non-equality bounds. | |
bool | ViolatedNqBounds (const mpq_class &lb, const mpq_class &ub) const |
Check if the new combination of lb and ub violates any of the existing non-equality bounds. | |
bool | IsActiveEquality (const mpq_class &value) const |
Check if value represents an equality bound. | |
bool | IsLowerBound (const mpq_class &value) const |
Check if value represents a lower bound. | |
bool | IsUpperBound (const mpq_class &value) const |
Check if value represents an upper bound. | |
bool | IsLowerBounded () const |
Check if the vector has a lower bound greater than inf_l_. | |
bool | IsUpperBounded () const |
Check if the vector has an upper bound lower than inf_u_. | |
bool | IsBounded () const |
Check if the vector has an upper bound and lower bound. | |
Private Member Functions | |
Bounds::const_iterator | LowerBoundEnd () const |
Return an iterator over bounds_ after the last lower bound and to the first upper bound. | |
BoundIterator | GetActiveBound (const mpq_class &lb, const mpq_class &ub) const |
Return a BoundIterator containing a minimal set of bounds enclosing the interval [lb , ub ] as well as all the not-equal constraints in that interval. | |
BoundIterator | GetActiveBounds (const mpq_class &lb, const mpq_class &ub) const |
Return a BoundIterator containing the set of bounds enclosing the interval [lb , ub ] as well as all the not-equal constraints in that interval. | |
Private Attributes | |
std::size_t | n_lower_bounds_ |
Number of lower bounds, both strict and non-strict. | |
Bounds | bounds_ |
Equality and inequality bounds. | |
Bounds | nq_bounds_ |
Non-equality bounds. | |
const mpq_class * | inf_l_ |
Starting lower bound. | |
const mpq_class * | inf_u_ |
Starting upper bound. | |
const mpq_class * | active_lower_bound_ |
Active lower bound. | |
const mpq_class * | active_upper_bound_ |
Active upper bound. | |
Data structure to store the LP solver bounds in a sorted vector to determine the active lower and upper bound for the column.
Every time a new bound is added, it checks if it violates any of the existing bounds. If a violation is detected, it returns the iterator to the first and last violated bound. The violating bound is not added and the vector remains unchanged.
Definition at line 48 of file BoundVector.h.
dlinear::BoundVector::BoundVector | ( | const mpq_class & | inf_l, |
const mpq_class & | inf_u ) |
Construct a new BoundVector using inf_l
as the the lower bound and inf_u
as the upper bound.
inf_l | lower bound |
inf_u | upper bound |
Definition at line 27 of file BoundVector.cpp.
|
inlinenodiscard |
Get read-only access to the active_lower_bound of the BoundVector.
Definition at line 225 of file BoundVector.h.
|
inlinenodiscard |
Get read-only access to the active_upper_bound of the BoundVector.
Definition at line 227 of file BoundVector.h.
BoundIterator dlinear::BoundVector::AddBound | ( | const Bound & | bound | ) |
Add a new bound to the vector.
The bound will be sorted in the vector according to its value and type with the goal of identifying violating bounds as fast a possible.
bound | bound to add |
Definition at line 36 of file BoundVector.cpp.
BoundIterator dlinear::BoundVector::AddBound | ( | const mpq_class & | value, |
LpColBound | lp_bound, | ||
const Literal & | theory_lit, | ||
const LiteralSet & | explanation = {} ) |
Add a new bound to the vector.
The bound will be sorted in the vector according to its value and type with the goal of identifying violating bounds as fast a possible. The idx
it is ignored by the BoundVector, but can be used by the caller to identify the bound. Before adding a new bound, a check is performed to ensure it does not violate any of the existing bounds. If a violation is detected, a BoundIterator containing all the violated bounds is returned instead.
value | value of the new bound |
lp_bound | type of the new bound |
theory_lit | theory literal associated with the bound |
explanation | set of theory literals justifying the existence of the bound |
Definition at line 39 of file BoundVector.cpp.
|
inlinenodiscard |
Get read-only access to the bounds vector of the BoundVector.
Definition at line 217 of file BoundVector.h.
void dlinear::BoundVector::Clear | ( | ) |
Clear the vector and reset the active bounds.
Active bounds are set to inf_l_ and inf_u_.
Definition at line 216 of file BoundVector.cpp.
|
nodiscard |
Return a BoundIterator containing a minimal set of bounds enclosing the interval [active_lower_bound_, active_upper_bound_] as well as all the not-equal constraints in that interval.
Definition at line 259 of file BoundVector.cpp.
|
nodiscardprivate |
Return a BoundIterator containing a minimal set of bounds enclosing the interval [lb
, ub
] as well as all the not-equal constraints in that interval.
lb | lower bound |
ub | upper bound |
Definition at line 261 of file BoundVector.cpp.
|
nodiscard |
Return a BoundIterator containing a minimal set of bounds enclosing the interval [value
, value
] as well as all the not-equal constraints in that interval.
value | value to check |
Definition at line 260 of file BoundVector.cpp.
|
nodiscard |
Return a BoundIterator containing a set of bounds enclosing the interval [active_lower_bound_, active_upper_bound_] as well as all the not-equal constraints in that interval.
Definition at line 276 of file BoundVector.cpp.
|
nodiscardprivate |
Return a BoundIterator containing the set of bounds enclosing the interval [lb
, ub
] as well as all the not-equal constraints in that interval.
lb | lower bound |
ub | upper bound |
Definition at line 280 of file BoundVector.cpp.
|
nodiscard |
Return a BoundIterator containing a set of bounds enclosing the interval [value
, value
] as well as all the not-equal constraints in that interval.
value | value to check |
Definition at line 279 of file BoundVector.cpp.
|
nodiscard |
Return a pair containing the active lower and upper bound.
Definition at line 331 of file BoundVector.cpp.
|
nodiscard |
Produce a LiteralSet containing all the active bounds that can be used as an explanation, only if the variable presents an equality active bound.
Definition at line 318 of file BoundVector.cpp.
void dlinear::BoundVector::GetActiveEqExplanation | ( | LiteralSet & | explanation | ) | const |
Produce a LiteralSet containing all the active bounds that can be used as an explanation, only if the variable presents an equality active bound.
explanation | set of literal corresponding to the explanation |
Definition at line 323 of file BoundVector.cpp.
|
inlinenodiscard |
Return the active equality bound.
An active equality bound is obtained when the active lower bound is equal to the active upper bound. If such condition is false, a nullptr is returned.
Definition at line 237 of file BoundVector.h.
|
nodiscard |
Produce a LiteralSet containing all the active bounds that can be used as an explanation.
theory_bound_to_lit | map between the bound id and the theory literal |
Definition at line 307 of file BoundVector.cpp.
void dlinear::BoundVector::GetActiveExplanation | ( | LiteralSet & | explanation | ) | const |
Produce a LiteralSet containing all the active bounds that can be used as an explanation.
explanation | set of literal corresponding to the explanation |
Definition at line 312 of file BoundVector.cpp.
|
inlinenodiscard |
Get read-only access to the negative lower bound of the BoundVector.
Definition at line 221 of file BoundVector.h.
|
inlinenodiscard |
Get read-only access to the positive infinity bound of the BoundVector.
Definition at line 223 of file BoundVector.h.
|
nodiscard |
Check if value
represents an equality bound.
value | value to check |
value
represents an equality bound value
does not represent an equality bound Definition at line 224 of file BoundVector.cpp.
|
nodiscard |
Check if the vector has an upper bound and lower bound.
Definition at line 253 of file BoundVector.cpp.
|
nodiscard |
Check if value
represents a lower bound.
value | value to check |
value
represents a lower bound value
does not represent a lower bound Definition at line 229 of file BoundVector.cpp.
|
nodiscard |
Check if the vector has a lower bound greater than inf_l_.
Definition at line 243 of file BoundVector.cpp.
|
nodiscard |
Check if value
represents an upper bound.
value | value to check |
value
represents an upper bound value
does not represent an upper bound Definition at line 236 of file BoundVector.cpp.
|
nodiscard |
Check if the vector has an upper bound lower than inf_u_.
Definition at line 248 of file BoundVector.cpp.
|
nodiscardprivate |
Return an iterator over bounds_ after the last lower bound and to the first upper bound.
Definition at line 255 of file BoundVector.cpp.
|
inlinenodiscard |
Return the number of lower bounds in the vector, both strict and non-strict.
Definition at line 146 of file BoundVector.h.
|
inlinenodiscard |
Return the number of upper bounds in the vector, both strict and non-strict.
Definition at line 151 of file BoundVector.h.
|
inlinenodiscard |
Get read-only access to the non-equal-to bounds vector of the BoundVector.
Definition at line 219 of file BoundVector.h.
bool dlinear::BoundVector::RemoveBound | ( | const Bound & | bound | ) |
Remove bound
from the vector if it is present.
bound | bound to remove |
Definition at line 107 of file BoundVector.cpp.
bool dlinear::BoundVector::RemoveBound | ( | const mpq_class & | value, |
LpColBound | lp_bound, | ||
const Literal & | theory_lit, | ||
const LiteralSet & | explanation = {} ) |
Remove the bound with the given value
, lp_bound
, theory_lit
and explanation
from the vector if it is present.
value | value of the bound |
lp_bound | type of the bound |
theory_lit | theory literal associated with the bound |
explanation | set of theory literals justifying the existence of the bound |
Definition at line 103 of file BoundVector.cpp.
void dlinear::BoundVector::SetBounds | ( | const mpq_class & | lb, |
const mpq_class & | ub ) |
Manually set the active bounds to lb
and ub
.
The active bounds will be set to lb
and ub
only if lb
is greater than the active lower bound and ub
is less than the active upper bound respectively.
lb | new lower bound |
ub | new upper bound |
std::runtime_error | if after setting the bounds, the lower bound is greater than the upper bound |
Definition at line 347 of file BoundVector.cpp.
void dlinear::BoundVector::SetLowerBound | ( | const mpq_class & | value | ) |
Manually set the active lower bound to value
.
The method won't have any effect if value
is less than the active lower bound.
value | value of the new lower bound |
std::runtime_error | if the value is greater than the active upper bound |
Definition at line 335 of file BoundVector.cpp.
void dlinear::BoundVector::SetUpperBound | ( | const mpq_class & | value | ) |
Manually set the active upper bound to value
.
The method won't have any effect if value
is greater than the active upper bound.
value | value of the new upper bound |
std::runtime_error | if the value is less than the active lower bound |
Definition at line 341 of file BoundVector.cpp.
|
nodiscard |
Check if the combination of value
and lp_bound
violates any of the existing bounds.
If that is the case, a non-empty BoundIterator containing all the violated bounds is returned.
value | value of the bound |
lp_bound | type of the bound |
Definition at line 147 of file BoundVector.cpp.
|
nodiscard |
Check if the active bounds violate any of the existing non-equality bounds.
Definition at line 196 of file BoundVector.cpp.
|
nodiscard |
Check if the new combination of lb
and ub
violates any of the existing non-equality bounds.
lb | lower bound |
ub | upper bound |
lb
and ub
violates any of the existing non-equality bounds Definition at line 206 of file BoundVector.cpp.