/// \file
/// \brief Defines the IndexFor, MultiFor, Permute and State classes
+/// \todo Improve documentation
#ifndef __defined_libdai_index_h
* and (long)i is equal to 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.
*/
class IndexFor {
private:
_index = 0;
}
- /// Copy constructor
- IndexFor( const IndexFor & ind ) : _index(ind._index), _sum(ind._sum), _count(ind._count), _dims(ind._dims) {}
-
- /// Assignment operator
- IndexFor& operator=( const IndexFor &ind ) {
- if( this != &ind ) {
- _index = ind._index;
- _sum = ind._sum;
- _count = ind._count;
- _dims = ind._dims;
- }
- return *this;
- }
-
/// Sets the index back to zero
IndexFor& clear() {
fill( _count.begin(), _count.end(), 0 );
/// Initialize from vector of index dimensions
MultiFor( const std::vector<size_t> &d ) : _dims(d), _states(d.size(),0), _state(0) {}
- /// Copy constructor
- MultiFor( const MultiFor &x ) : _dims(x._dims), _states(x._states), _state(x._state) {}
-
- /// Assignment operator
- MultiFor& operator=( const MultiFor & x ) {
- if( this != &x ) {
- _dims = x._dims;
- _states = x._states;
- _state = x._state;
- }
- return *this;
- }
-
/// Return linear state
operator size_t() const {
assert( valid() );
assert( _dims.size() == _sigma.size() );
}
- /// Copy constructor
- Permute( const Permute &x ) : _dims(x._dims), _sigma(x._sigma) {}
-
- /// Assignment operator
- Permute& operator=( const Permute &x ) {
- if( this != &x ) {
- _dims = x._dims;
- _sigma = x._sigma;
- }
- return *this;
- }
-
- /// Converts the linear index li to a vector index
- /// corresponding with the dimensions in _dims,
- /// permutes it according to sigma,
- /// and converts it back to a linear index
- /// according to the permuted dimensions.
+ /// Calculates a permuted linear index.
+ /** Converts the linear index li to a vector index
+ * corresponding with the dimensions in _dims, permutes it according to sigma,
+ * and converts it back to a linear index according to the permuted dimensions.
+ */
size_t convert_linear_index( size_t li ) {
size_t N = _dims.size();
states[*v] = 0;
}
- /// Copy constructor
- State( const State & x ) : state(x.state), states(x.states) {}
-
- /// Assignment operator
- State& operator=( const State &x ) {
- if( this != &x ) {
- state = x.state;
- states = x.states;
- }
- return *this;
- }
-
/// Return linear state
operator size_t() const {
assert( valid() );
return( state );
}
- /// Return state of variable n,
- /// or zero if n is not in this State
+ /// Return state of variable n, or zero if n is not in this State
size_t operator() ( const Var &n ) const {
assert( valid() );
states_type::const_iterator entry = states.find( n );
return entry->second;
}
- /// Return linear state of variables in varset,
- /// setting them to zero if they are not in this State
+ /// Return linear state of variables in varset, setting them to zero if they are not in this State
size_t operator() ( const VarSet &vs ) const {
assert( valid() );
size_t vs_state = 0;
return vs_state;
}
- /// Postfix increment operator
- void operator++( int ) {
+ /// Prefix increment operator
+ void operator++( ) {
if( valid() ) {
state++;
states_type::iterator entry = states.begin();
state = -1;
}
}
+
+ /// Postfix increment operator
+ void operator++( int ) {
+ operator++();
+ }
/// Returns true if the current state is valid
bool valid() const {