d0a9950667091c808363d566161e9d76436cf2b9
[libdai.git] / include / dai / var.h
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
4
5 This file is part of libDAI.
6
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.
11
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.
16
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
20 */
21
22
23 #ifndef __defined_libdai_var_h
24 #define __defined_libdai_var_h
25
26
27 #include <iostream>
28
29
30 namespace dai {
31
32
33 /// Represents a discrete variable
34 class Var {
35 private:
36 /// Internal label of the variable
37 long _label;
38
39 /// Number of possible values
40 size_t _states;
41
42 public:
43 /// Default constructor
44 Var() : _label(-1), _states(0) {};
45 /// Constructor
46 Var(long label, size_t states) : _label(label), _states(states) {};
47
48 /// Read access to label
49 long label() const { return _label; };
50 /// Access to label
51 long & label() { return _label; };
52
53 /// Read access to states
54 size_t states () const { return _states; };
55 /// Access to states
56 size_t& states () { return _states; };
57
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 ); };
70
71 /// Stream output operator
72 friend std::ostream& operator << (std::ostream& os, const Var& n) {
73 return( os << "[" << n.label() << "]" );
74 };
75 };
76
77
78 } // end of namespace dai
79
80
81 #endif