libDAI
include/dai/varset.h
Go to the documentation of this file.
00001 /*  This file is part of libDAI - http://www.libdai.org/
00002  *
00003  *  Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
00004  *
00005  *  Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
00006  */
00007 
00008 
00011 
00012 
00013 #ifndef __defined_libdai_varset_h
00014 #define __defined_libdai_varset_h
00015 
00016 
00017 #include <vector>
00018 #include <map>
00019 #include <ostream>
00020 #include <dai/var.h>
00021 #include <dai/util.h>
00022 #include <dai/smallset.h>
00023 
00024 
00025 namespace dai {
00026 
00027 
00028 // Predefine for definitions of calcLinearState() and calcState()
00029 class VarSet;
00030 
00031 
00033 
00060 size_t calcLinearState( const VarSet &vs, const std::map<Var, size_t> &state );
00061 
00062 
00064 
00085 std::map<Var, size_t> calcState( const VarSet &vs, size_t linearState );
00086 
00087 
00089 
00094 class VarSet : public SmallSet<Var> {
00095     public:
00097 
00098 
00099         VarSet() : SmallSet<Var>() {}
00100 
00102         VarSet( const SmallSet<Var> &x ) : SmallSet<Var>(x) {}
00103 
00105         VarSet( const Var &v ) : SmallSet<Var>(v) {}
00106 
00108         VarSet( const Var &v1, const Var &v2 ) : SmallSet<Var>(v1,v2) {}
00109 
00111 
00116         template <typename VarIterator>
00117         VarSet( VarIterator begin, VarIterator end, size_t sizeHint=0 ) : SmallSet<Var>(begin,end,sizeHint) {}
00119 
00121 
00122 
00123 
00130         BigInt nrStates() const {
00131             BigInt states = 1;
00132             for( VarSet::const_iterator n = begin(); n != end(); n++ )
00133                 states *= n->states();
00134             return states;
00135         }
00137 
00139 
00140 
00141         friend std::ostream& operator<<( std::ostream &os, const VarSet &vs )  {
00142             os << "{";
00143             for( VarSet::const_iterator v = vs.begin(); v != vs.end(); v++ )
00144                 os << (v != vs.begin() ? ", " : "") << *v;
00145             os << "}";
00146             return( os );
00147         }
00149 };
00150 
00151 
00152 } // end of namespace dai
00153 
00154 
00165 #endif