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.
34 /** It contains the label of the variable, an integer-valued
35 * unique ID for that variable, and the number of possible
36 * values ("states") of the variable.
40 /// Label of the variable (its unique ID)
43 /// Number of possible values
47 /// Default constructor
48 Var() : _label(-1), _states(0) {}
50 Var( long label
, size_t states
) : _label(label
), _states(states
) {}
53 long label() const { return _label
; }
54 /// Returns reference to label
55 long & label() { return _label
; }
57 /// Returns the number of states
58 size_t states () const { return _states
; }
59 /// Returns reference to number of states
60 size_t& states () { return _states
; }
62 /// Smaller-than operator (only compares labels)
63 bool operator < ( const Var
& n
) const { return( _label
< n
._label
); }
64 /// Larger-than operator (only compares labels)
65 bool operator > ( const Var
& n
) const { return( _label
> n
._label
); }
66 /// Smaller-than-or-equal-to operator (only compares labels)
67 bool operator <= ( const Var
& n
) const { return( _label
<= n
._label
); }
68 /// Larger-than-or-equal-to operator (only compares labels)
69 bool operator >= ( const Var
& n
) const { return( _label
>= n
._label
); }
70 /// Not-equal-to operator (only compares labels)
71 bool operator != ( const Var
& n
) const { return( _label
!= n
._label
); }
72 /// Equal-to operator (only compares labels)
73 bool operator == ( const Var
& n
) const { return( _label
== n
._label
); }
75 /// Write a Var to output stream
76 friend std::ostream
& operator << ( std::ostream
& os
, const Var
& n
) {
77 return( os
<< "[" << n
.label() << "]" );
82 } // end of namespace dai