AIToolbox
A library that offers tools for AI problem solving.
AIToolbox::SubsetEnumerator< Index > Class Template Reference

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 IdsStorageoperator* () const
 This operator returns the current combination. More...
 
const IdsStorageoperator-> () const
 This operator returns a pointer to the current combination. More...
 

Detailed Description

template<typename Index>
class AIToolbox::SubsetEnumerator< Index >

This class enumerates all possible vectors of finite subsets over N elements.

Member Typedef Documentation

◆ IdsStorage

template<typename Index >
using AIToolbox::SubsetEnumerator< Index >::IdsStorage = std::vector<Index>

Constructor & Destructor Documentation

◆ SubsetEnumerator()

template<typename Index >
AIToolbox::SubsetEnumerator< Index >::SubsetEnumerator ( size_t  elementsN,
Index  lowerBound,
Index  upperBound 
)
inline

Default constructor.

Parameters
elementsNThe number of elements that the subset should have (<= limit);
lowerBoundEither an integer, or an iterator to the start of a range containing the elements to subset.
upperBoundEither an integer (excluded), or an iterator to the end of a range containing the elements to subset.

Member Function Documentation

◆ advance()

template<typename Index >
auto AIToolbox::SubsetEnumerator< Index >::advance ( )
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.

Returns
The id of the leftmost element changed by the advance.

◆ isValid()

template<typename Index >
bool AIToolbox::SubsetEnumerator< Index >::isValid ( ) const
inline

This function returns whether there are more subsets to be enumerated.

◆ operator*()

template<typename Index >
const IdsStorage& AIToolbox::SubsetEnumerator< Index >::operator* ( ) const
inline

This operator returns the current combination.

This operator can be called only if isValid() is true. Otherwise behavior is undefined.

Returns
The current combination.

◆ operator->()

template<typename Index >
const IdsStorage* AIToolbox::SubsetEnumerator< Index >::operator-> ( ) const
inline

This operator returns a pointer to the current combination.

This operator can be called only if isValid() is true. Otherwise behavior is undefined.

Returns
The current combination.

◆ reset()

template<typename Index >
void AIToolbox::SubsetEnumerator< Index >::reset ( )
inline

This function resets the enumerator to the valid beginning.

◆ size()

template<typename Index >
auto AIToolbox::SubsetEnumerator< Index >::size ( ) const
inline

This function returns the size of the range covered.

◆ subsetsSize()

template<typename Index >
auto AIToolbox::SubsetEnumerator< Index >::subsetsSize ( ) const
inline

This function returns the number of subsets enumerated over.


The documentation for this class was generated from the following file: