1 /* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
2 Radboud University Nijmegen, The Netherlands /
3 Max Planck Institute for Biological Cybernetics, Germany
5 Copyright (C) 2002 Martijn Leisink [martijn@mbfys.kun.nl]
6 Radboud University Nijmegen, The Netherlands
8 This file is part of libDAI.
10 libDAI is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 libDAI is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with libDAI; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 /// \brief Defines class Var
30 #ifndef __defined_libdai_var_h
31 #define __defined_libdai_var_h
40 /// Represents a discrete random variable.
41 /** It contains the \a label of the variable (an integer-valued unique ID)
42 * and the number of possible values (\a states) of the variable.
46 /// Label of the variable (its unique ID)
49 /// Number of possible values
53 /// Default constructor
54 Var() : _label(-1), _states(0) {}
56 Var( long label
, size_t states
) : _label(label
), _states(states
) {}
59 long label() const { return _label
; }
60 /// Returns reference to label
61 long & label() { return _label
; }
63 /// Returns the number of states
64 size_t states () const { return _states
; }
65 /// Returns reference to number of states
66 size_t& states () { return _states
; }
68 /// Smaller-than operator (only compares labels)
69 bool operator < ( const Var
& n
) const { return( _label
< n
._label
); }
70 /// Larger-than operator (only compares labels)
71 bool operator > ( const Var
& n
) const { return( _label
> n
._label
); }
72 /// Smaller-than-or-equal-to operator (only compares labels)
73 bool operator <= ( const Var
& n
) const { return( _label
<= n
._label
); }
74 /// Larger-than-or-equal-to operator (only compares labels)
75 bool operator >= ( const Var
& n
) const { return( _label
>= n
._label
); }
76 /// Not-equal-to operator (only compares labels)
77 bool operator != ( const Var
& n
) const { return( _label
!= n
._label
); }
78 /// Equal-to operator (only compares labels)
79 bool operator == ( const Var
& n
) const { return( _label
== n
._label
); }
81 /// Writes a Var to an output stream
82 friend std::ostream
& operator << ( std::ostream
& os
, const Var
& n
) {
83 return( os
<< "[" << n
.label() << "]" );
88 } // end of namespace dai