00001 /* This file is part of libDAI - http://www.libdai.org/ 00002 * 00003 * libDAI is licensed under the terms of the GNU General Public License version 00004 * 2, or (at your option) any later version. libDAI is distributed without any 00005 * warranty. See the file COPYING for more details. 00006 * 00007 * Copyright (C) 2002 Martijn Leisink [martijn@mbfys.kun.nl] 00008 * Copyright (C) 2006-2009 Joris Mooij [joris dot mooij at libdai dot org] 00009 * Copyright (C) 2002-2007 Radboud University Nijmegen, The Netherlands 00010 */ 00011 00012 00015 00016 00017 #ifndef __defined_libdai_var_h 00018 #define __defined_libdai_var_h 00019 00020 00021 #include <iostream> 00022 #include <dai/exceptions.h> 00023 00024 00025 namespace dai { 00026 00027 00029 00040 class Var { 00041 private: 00043 size_t _label; 00044 00046 size_t _states; 00047 00048 public: 00050 Var() : _label(-1), _states(0) {} 00052 Var( size_t label, size_t states ) : _label(label), _states(states) {} 00053 00055 size_t label() const { return _label; } 00057 size_t& label() { return _label; } 00058 00060 size_t states () const { return _states; } 00062 size_t& states () { return _states; } 00063 00065 bool operator < ( const Var& n ) const { return( _label < n._label ); } 00067 bool operator > ( const Var& n ) const { return( _label > n._label ); } 00069 bool operator <= ( const Var& n ) const { 00070 #ifdef DAI_DEBUG 00071 if( _label == n._label ) 00072 DAI_ASSERT( _states == n._states ); 00073 #endif 00074 return( _label <= n._label ); 00075 } 00077 bool operator >= ( const Var& n ) const { 00078 #ifdef DAI_DEBUG 00079 if( _label == n._label ) 00080 DAI_ASSERT( _states == n._states ); 00081 #endif 00082 return( _label >= n._label ); 00083 } 00085 bool operator != ( const Var& n ) const { 00086 #ifdef DAI_DEBUG 00087 if( _label == n._label ) 00088 DAI_ASSERT( _states == n._states ); 00089 #endif 00090 return( _label != n._label ); 00091 } 00093 bool operator == ( const Var& n ) const { 00094 #ifdef DAI_DEBUG 00095 if( _label == n._label ) 00096 DAI_ASSERT( _states == n._states ); 00097 #endif 00098 return( _label == n._label ); 00099 } 00100 00102 friend std::ostream& operator << ( std::ostream& os, const Var& n ) { 00103 return( os << "x" << n.label() ); 00104 } 00105 }; 00106 00107 00108 } // end of namespace dai 00109 00110 00111 #endif