aGrUM  0.21.0
a C++ library for (probabilistic) graphical models
integerVariable.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library 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 Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief Base class for integer discrete random variables
24  *
25  * @author Christophe GONZALES(@AMU) & Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 #ifndef GUM_INTEGER_DISCRETE_VARIABLE_H
28 #define GUM_INTEGER_DISCRETE_VARIABLE_H
29 
30 #include <iostream>
31 #include <sstream>
32 #include <string>
33 
34 #include <agrum/agrum.h>
35 
36 #include <agrum/tools/core/sequence.h>
37 #include <agrum/tools/variables/discreteVariable.h>
38 
39 namespace gum {
40 
41  /** class IntegerVariable
42  * @brief The class representing discrete integer random variables
43  * @ingroup multidim_group
44  */
45  /* =========================================================================*/
46 
47  class IntegerVariable: public DiscreteVariable {
48  public:
49  // ############################################################################
50  /// @name Constructors / Destructors
51  // ############################################################################
52  /// @{
53 
54  /** @brief constructor
55  * @param aName the name of the variable
56  * @param aDesc the Description of the variable, if any
57  */
58  IntegerVariable(const std::string& aName,
59  const std::string& aDesc = "");
60 
61  /** @brief constructor assigning a domain to the variable
62  * @param aName the name of the variable
63  * @param aDesc the Description of the variable, if any
64  * @param domain the domain (set of values) of the variable
65  */
66  IntegerVariable(const std::string& aName,
67  const std::string& aDesc,
68  const std::vector< int >& domain);
69 
70  /// Copy constructor
71  /**
72  * @param from the variable we copy
73  */
74  IntegerVariable(const IntegerVariable& from);
75 
76  /// move constructor
77  IntegerVariable(IntegerVariable&& from);
78 
79  /// virtual copy constructor
80  virtual IntegerVariable* clone() const;
81 
82  /// destructor
83  virtual ~IntegerVariable();
84 
85  /// @}
86 
87 
88  // ############################################################################
89  /// @name Operators
90  // ############################################################################
91  /// @{
92 
93  /// copy operator
94  /** @param from the integer discrete random variable we copy */
95  IntegerVariable& operator=(const IntegerVariable& from);
96 
97  /// move operator
98  /** @param from the integer discrete random variable we copy */
99  IntegerVariable& operator=(IntegerVariable&& from);
100 
101  /// equality operator
102  virtual bool operator==(const Variable& var) const;
103 
104  /// inequality operator
105  virtual bool operator!=(const Variable& var) const;
106 
107  /// @}
108 
109 
110  // ############################################################################
111  /// @name Accessors / Modifiers
112  // ############################################################################
113 
114  /// @{
115  /// returns the domain size of the discrete random variable
116  virtual Size domainSize() const;
117 
118  /// returns the type of variable
119  virtual VarType varType() const;
120 
121  /// returns the index of a given label
122  /** @param label searched label
123  * @return the index of this label
124  * @throw NotFound */
125  virtual Idx index(const std::string& label) const;
126 
127  /// returns a string corresponding to the ith value of the domain
128  virtual std::string label(Idx index) const;
129 
130  /// get a integer representation of the value at a given index
131  virtual double numerical(Idx index) const;
132 
133  /// Returns the domain as a string
134  virtual const std::string domain() const;
135 
136  /// returns the domain as a sequence of values
137  const Sequence< int >& integerDomain() const;
138 
139  /// add a new value to the domain size
140  /** @throw DuplicateElement is raised if the variable already contains the value
141  * @return *this which allows : v.addValue(1).addValue(2)...;
142  */
143  IntegerVariable& addValue(int value);
144 
145  /// substitute a value by another one
146  void changeValue(int old_value, int new_value);
147 
148  /// erase a value from the domain of the variable
149  void eraseValue(int value);
150 
151  /// clear the domain of the variable
152  void eraseValues();
153 
154  /// @}
155 
156  private:
157  /// the domain of the variable
158  Sequence< int > _domain_;
159  };
160 
161 } /* namespace gum */
162 
163 
164 #ifndef GUM_NO_INLINE
165 # include <agrum/tools/variables/integerVariable_inl.h>
166 #endif /* GUM_NO_INLINE */
167 
168 #endif /* GUM_INTEGER_DISCRETE_VARIABLE_H */