6#include "BoundIterator.h"
13#include "dlinear/util/exception.h"
20 : begin_bounds_it_(default_empty_vector_.cend()),
21 bounds_it_(default_empty_vector_.cend()),
22 end_bounds_it_(default_empty_vector_.cend()),
23 begin_nq_bounds_it_(default_empty_vector_.cend()),
24 nq_bounds_it_(default_empty_vector_.cend()),
25 end_nq_bounds_it_(default_empty_vector_.cend()) {
28 "Non-equal bounds iterator is out of bounds.");
32 BoundIterator::internal_iterator end_bounds_it,
33 BoundIterator::internal_iterator begin_nq_bounds_it,
34 BoundIterator::internal_iterator end_nq_bounds_it)
35 : begin_bounds_it_(begin_bounds_it),
36 bounds_it_(begin_bounds_it),
37 end_bounds_it_(
std::max(end_bounds_it, begin_bounds_it)),
38 begin_nq_bounds_it_(begin_nq_bounds_it),
39 nq_bounds_it_(begin_nq_bounds_it),
40 end_nq_bounds_it_(
std::max(end_nq_bounds_it, begin_nq_bounds_it)) {
43 "Non-equal bounds iterator is out of bounds.");
47 std::pair<BoundIterator::internal_iterator, BoundIterator::internal_iterator> nq_bounds)
48 : begin_bounds_it_(bounds.first),
49 bounds_it_(bounds.first),
50 end_bounds_it_(
std::max(bounds.second, bounds.first)),
51 begin_nq_bounds_it_(nq_bounds.first),
52 nq_bounds_it_(nq_bounds.first),
53 end_nq_bounds_it_(
std::max(nq_bounds.second, nq_bounds.first)) {
56 "Non-equal bounds iterator is out of bounds.");
59 BoundIterator::internal_iterator end_bounds_it)
60 : begin_bounds_it_(begin_bounds_it),
61 bounds_it_(begin_bounds_it),
62 end_bounds_it_(
std::max(end_bounds_it, begin_bounds_it)),
63 begin_nq_bounds_it_(default_empty_vector_.cend()),
64 nq_bounds_it_(default_empty_vector_.cend()),
65 end_nq_bounds_it_(default_empty_vector_.cend()) {
68 "Non-equal bounds iterator is out of bounds.");
71 : begin_bounds_it_(bounds.first),
72 bounds_it_(bounds.first),
73 end_bounds_it_(
std::max(bounds.second, bounds.first)),
74 begin_nq_bounds_it_(default_empty_vector_.cend()),
75 nq_bounds_it_(default_empty_vector_.cend()),
76 end_nq_bounds_it_(default_empty_vector_.cend()) {
79 "Non-equal bounds iterator is out of bounds.");
91const BoundIterator BoundIterator::operator++(
int) {
97BoundIterator &BoundIterator::operator--() {
105const BoundIterator BoundIterator::operator--(
int) {
110typename BoundIterator::value_type BoundIterator::operator[](
int i)
const {
120 auto [bound_it, end_bound_it] =
bounds();
121 for (; bound_it != end_bound_it; ++bound_it) {
122 explanation.insert(bound_it->explanation.begin(), bound_it->explanation.end());
125 auto [nq_bound_it, end_nq_bound_it] =
nq_bounds();
126 for (; nq_bound_it != end_nq_bound_it; ++nq_bound_it) {
127 explanation.insert(nq_bound_it->explanation.begin(), nq_bound_it->explanation.end());
137 auto [bound_it, end_bound_it] =
bounds();
138 for (; bound_it != end_bound_it; ++bound_it) {
140 if (lit.has_value())
explanation.insert(lit.value());
141 explanation.insert(bound_it->explanation.begin(), bound_it->explanation.end());
145 auto [nq_bound_it, end_nq_bound_it] =
nq_bounds();
146 for (; nq_bound_it != end_nq_bound_it; ++nq_bound_it) {
148 if (lit.has_value())
explanation.insert(lit.value());
149 explanation.insert(nq_bound_it->explanation.begin(), nq_bound_it->explanation.end());
155std::ostream &operator<<(std::ostream &os,
const BoundIterator &violation) {
157 os <<
"BoundIterator{";
158 for (
size_t i = 0; it; ++it, ++i) {
160 if (i + 1 < it.size()) {
const internal_iterator end_nq_bounds_it_
End iterator of the non-equal bounds.
internal_iterator nq_bounds_it_
Iterator to the current non-equal bound.
std::pair< internal_iterator, internal_iterator > nq_bounds() const
Return the pair of iterators to the non-equal bounds.
std::pair< internal_iterator, internal_iterator > bounds() const
Return the pair of iterators to the bounds.
LiteralSet explanation() const
Produce and explanation formed by all the theory literals present in the violation.
internal_iterator bounds_it_
Iterator to the current bound.
static const vector_type default_empty_vector_
Default empty vector. Used for default construction.
const internal_iterator begin_nq_bounds_it_
Begin iterator to the first non-equal bound.
BoundIterator()
Construct an empty iterator.
std::set< LiteralSet > explanations(const std::optional< Literal > &lit={}) const
Produce a set of explanations.
const internal_iterator end_bounds_it_
End iterator of the bounds.
const internal_iterator begin_bounds_it_
Begin iterator to the first bound.
Global namespace for the dlinear library.
std::set< Literal > LiteralSet
A set of literals.