libDAI
|
Tool for looping over the states of several variables. More...
#include <dai/index.h>
Public Member Functions | |
IndexFor () | |
Default constructor. More... | |
IndexFor (const VarSet &indexVars, const VarSet &forVars) | |
Construct IndexFor object from indexVars and forVars. More... | |
IndexFor & | reset () |
Resets the state. More... | |
operator size_t () const | |
Conversion to size_t: returns linear index of the current state of indexVars. More... | |
IndexFor & | operator++ () |
Increments the current state of forVars (prefix) More... | |
void | operator++ (int) |
Increments the current state of forVars (postfix) More... | |
bool | valid () const |
Returns true if the current state is valid. More... | |
Private Attributes | |
long | _index |
The current linear index corresponding to the state of indexVars. More... | |
std::vector< long > | _sum |
For each variable in forVars, the amount of change in _index. More... | |
std::vector< size_t > | _state |
For each variable in forVars, the current state. More... | |
std::vector< size_t > | _ranges |
For each variable in forVars, its number of possible values. More... | |
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:
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.
|
inline |
Default constructor.
Construct IndexFor object from indexVars and forVars.
|
inline |
Resets the state.
|
inline |
Conversion to size_t:
returns linear index of the current state of indexVars.
|
inline |
Increments the current state of forVars (prefix)
|
inline |
Increments the current state of forVars (postfix)
|
inline |
Returns true
if the current state is valid.
|
private |
The current linear index corresponding to the state of indexVars.
|
private |
For each variable in forVars, the amount of change in _index.
|
private |
For each variable in forVars, the current state.
|
private |
For each variable in forVars, its number of possible values.