|
| State () |
| Default constructor. More...
|
|
| State (const VarSet &vs, BigInt linearState=0) |
| Construct from VarSet vs and corresponding linear state linearState. More...
|
|
| State (const std::map< Var, size_t > &s) |
| Construct from a std::map<Var, size_t> More...
|
|
const_iterator | begin () const |
| Returns constant iterator that points to the first item. More...
|
|
const_iterator | end () const |
| Returns constant iterator that points beyond the last item. More...
|
|
| operator size_t () const |
| Return current linear state. More...
|
|
template<typename InputIterator > |
void | insert (InputIterator b, InputIterator e) |
| Inserts a range of variable-state pairs, changing the current state. More...
|
|
const std::map< Var, size_t > & | get () const |
| Return current state represented as a map. More...
|
|
| operator const std::map< Var, size_t > & () const |
| Cast into std::map<Var, size_t> More...
|
|
size_t | operator() (const Var &v) const |
| Return current state of variable v, or 0 if v is not in *this . More...
|
|
BigInt | operator() (const VarSet &vs) const |
| Return linear state of variables in vs, assuming that variables that are not in *this are in state 0. More...
|
|
void | operator++ () |
| Increments the current state (prefix) More...
|
|
void | operator++ (int) |
| Increments the current state (postfix) More...
|
|
bool | valid () const |
| Returns true if the current state is valid. More...
|
|
void | reset () |
| Resets the current state (to the joint state represented by linear state 0) More...
|
|
Makes it easy to iterate over all possible joint states of variables within a VarSet.
A joint state of several variables can be represented in two different ways, by a map that maps each variable to its own state, or by an integer that gives the index of the joint state in the canonical enumeration.
Both representations are useful, and the main functionality provided by the State class is to simplify iterating over the various joint states of a VarSet and to provide access to the current state in both representations.
As an example, consider the following code snippet which iterates over all joint states of variables x0 and x1:
VarSet vars( x0, x1 );
for(
State S(vars); S.valid(); S++ ) {
cout << "Linear state: " << S.get() << ", x0 = " << S(x0) << ", x1 = " << S(x1) << endl;
}
- Note
- The same functionality could be achieved by simply iterating over the linear state and using dai::calcState(), but the State class offers a more efficient implementation.
-
A State is very similar to a dai::multifor, but tailored for Var 's and VarSet 's.
- See also
- dai::calcLinearState(), dai::calcState()
- Idea:
- Make the State class a more prominent part of libDAI (and document it clearly, explaining the concept of state); add more optimized variants of the State class like IndexFor (e.g. for TFactor<>::slice()).
- Examples:
- example_permute.cpp, and example_varset.cpp.