dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
BoundVector.h
1
7#pragma once
8
9#include <compare>
10#include <cstddef>
11#include <iosfwd>
12#include <map>
13#include <utility>
14#include <vector>
15
16#include "dlinear/libs/libgmp.h"
17#include "dlinear/solver/BoundIterator.h"
18#include "dlinear/solver/LpColBound.h"
19#include "dlinear/symbolic/literal.h"
20#include "dlinear/util/SortedVector.hpp"
21
22namespace dlinear {
23
49 public:
51
57 BoundVector(const mpq_class& inf_l, const mpq_class& inf_u);
58
70 BoundIterator AddBound(const Bound& bound);
87 BoundIterator AddBound(const mpq_class& value, LpColBound lp_bound, const Literal& theory_lit,
88 const LiteralSet& explanation = {});
95 bool RemoveBound(const Bound& bound);
106 bool RemoveBound(const mpq_class& value, LpColBound lp_bound, const Literal& theory_lit,
107 const LiteralSet& explanation = {});
115 void SetLowerBound(const mpq_class& value);
123 void SetUpperBound(const mpq_class& value);
133 void SetBounds(const mpq_class& lb, const mpq_class& ub);
134
140 void Clear();
141
146 [[nodiscard]] int n_lower_bounds() const { return n_lower_bounds_; }
151 [[nodiscard]] int n_upper_bounds() const { return static_cast<int>(bounds_.size()) - n_lower_bounds_; }
159 [[nodiscard]] BoundIterator GetActiveBound() const;
167 [[nodiscard]] BoundIterator GetActiveBound(const mpq_class& value) const;
176 [[nodiscard]] BoundIterator GetActiveBounds() const;
185 [[nodiscard]] BoundIterator GetActiveBounds(const mpq_class& value) const;
190 void GetActiveExplanation(LiteralSet& explanation) const;
196 [[nodiscard]] LiteralSet GetActiveExplanation() const;
203 void GetActiveEqExplanation(LiteralSet& explanation) const;
210 [[nodiscard]] LiteralSet GetActiveEqExplanation() const;
215 [[nodiscard]] std::pair<const mpq_class&, const mpq_class&> GetActiveBoundsValue() const;
217 [[nodiscard]] const Bounds& bounds() const { return bounds_; }
219 [[nodiscard]] const Bounds& nq_bounds() const { return nq_bounds_; }
221 [[nodiscard]] const mpq_class& inf_l() const { return *inf_l_; }
223 [[nodiscard]] const mpq_class& inf_u() const { return *inf_u_; }
225 [[nodiscard]] const mpq_class& active_lower_bound() const { return *active_lower_bound_; }
227 [[nodiscard]] const mpq_class& active_upper_bound() const { return *active_upper_bound_; }
228
237 [[nodiscard]] const mpq_class* GetActiveEqualityBound() const {
239 }
240
241 [[nodiscard]] const Bound& operator[](std::size_t idx) const { return bounds_[idx]; }
242
252 [[nodiscard]] BoundIterator ViolatedBounds(const mpq_class& value, LpColBound lp_bound) const;
258 [[nodiscard]] bool ViolatedNqBounds() const;
266 [[nodiscard]] bool ViolatedNqBounds(const mpq_class& lb, const mpq_class& ub) const;
267
274 [[nodiscard]] bool IsActiveEquality(const mpq_class& value) const;
281 [[nodiscard]] bool IsLowerBound(const mpq_class& value) const;
282
289 [[nodiscard]] bool IsUpperBound(const mpq_class& value) const;
295 [[nodiscard]] bool IsLowerBounded() const;
301 [[nodiscard]] bool IsUpperBounded() const;
309 [[nodiscard]] bool IsBounded() const;
310
311 private:
316 [[nodiscard]] Bounds::const_iterator LowerBoundEnd() const;
326 [[nodiscard]] BoundIterator GetActiveBound(const mpq_class& lb, const mpq_class& ub) const;
337 [[nodiscard]] BoundIterator GetActiveBounds(const mpq_class& lb, const mpq_class& ub) const;
338
339 std::size_t n_lower_bounds_;
342 const mpq_class* inf_l_;
343 const mpq_class* inf_u_;
344 const mpq_class* active_lower_bound_;
345 const mpq_class* active_upper_bound_;
346};
347
348using BoundVectorMap = std::map<Variable, BoundVector>;
349using BoundVectorVector = std::vector<BoundVector>;
350
351std::ostream& operator<<(std::ostream& os, const BoundVector& bounds_vector);
352std::ostream& operator<<(std::ostream& os, const BoundVectorMap& bounds_vector_map);
353std::ostream& operator<<(std::ostream& os, const BoundVectorVector& bounds_vector_vector);
354
355} // namespace dlinear
356
357#ifdef DLINEAR_INCLUDE_FMT
358
359#include "dlinear/util/logging.h"
360
361OSTREAM_FORMATTER(dlinear::BoundIterator)
362OSTREAM_FORMATTER(dlinear::BoundVector)
363OSTREAM_FORMATTER(dlinear::BoundVectorMap)
364OSTREAM_FORMATTER(dlinear::BoundVectorVector)
365
366#endif
BoundIterator class.
Data structure to store the LP solver bounds in a sorted vector to determine the active lower and upp...
Definition BoundVector.h:48
const mpq_class * active_upper_bound_
Active upper bound.
void SetUpperBound(const mpq_class &value)
Manually set the active upper bound to value.
BoundIterator GetActiveBounds() const
Return a BoundIterator containing a set of bounds enclosing the interval [active_lower_bound_,...
void SetLowerBound(const mpq_class &value)
Manually set the active lower bound to value.
int n_lower_bounds() const
Return the number of lower bounds in the vector, both strict and non-strict.
const mpq_class * active_lower_bound_
Active lower bound.
std::size_t n_lower_bounds_
Number of lower bounds, both strict and non-strict.
Bounds nq_bounds_
Non-equality bounds.
const mpq_class * GetActiveEqualityBound() const
Return the active equality bound.
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.
const mpq_class & active_lower_bound() const
Get read-only access to the active_lower_bound of the BoundVector.
bool RemoveBound(const Bound &bound)
Remove bound from the vector if it is present.
Bounds::const_iterator LowerBoundEnd() const
Return an iterator over bounds_ after the last lower bound and to the first upper bound.
BoundIterator AddBound(const Bound &bound)
Add a new bound to the vector.
const mpq_class & active_upper_bound() const
Get read-only access to the active_upper_bound of the BoundVector.
LiteralSet GetActiveExplanation() const
Produce a LiteralSet containing all the active bounds that can be used as an explanation.
bool IsUpperBound(const mpq_class &value) const
Check if value represents an upper bound.
bool IsActiveEquality(const mpq_class &value) const
Check if value represents an equality bound.
bool IsBounded() const
Check if the vector has an upper bound and lower bound.
void Clear()
Clear the vector and reset the active bounds.
const mpq_class * inf_u_
Starting upper 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 IsLowerBound(const mpq_class &value) const
Check if value represents a lower 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_
Starting lower bound.
int n_upper_bounds() const
Return the number of upper bounds in the vector, both strict and non-strict.
bool IsLowerBounded() const
Check if the vector has a lower bound greater than inf_l_.
Bounds bounds_
Equality and inequality bounds.
bool IsUpperBounded() const
Check if the vector has an upper bound lower than inf_u_.
const mpq_class & inf_u() const
Get read-only access to the positive infinity bound of the BoundVector.
bool ViolatedNqBounds() const
Check if the active bounds violate any of the existing non-equality bounds.
BoundIterator GetActiveBound() const
Return a BoundIterator containing a minimal set of bounds enclosing the interval [active_lower_bound_...
LiteralSet GetActiveEqExplanation() const
Produce a LiteralSet containing all the active bounds that can be used as an explanation,...
const mpq_class & inf_l() const
Get read-only access to the negative lower bound of the BoundVector.
void SetBounds(const mpq_class &lb, const mpq_class &ub)
Manually set the active bounds to lb and ub.
size_t size() const
Get read-only access to the size of the vector.
typename std::vector< Bound >::const_iterator const_iterator
Global namespace for the dlinear library.
LpColBound
Describe the bound of a linear program variable.
Definition LpColBound.h:21
std::set< Literal > LiteralSet
A set of literals.
Definition literal.h:28
Tuple containing the value, bound type and theory literal associated with the bound.
Definition Bound.h:24
A literal is a variable with an associated truth value, indicating whether it is true or false.
Definition literal.h:24