dai::IndexFor Class Reference

Tool for looping over the states of several variables. More...

#include <dai/index.h>

List of all members.

Public Member Functions

 IndexFor ()
 Default constructor.
 IndexFor (const VarSet &indexVars, const VarSet &forVars)
 Construct IndexFor object from indexVars and forVars.
IndexForreset ()
 Resets the state.
 operator size_t () const
 Conversion to size_t: returns linear index of the current state of indexVars.
IndexForoperator++ ()
 Increments the current state of forVars (prefix).
void operator++ (int)
 Increments the current state of forVars (postfix).
bool valid () const
 Returns true if the current state is valid.

Private Attributes

long _index
 The current linear index corresponding to the state of indexVars.
std::vector< long > _sum
 For each variable in forVars, the amount of change in _index.
std::vector< size_t > _state
 For each variable in forVars, the current state.
std::vector< size_t > _ranges
 For each variable in forVars, its number of possible values.


Detailed Description

Tool for looping over the states of several variables.

The class IndexFor is an important tool for indexing Factor entries. Its usage can best be explained by an example. Assume indexVars, forVars are both VarSet 's. Then the following code:

      IndexFor i( indexVars, forVars );
      size_t iter = 0;
      for( ; i.valid(); i++, iter++ ) {
          cout << "State of forVars: " << calcState( forVars, iter ) << "; ";
          cout << "state of indexVars: " << calcState( indexVars, size_t(i) ) << endl;
      }
loops over all joint states of the variables in forVars, and (size_t)i equals the linear index of the corresponding state of indexVars, where the variables in indexVars that are not in forVars assume their zero'th value.
Idea:
Optimize all indices as follows: keep a cache of all (or only relatively small) indices that have been computed (use a hash). Then, instead of computing on the fly, use the precomputed ones. Here the labels of the variables don't matter, but the ranges of the variables do.

Constructor & Destructor Documentation

dai::IndexFor::IndexFor (  )  [inline]

Default constructor.

dai::IndexFor::IndexFor ( const VarSet indexVars,
const VarSet forVars 
) [inline]

Construct IndexFor object from indexVars and forVars.


Member Function Documentation

IndexFor& dai::IndexFor::reset (  )  [inline]

Resets the state.

dai::IndexFor::operator size_t (  )  const [inline]

Conversion to size_t: returns linear index of the current state of indexVars.

IndexFor& dai::IndexFor::operator++ (  )  [inline]

Increments the current state of forVars (prefix).

void dai::IndexFor::operator++ ( int   )  [inline]

Increments the current state of forVars (postfix).

bool dai::IndexFor::valid (  )  const [inline]

Returns true if the current state is valid.


Member Data Documentation

long dai::IndexFor::_index [private]

The current linear index corresponding to the state of indexVars.

std::vector<long> dai::IndexFor::_sum [private]

For each variable in forVars, the amount of change in _index.

std::vector<size_t> dai::IndexFor::_state [private]

For each variable in forVars, the current state.

std::vector<size_t> dai::IndexFor::_ranges [private]

For each variable in forVars, its number of possible values.


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

Generated on Thu Aug 5 19:04:06 2010 for libDAI by  doxygen 1.5.5