dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
BitIncrementIterator.h
1
9#pragma once
10
11#include <algorithm>
12#include <cstddef>
13#include <iosfwd>
14#include <iterator>
15#include <vector>
16
17namespace dlinear {
18
59 public:
60 using iterator_category = std::input_iterator_tag;
61 using value_type = std::vector<bool>;
62 using reference = value_type const &;
63 using pointer = value_type const *;
64 using difference_type = ptrdiff_t;
65
73 explicit BitIncrementIterator(std::size_t n)
74 : vector_(n, false), fixed_(n, false), starting_vector_(n, false), ending_vector_(n, true) {}
82 explicit BitIncrementIterator(std::vector<bool> starting_value);
83
84 explicit operator bool() const { return !vector_.empty(); }
85
86 pointer operator->() const { return &vector_; }
87 reference operator*() const { return vector_; }
88
89 bool operator==(const BitIncrementIterator &rhs) const { return vector_ == rhs.vector_; }
90 bool operator!=(const BitIncrementIterator &rhs) const { return vector_ != rhs.vector_; }
91
92 BitIncrementIterator &operator++();
93 const BitIncrementIterator operator++(int);
94
95 BitIncrementIterator &operator--();
96 const BitIncrementIterator operator--(int);
97
98 bool operator[](std::size_t i) const;
99
110 [[nodiscard]] bool IsFixed(std::size_t i) const { return fixed_[i]; }
111
121 void Set(std::size_t i, bool value, bool force = false) { vector_[i] = force || !fixed_[i] ? value : vector_[i]; }
122
130 void SetFixed(std::size_t i, bool fixed) { fixed_[i] = fixed; }
131
145 bool Learn(std::size_t i);
160 bool Learn(std::size_t i, bool value);
161
162 private:
167 void ResetNonFixedRight(std::size_t start_pos = 0);
172 void ResetNonFixedLeft(std::size_t start_pos);
176 void ResetNonFixed();
184 [[nodiscard]] bool IsDone() const;
185
193 void UpdateVector(std::size_t i, bool value);
194
195 std::vector<bool> vector_;
196 std::vector<bool> fixed_;
197 std::vector<bool> starting_vector_;
198 std::vector<bool> ending_vector_;
199};
200
201std::vector<bool> &operator++(std::vector<bool> &vector);
202std::vector<bool> &operator--(std::vector<bool> &vector);
203std::ostream &operator<<(std::ostream &os, const BitIncrementIterator &it);
204
205} // namespace dlinear
206
207#ifdef DLINEAR_INCLUDE_FMT
208
209#include "dlinear/util/logging.h"
210
211OSTREAM_FORMATTER(dlinear::BitIncrementIterator)
212
213#endif
BitIncrementIterator class.
std::vector< bool > starting_vector_
Vector to store the starting value of the iterator.
void ResetNonFixedLeft(std::size_t start_pos)
Reset all the non-fixed bits to the left of start_pos to their starting value.
bool IsDone() const
Check if the iterator is done.
bool Learn(std::size_t i)
Learn the value of the bit at position i by inverting the bit.
void ResetNonFixedRight(std::size_t start_pos=0)
Reset all the non-fixed bits to the right of start_pos to their starting value.
void ResetNonFixed()
Reset all the non-fixed bits in the vector to their starting value.
std::vector< bool > ending_vector_
Vector to store the ending value of the iterator.
void SetFixed(std::size_t i, bool fixed)
Set whether the i 'th bit of the vector is fixed.
std::vector< bool > vector_
The bit vector that will assume all the possible values.
void Set(std::size_t i, bool value, bool force=false)
Set the i 't bit of the vector to value.
BitIncrementIterator(std::size_t n)
Construct a new BitIncrementIterator object.
bool IsFixed(std::size_t i) const
Check if the bit at position i is fixed.
bool Learn(std::size_t i, bool value)
Learn the value of the bit at position i by setting the bit to value.
void UpdateVector(std::size_t i, bool value)
After a Learn operation to set the i 'th bit to value, update the vector.
std::vector< bool > fixed_
Vector to indicate the fixed bits.
Global namespace for the dlinear library.