aGrUM  0.14.2
discreteVariable.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 #ifndef GUM_DISCRETE_VARIABLE_H
27 #define GUM_DISCRETE_VARIABLE_H
28 
29 #include <ostream>
30 #include <string>
31 
32 #include <agrum/agrum.h>
33 
34 #include <agrum/core/hashFunc.h>
36 
37 namespace gum {
38 
39  /* ===========================================================================
40  */
41  /* ===========================================================================
42  */
43  /* === GUM_DISCRETE_VARIABLE ===
44  */
45  /* ===========================================================================
46  */
47  /* ===========================================================================
48  */
54  /* ===========================================================================
55  */
56 
57  class DiscreteVariable : public Variable {
58  public:
59  // ############################################################################
61  // ############################################################################
63 
65 
66  DiscreteVariable(const std::string& aName, const std::string& aDesc);
67 
69 
77 
79 
80  virtual ~DiscreteVariable();
81 
84 
85  virtual DiscreteVariable* clone() const = 0;
86 
88 
89  // ############################################################################
91  // ############################################################################
93 
95 
96  bool empty() const;
97 
99 
100  virtual Size domainSize() const = 0;
101 
103  std::vector< std::string > labels() const;
104 
106  virtual double numerical(Idx indice) const = 0;
107 
109 
110  virtual VarType varType() const = 0;
112 
113  // ############################################################################
115  // ############################################################################
117 
119 
123 
125  virtual bool operator==(const DiscreteVariable& aRV) const;
126 
128 
129  virtual bool operator!=(const DiscreteVariable& aRV) const;
130 
132 
137  Idx operator[](const std::string& label) const { return index(label); };
138  virtual Idx index(const std::string& label) const = 0;
139 
141 
144  virtual std::string label(Idx i) const = 0;
145 
147  const std::string toString() const;
148 
150  const std::string toStringWithDescription() const;
151 
153  virtual const std::string domain() const = 0;
154 
155  protected:
157  DiscreteVariable() { GUM_CONSTRUCTOR(DiscreteVariable); };
158  };
159 
161 
162  std::ostream& operator<<(std::ostream&, const DiscreteVariable&);
163 
164 } /* namespace gum */
165 
166 #ifndef GUM_NO_INLINE
168 #endif /* GUM_NO_INLINE */
169 
170 #endif /* GUM_DISCRETE_VARIABLE_H */
std::vector< std::string > labels() const
vector of labels
Base class for every random variable.
Definition: variable.h:63
DiscreteVariable & operator=(const DiscreteVariable &aRV)
Copy operator.
virtual double numerical(Idx indice) const =0
get a numerical representation of the indice-th value.
virtual const std::string domain() const =0
string represent the domain of the variable
virtual DiscreteVariable * clone() const =0
Copy Factory.
virtual VarType varType() const =0
returns the varType of variable
Classes providing basic hash functions for hash tables.
Idx operator[](const std::string &label) const
from the label to its index in var.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
virtual bool operator==(const DiscreteVariable &aRV) const
equality operator
const std::string toStringWithDescription() const
string version of *this using description attribute instead of name.
virtual Size domainSize() const =0
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map&#39;s DAG in output using the Graphviz-dot format.
Definition: BayesNet_tpl.h:583
virtual std::string label(Idx i) const =0
get the indice-th label. This method is pure virtual.
virtual bool operator!=(const DiscreteVariable &aRV) const
inequality operator
VarType
Definition: variable.h:38
virtual Idx index(const std::string &label) const =0
Base class for random variable.
virtual ~DiscreteVariable()
destructor
DiscreteVariable()
(protected) Default constructor
const std::string toString() const
string version of *this
Size Idx
Type for indexes.
Definition: types.h:50
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45