AIToolbox
A library that offers tools for AI problem solving.
|
This class enumerates all possible vectors of finite subsets over N elements. More...
#include <AIToolbox/Utils/Combinatorics.hpp>
Public Types | |
using | IdsStorage = std::vector< Index > |
Public Member Functions | |
SubsetEnumerator (size_t elementsN, Index lowerBound, Index upperBound) | |
Default constructor. More... | |
auto | advance () |
This function advances the SubsetEnumerator to the next possible subset. More... | |
bool | isValid () const |
This function returns whether there are more subsets to be enumerated. More... | |
void | reset () |
This function resets the enumerator to the valid beginning. More... | |
auto | subsetsSize () const |
This function returns the number of subsets enumerated over. More... | |
auto | size () const |
This function returns the size of the range covered. More... | |
const IdsStorage & | operator* () const |
This operator returns the current combination. More... | |
const IdsStorage * | operator-> () const |
This operator returns a pointer to the current combination. More... | |
This class enumerates all possible vectors of finite subsets over N elements.
using AIToolbox::SubsetEnumerator< Index >::IdsStorage = std::vector<Index> |
|
inline |
Default constructor.
elementsN | The number of elements that the subset should have (<= limit); |
lowerBound | Either an integer, or an iterator to the start of a range containing the elements to subset. |
upperBound | Either an integer (excluded), or an iterator to the end of a range containing the elements to subset. |
|
inline |
This function advances the SubsetEnumerator to the next possible subset.
This function iterates first on the last elements of the subset vector, and iterates over the previous ones once it reaches the end. For example, for a subset of length 3 over 6 elements the iteration will look like this:
0, 1, 2 0, 1, 3 0, 1, 4 0, 1, 5 0, 2, 3 0, 2, 4 0, 2, 5 1, 2, 3 etc.
The number returned by this function represents the id of the leftmost (lowest) element that has been changed by the advance. This may be useful in case you need to do some work for the elements that changed in the subset, and want to lose as little time as possible.
|
inline |
This function returns whether there are more subsets to be enumerated.
|
inline |
This operator returns the current combination.
This operator can be called only if isValid() is true. Otherwise behavior is undefined.
|
inline |
This operator returns a pointer to the current combination.
This operator can be called only if isValid() is true. Otherwise behavior is undefined.
|
inline |
This function resets the enumerator to the valid beginning.
|
inline |
This function returns the size of the range covered.
|
inline |
This function returns the number of subsets enumerated over.