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(0), _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 { 00066 #ifdef DAI_DEBUG 00067 if( _label == n._label ) 00068 DAI_ASSERT( _states == n._states ); 00069 #endif 00070 return( _label < n._label ); 00071 } 00072 00074 bool operator> ( const Var& n ) const { 00075 #ifdef DAI_DEBUG 00076 if( _label == n._label ) 00077 DAI_ASSERT( _states == n._states ); 00078 #endif 00079 return( _label > n._label ); 00080 } 00081 00083 bool operator<= ( const Var& n ) const { 00084 #ifdef DAI_DEBUG 00085 if( _label == n._label ) 00086 DAI_ASSERT( _states == n._states ); 00087 #endif 00088 return( _label <= n._label ); 00089 } 00090 00092 bool operator>= ( const Var& n ) const { 00093 #ifdef DAI_DEBUG 00094 if( _label == n._label ) 00095 DAI_ASSERT( _states == n._states ); 00096 #endif 00097 return( _label >= n._label ); 00098 } 00099 00101 bool operator!= ( const Var& n ) const { 00102 #ifdef DAI_DEBUG 00103 if( _label == n._label ) 00104 DAI_ASSERT( _states == n._states ); 00105 #endif 00106 return( _label != n._label ); 00107 } 00108 00110 bool operator== ( const Var& n ) const { 00111 #ifdef DAI_DEBUG 00112 if( _label == n._label ) 00113 DAI_ASSERT( _states == n._states ); 00114 #endif 00115 return( _label == n._label ); 00116 } 00117 00119 friend std::ostream& operator << ( std::ostream& os, const Var& n ) { 00120 return( os << "x" << n.label() ); 00121 } 00122 }; 00123 00124 00125 } // end of namespace dai 00126 00127 00128 #endif