1 /* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
2 Copyright (C) 2002 Martijn Leisink [martijn@mbfys.kun.nl]
3 Radboud University Nijmegen, The Netherlands
5 This file is part of libDAI.
7 libDAI is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 libDAI is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with libDAI; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef __defined_libdai_var_h
24 #define __defined_libdai_var_h
33 /// Represents a discrete variable
36 /// Internal label of the variable
39 /// Number of possible values
43 /// Default constructor
44 Var() : _label(-1), _states(0) {};
46 Var(long label
, size_t states
) : _label(label
), _states(states
) {};
48 /// Read access to label
49 long label() const { return _label
; };
51 long & label() { return _label
; };
53 /// Read access to states
54 size_t states () const { return _states
; };
56 size_t& states () { return _states
; };
58 /// Smaller-than operator (compares labels)
59 bool operator < (const Var
& n
) const { return( _label
< n
._label
); };
60 /// Larger-than operator (compares labels)
61 bool operator > (const Var
& n
) const { return( _label
> n
._label
); };
62 /// Smaller-than-or-equal-to operator (compares labels)
63 bool operator <= (const Var
& n
) const { return( _label
<= n
._label
); };
64 /// Larger-than-or-equal-to operator (compares labels)
65 bool operator >= (const Var
& n
) const { return( _label
>= n
._label
); };
66 /// Not-equal-to operator (compares labels)
67 bool operator != (const Var
& n
) const { return( _label
!= n
._label
); };
68 /// Equal-to operator (compares labels)
69 bool operator == (const Var
& n
) const { return( _label
== n
._label
); };
71 /// Stream output operator
72 friend std::ostream
& operator << (std::ostream
& os
, const Var
& n
) {
73 return( os
<< "[" << n
.label() << "]" );
78 } // end of namespace dai