dlinear
0.0.1
Delta-complete SMT solver for linear programming
|
BitIncrementIterator class. More...
#include <BitIncrementIterator.h>
Public Member Functions | |
BitIncrementIterator (std::size_t n) | |
Construct a new BitIncrementIterator object. | |
BitIncrementIterator (std::vector< bool > starting_value) | |
Construct a new BitIncrementIterator object. | |
bool | IsFixed (std::size_t i) const |
Check if the bit at position i is fixed. | |
void | Set (std::size_t i, bool value, bool force=false) |
Set the i 't bit of the vector to value . | |
void | SetFixed (std::size_t i, bool fixed) |
Set whether the i 'th bit of the vector is fixed. | |
bool | Learn (std::size_t i) |
Learn the value of the bit at position i by inverting the bit. | |
bool | Learn (std::size_t i, bool value) |
Learn the value of the bit at position i by setting the bit to value . | |
Private Member Functions | |
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 | ResetNonFixedLeft (std::size_t start_pos) |
Reset all the non-fixed bits to the left of start_pos to their starting value. | |
void | ResetNonFixed () |
Reset all the non-fixed bits in the vector to their starting value. | |
bool | IsDone () const |
Check if the iterator is done. | |
void | UpdateVector (std::size_t i, bool value) |
After a Learn operation to set the i 'th bit to value , update the vector. | |
BitIncrementIterator class.
The BitIncrementIterator class is an abstraction used to iterate over all the possible bit vectors of a given size. It stores a vector of booleans and each time it is incremented, it changes the vector to the next possible bit vector. The result simulates the increment operation of a binary number. If the iterator is incremented when boolean vector if filled with true, the vector itself is cleared and the iterator is considered done.
The default behaviour of this class ensures full-exploration-guarantee
: all possible configuration the bit vector can be in will be explored. Using any Learn method will continue to maintain the guarantee over the now halved configuration space, but some previously visited configuration may appear again.
Definition at line 58 of file BitIncrementIterator.h.
|
inlineexplicit |
Construct a new BitIncrementIterator object.
The vector is initialized with n
bits set to false. If n
is 0, the vector is empty and is considered done immediately.
n | number of bits in the vector |
Definition at line 73 of file BitIncrementIterator.h.
|
explicit |
Construct a new BitIncrementIterator object.
The vector is initialized with the value of starting_value
. After enumerating all possible boolean vectors, the iterator will terminate and the vector will be cleared.
starting_value | vector of booleans to initialize the iterator with |
Definition at line 35 of file BitIncrementIterator.cpp.
|
nodiscardprivate |
Check if the iterator is done.
This happens when the vector is filled with true in every non-fixed position.
Definition at line 102 of file BitIncrementIterator.cpp.
|
inlinenodiscard |
Check if the bit at position i
is fixed.
A bit is fixed if it is set to a specific value using the Learn method. A fixed bit's value cannot be changed anymore by the increment operation.
i | index of the bit to check. The index must be in the range [0, n), big endian order. |
std::out_of_range | if i is out of range |
Definition at line 110 of file BitIncrementIterator.h.
bool dlinear::BitIncrementIterator::Learn | ( | std::size_t | i | ) |
Learn the value of the bit at position i
by inverting the bit.
Invert the bit at position i
and fix it to the new value. A fixed bit's value cannot be changed anymore by the increment operation.
full-exploration-guarantee
. If you want to avoid this behaviour, use Set and SetFixed manually. i | index of the bit to check. The index must be in the range [0, n), big endian order. |
std::out_of_range | if i is out of range |
bool dlinear::BitIncrementIterator::Learn | ( | std::size_t | i, |
bool | value ) |
Learn the value of the bit at position i
by setting the bit to value
.
Set the value of the bit at position i
to value
and fix it to the new value. A fixed bit's value cannot be changed anymore by the increment operation.
full-exploration-guarantee
. If you want to avoid this behaviour, use Set and SetFixed manually. i | index of the bit to check. The index must be in the range [0, n), big endian order. |
value | value to set the bit to |
value
std::out_of_range | if i is out of range |
|
private |
Reset all the non-fixed bits to the left of start_pos
to their starting value.
start_pos | starting position. The index must be in the range [0, n), big endian order. |
Definition at line 116 of file BitIncrementIterator.cpp.
|
private |
Reset all the non-fixed bits to the right of start_pos
to their starting value.
start_pos | starting position. The index must be in the range [0, n), big endian order. |
Definition at line 110 of file BitIncrementIterator.cpp.
|
inline |
Set the i
't bit of the vector to value
.
If the bit was fixed, no operation will be performed unless force
is specified.
full-exploration-guarantee
. i | index of the bit to change |
value | new value of the bit |
force | whether to ignore if the bit is fixed. This will not change it's fixed status |
Definition at line 121 of file BitIncrementIterator.h.
|
inline |
Set whether the i
'th bit of the vector is fixed.
full-exploration-guarantee
. i | index of the bit to make fixed or un-fixed |
fixed | whether the bit should be fixed or not |
Definition at line 130 of file BitIncrementIterator.h.
|
private |
After a Learn operation to set the i
'th bit to value
, update the vector.
Set the i
'th bit to value
, potentially modifying the vector in order to ensure a full exploration.
i | index of the bit to set |
value | new value of the bit |
Definition at line 128 of file BitIncrementIterator.cpp.