Updated copyrights
[libdai.git] / include / dai / var.h
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
4
5 Copyright (C) 2002 Martijn Leisink [martijn@mbfys.kun.nl]
6 Radboud University Nijmegen, The Netherlands
7
8 This file is part of libDAI.
9
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.
14
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.
19
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
23 */
24
25
26 #ifndef __defined_libdai_var_h
27 #define __defined_libdai_var_h
28
29
30 #include <iostream>
31
32
33 namespace dai {
34
35
36 /// Represents a discrete variable.
37 /** It contains the label of the variable, an integer-valued
38 * unique ID for that variable, and the number of possible
39 * values ("states") of the variable.
40 */
41 class Var {
42 private:
43 /// Label of the variable (its unique ID)
44 long _label;
45
46 /// Number of possible values
47 size_t _states;
48
49 public:
50 /// Default constructor
51 Var() : _label(-1), _states(0) {}
52 /// Constructor
53 Var( long label, size_t states ) : _label(label), _states(states) {}
54
55 /// Returns the label
56 long label() const { return _label; }
57 /// Returns reference to label
58 long & label() { return _label; }
59
60 /// Returns the number of states
61 size_t states () const { return _states; }
62 /// Returns reference to number of states
63 size_t& states () { return _states; }
64
65 /// Smaller-than operator (only compares labels)
66 bool operator < ( const Var& n ) const { return( _label < n._label ); }
67 /// Larger-than operator (only compares labels)
68 bool operator > ( const Var& n ) const { return( _label > n._label ); }
69 /// Smaller-than-or-equal-to operator (only compares labels)
70 bool operator <= ( const Var& n ) const { return( _label <= n._label ); }
71 /// Larger-than-or-equal-to operator (only compares labels)
72 bool operator >= ( const Var& n ) const { return( _label >= n._label ); }
73 /// Not-equal-to operator (only compares labels)
74 bool operator != ( const Var& n ) const { return( _label != n._label ); }
75 /// Equal-to operator (only compares labels)
76 bool operator == ( const Var& n ) const { return( _label == n._label ); }
77
78 /// Write a Var to output stream
79 friend std::ostream& operator << ( std::ostream& os, const Var& n ) {
80 return( os << "[" << n.label() << "]" );
81 }
82 };
83
84
85 } // end of namespace dai
86
87
88 #endif