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

This class enumerates the indeces of all combinations where a value is fixed. More...

#include <AIToolbox/Factored/Utils/Core.hpp>

Public Member Functions

 PartialIndexEnumerator (const Factors &F, size_t fixedFactor, size_t val)
 Basic constructor. More...
 
 PartialIndexEnumerator (const Factors &F, const PartialKeys &factors, size_t fixedFactor, size_t val, bool missing=false)
 Basic constructor. More...
 
size_t operator* () const
 This operator returns the current index. More...
 
void advance ()
 This function advances the PartialFactorsEnumerator to the next index. More...
 
bool isValid ()
 This function returns whether it is safe to dereference the PartialFactorsEnumerator. More...
 
void reset ()
 This function resets the PartialIndexEnumerator to the first valid index. More...
 

Detailed Description

This class enumerates the indeces of all combinations where a value is fixed.

This class is somewhat similar to PartialFactorsEnumerator, but handles indexes rather than full enumerations. In particular, it lists all the indeces of the enumerations of certain key-values, where a given key-value is assumed fixed.

To make a concrete example, consider the list that PartialFactorsEnumerator generates for a space of (2,3).

(0,0) -> 0 (1,0) -> 1 (0,1) -> 2 (1,1) -> 3 (0,2) -> 4 (1,2) -> 5

With the arrows we have associated an index to each combination. We can then use PartialIndexEnumerator to list all indeces where the first key is zero, which would return

[0, 2, 4].

Otherwise, we could ask the indeces where the second key is one, which would return

[2, 3]

PartialFactorsEnumerator and PartialIndexEnumerator are guaranteed to be "in sync", in the sense that the indeces returned will always correspond to the n-th element generated by the PartialFactorsEnumerator.

Note that PartialIndexEnumerator is quite efficient, as it does not need to do any allocation, and advancing the enumeration only requires a couple of simple operations.

Constructor & Destructor Documentation

◆ PartialIndexEnumerator() [1/2]

AIToolbox::Factored::PartialIndexEnumerator::PartialIndexEnumerator ( const Factors F,
size_t  fixedFactor,
size_t  val 
)

Basic constructor.

Parameters
FThe factor space to operate on.
fixedFactorThe factor to consider fixed.
valThe value of the fixed factor.

◆ PartialIndexEnumerator() [2/2]

AIToolbox::Factored::PartialIndexEnumerator::PartialIndexEnumerator ( const Factors F,
const PartialKeys factors,
size_t  fixedFactor,
size_t  val,
bool  missing = false 
)

Basic constructor.

Parameters
FThe factor space to operate on.
factorsThe factors to take into considerations.
fixedFactorThe factor to consider fixed.
valThe value of the fixed factor.
missingWhether fixedFactor is already present in the input PartialKeys, or not.

Member Function Documentation

◆ advance()

void AIToolbox::Factored::PartialIndexEnumerator::advance ( )

This function advances the PartialFactorsEnumerator to the next index.

◆ isValid()

bool AIToolbox::Factored::PartialIndexEnumerator::isValid ( )

This function returns whether it is safe to dereference the PartialFactorsEnumerator.

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

◆ operator*()

size_t AIToolbox::Factored::PartialIndexEnumerator::operator* ( ) const

This operator returns the current index.

Returns
The index the enumerator is at this moment.

◆ reset()

void AIToolbox::Factored::PartialIndexEnumerator::reset ( )

This function resets the PartialIndexEnumerator to the first valid index.


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