Partial adoption of contributions by Giuseppe:
[libdai.git] / include / dai / var.h
1 /* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
2 Radboud University Nijmegen, The Netherlands
3
4 This file is part of libDAI.
5
6 libDAI is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 libDAI is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with libDAI; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21
22 #ifndef __defined_libdai_var_h
23 #define __defined_libdai_var_h
24
25
26 #include <iostream>
27
28
29 namespace dai {
30
31
32 /// Represents a discrete variable
33 class Var {
34 private:
35 /// Internal label of the variable
36 long _label;
37
38 /// Number of possible values
39 size_t _states;
40
41 public:
42 /// Default constructor
43 Var() : _label(-1), _states(0) {};
44 /// Constructor
45 Var(long label, size_t states) : _label(label), _states(states) {};
46
47 /// Read access to label
48 long label() const { return _label; };
49 /// Access to label
50 long & label() { return _label; };
51
52 /// Read access to states
53 size_t states () const { return _states; };
54 /// Access to states
55 size_t& states () { return _states; };
56
57 /// Smaller-than operator (compares labels)
58 bool operator < (const Var& n) const { return( _label < n._label ); };
59 /// Larger-than operator (compares labels)
60 bool operator > (const Var& n) const { return( _label > n._label ); };
61 /// Smaller-than-or-equal-to operator (compares labels)
62 bool operator <= (const Var& n) const { return( _label <= n._label ); };
63 /// Larger-than-or-equal-to operator (compares labels)
64 bool operator >= (const Var& n) const { return( _label >= n._label ); };
65 /// Not-equal-to operator (compares labels)
66 bool operator != (const Var& n) const { return( _label != n._label ); };
67 /// Equal-to operator (compares labels)
68 bool operator == (const Var& n) const { return( _label == n._label ); };
69
70 /// Stream output operator
71 friend std::ostream& operator << (std::ostream& os, const Var& n) {
72 return( os << "[" << n.label() << "]" );
73 };
74 };
75
76
77 } // end of namespace dai
78
79
80 #endif