AIToolbox
A library that offers tools for AI problem solving.
|
This class enumerates all possible values for a PartialFactors. More...
#include <AIToolbox/Factored/Utils/Core.hpp>
Public Member Functions | |
PartialFactorsEnumerator (Factors f, PartialKeys factors) | |
Basic constructor. More... | |
PartialFactorsEnumerator (Factors f) | |
Basic constructor. More... | |
PartialFactorsEnumerator (Factors f, const PartialKeys &factors, size_t factorToSkip, bool missing=false) | |
Skip constructor. More... | |
PartialFactorsEnumerator (Factors f, size_t factorToSkip) | |
Skip constructor. More... | |
size_t | getFactorToSkipId () const |
This function returns the id of the factorToSkip inside the PartialFactorsEnumerator. More... | |
void | advance () |
This function advances the PartialFactorsEnumerator to the next possible combination. More... | |
bool | isValid () const |
This function returns whether this object has terminated advancing and can be dereferenced. More... | |
void | reset () |
This function resets the enumerator to the valid beginning (a fully zero PartialFactor). More... | |
size_t | size () const |
This function returns the number of times that advance() can be called from the initial state. More... | |
PartialFactors & | operator* () |
This operator returns the current iteration in the values of the PartialFactors. More... | |
PartialFactors * | operator-> () |
This operator returns the current iteration in the values of the PartialFactors. More... | |
This class enumerates all possible values for a PartialFactors.
This class is a simple enumerator that goes through all possible values of a PartialFactors for the specific input factors. An additional separate factor index can be specified in order to skip that factor, to allow the user to modify that freely.
The iteration is always done by increasing the lowest id first. So for example in a space (2,3), we iterate in the following order:
(0,0) (1,0) (0,1) (1,1) (0,2) (1,2)
AIToolbox::Factored::PartialFactorsEnumerator::PartialFactorsEnumerator | ( | Factors | f, |
PartialKeys | factors | ||
) |
Basic constructor.
This constructor initializes the internal PartialFactors with the factors obtained as inputs. In addition it saves the input Factor as the ceiling for the values in the PartialFactors.
f | The factor space for the internal PartialFactors. |
factors | The factors to take into consideration. |
AIToolbox::Factored::PartialFactorsEnumerator::PartialFactorsEnumerator | ( | Factors | f | ) |
Basic constructor.
This constructor initializes the internal PartialFactors with the factors obtained as inputs. This constructor can be used when one wants to iterate over all factors.
f | The factor space for the internal PartialFactors. |
AIToolbox::Factored::PartialFactorsEnumerator::PartialFactorsEnumerator | ( | Factors | f, |
const PartialKeys & | factors, | ||
size_t | factorToSkip, | ||
bool | missing = false |
||
) |
Skip constructor.
This constructor is the same as the basic one, but it additionally remembers that the input factorToSkip will not be enumerated, and will in fact be editable by the client.
The factorToSkip must be within the Factors space, or it will not be taken into consideration.
f | The factor space for the internal PartialFactors. |
factors | The factors to take into considerations. |
factorToSkip | The factor to skip. |
missing | Whether factorToSkip is already present in the input PartialKeys or it must be added. |
AIToolbox::Factored::PartialFactorsEnumerator::PartialFactorsEnumerator | ( | Factors | f, |
size_t | factorToSkip | ||
) |
Skip constructor.
This constructor is the same as the basic one, but it additionally remembers that the input factorToSkip will not be enumerated, and will in fact be editable by the client.
This constructor can be used to enumerate over all factors.
The factorToSkip must be within the Factors space, or it will not be taken into consideration.
f | The factor space for the internal PartialFactors. |
factorToSkip | The factor to skip. |
void AIToolbox::Factored::PartialFactorsEnumerator::advance | ( | ) |
This function advances the PartialFactorsEnumerator to the next possible combination.
size_t AIToolbox::Factored::PartialFactorsEnumerator::getFactorToSkipId | ( | ) | const |
This function returns the id of the factorToSkip inside the PartialFactorsEnumerator.
This function is provided for convenience, since PartialFactorsEnumerator has to compute this id anyway. It represents the id of the factorToSkip inside the vectors contained in the PartialFactors. This is useful so the client can go and edit that particular element directly.
bool AIToolbox::Factored::PartialFactorsEnumerator::isValid | ( | ) | const |
This function returns whether this object has terminated advancing and can be dereferenced.
PartialFactors& AIToolbox::Factored::PartialFactorsEnumerator::operator* | ( | ) |
This operator returns the current iteration in the values of the PartialFactors.
This operator can be called only if isValid() is true. Otherwise behavior is undefined.
The PartialFactors returned are editable, so that the user can change the factorToSkip values. If other values are edited, and the resulting PartialFactors still has valid values (below the Factors ceiling), the next advance() call will continue from there. If advance() is called with an invalid PartialFactors behavior is undefined.
PartialFactors* AIToolbox::Factored::PartialFactorsEnumerator::operator-> | ( | ) |
This operator returns the current iteration in the values of the PartialFactors.
This operator can be called only if isValid() is true. Otherwise behavior is undefined.
The PartialFactors returned are editable, so that the user can change the factorToSkip values. If other values are edited, and the resulting PartialFactors still has valid values (below the Factors ceiling), the next advance() call will continue from there. If advance() is called with an invalid PartialFactors behavior is undefined.
void AIToolbox::Factored::PartialFactorsEnumerator::reset | ( | ) |
This function resets the enumerator to the valid beginning (a fully zero PartialFactor).
size_t AIToolbox::Factored::PartialFactorsEnumerator::size | ( | ) | const |
This function returns the number of times that advance() can be called from the initial state.
Warning: This operation is NOT cheap, as this number needs to be computed.