AIToolbox
A library that offers tools for AI problem solving.
AIToolbox::Factored::PartialFactorsEnumerator Class Reference

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...
 
PartialFactorsoperator* ()
 This operator returns the current iteration in the values of the PartialFactors. More...
 
PartialFactorsoperator-> ()
 This operator returns the current iteration in the values of the PartialFactors. More...
 

Detailed Description

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)

Constructor & Destructor Documentation

◆ PartialFactorsEnumerator() [1/4]

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.

Parameters
fThe factor space for the internal PartialFactors.
factorsThe factors to take into consideration.

◆ PartialFactorsEnumerator() [2/4]

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.

Parameters
fThe factor space for the internal PartialFactors.

◆ PartialFactorsEnumerator() [3/4]

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.

Parameters
fThe factor space for the internal PartialFactors.
factorsThe factors to take into considerations.
factorToSkipThe factor to skip.
missingWhether factorToSkip is already present in the input PartialKeys or it must be added.

◆ PartialFactorsEnumerator() [4/4]

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.

Parameters
fThe factor space for the internal PartialFactors.
factorToSkipThe factor to skip.

Member Function Documentation

◆ advance()

void AIToolbox::Factored::PartialFactorsEnumerator::advance ( )

This function advances the PartialFactorsEnumerator to the next possible combination.

◆ getFactorToSkipId()

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.

Returns
The id of the factorToSkip inside the PartialFactorsEnumerator.

◆ isValid()

bool AIToolbox::Factored::PartialFactorsEnumerator::isValid ( ) const

This function returns whether this object has terminated advancing and can be dereferenced.

Returns
True if we can still be dereferenced, false otherwise.

◆ operator*()

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.

Returns
The current PartialFactors values.

◆ operator->()

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.

Returns
The current PartialFactors values.

◆ reset()

void AIToolbox::Factored::PartialFactorsEnumerator::reset ( )

This function resets the enumerator to the valid beginning (a fully zero PartialFactor).

◆ size()

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.


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