aGrUM  0.14.2
PRMAggregate.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
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  ***************************************************************************/
27 #ifndef GUM_AGGREGATE_H
28 #define GUM_AGGREGATE_H
29 
30 #include <memory>
31 #include <string>
32 
36 
42 
43 
44 namespace gum {
45  namespace prm {
46 
66  template < typename GUM_SCALAR >
67  class PRMAggregate : public PRMClassElement< GUM_SCALAR > {
68  friend class PRMClass< GUM_SCALAR >;
69 
70  public:
71  // ========================================================================
73  // ========================================================================
75 
77  enum class AggregateType : char {
78  MIN,
79  MAX,
80  COUNT,
81  EXISTS,
82  FORALL,
83  OR,
84  AND,
85  AMPLITUDE,
86  MEDIAN
87  };
88 
97  static AggregateType str2enum(const std::string& str) {
98  if (toLower(str) == "min") {
99  return AggregateType::MIN;
100  } else if (toLower(str) == "max") {
101  return AggregateType::MAX;
102  } else if (toLower(str) == "count") {
103  return AggregateType::COUNT;
104  } else if (toLower(str) == "exists") {
105  return AggregateType::EXISTS;
106  } else if (toLower(str) == "or") {
107  return AggregateType::OR;
108  } else if (toLower(str) == "and") {
109  return AggregateType::AND;
110  } else if (toLower(str) == "forall") {
111  return AggregateType::FORALL;
112  } else if (toLower(str) == "amplitude") {
114  } else if (toLower(str) == "median") {
115  return AggregateType::MEDIAN;
116  } else {
117  std::string msg = "Unknown aggregate: ";
118  msg.append(str);
119  GUM_ERROR(NotFound, msg);
120  }
121  }
122 
124  // ========================================================================
126  // ========================================================================
128 
136  PRMAggregate(const std::string& name,
137  AggregateType aggType,
138  const PRMType& rvType);
139 
148  PRMAggregate(const std::string& name,
149  AggregateType aggType,
150  const PRMType& rvType,
151  Idx label);
152 
154  virtual ~PRMAggregate();
155 
157  // ========================================================================
159  // ========================================================================
161 
164  elt_type() const;
165 
167  AggregateType agg_type() const;
168 
174  Idx label() const;
175  const std::string& labelValue() const;
176 
182  std::shared_ptr< Idx > sharedLabel() const;
183 
189  void sharedLabel(std::shared_ptr< Idx > label);
190 
194  void setLabel(Idx idx);
195  void setLabel(const std::string& label);
196 
200  bool hasLabel() const;
201 
203  virtual void addParent(const PRMClassElement< GUM_SCALAR >& elt);
204 
206  virtual void addChild(const PRMClassElement< GUM_SCALAR >& elt);
207 
209  virtual PRMType& type();
210 
212  virtual const PRMType& type() const;
213 
219  virtual Potential< GUM_SCALAR >& cpf();
220 
226  virtual const Potential< GUM_SCALAR >& cpf() const;
227 
235 
238  private:
239  // ========================================================================
241  // ========================================================================
243 
246 
249  operator=(const PRMAggregate< GUM_SCALAR >& source);
250 
252  // ========================================================================
254  // ========================================================================
256 
259 
263 
267  std::shared_ptr< Idx > __label;
268  // Idx* __label;
269  std::string __label_value;
270 
272  };
273 
274 
275 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
276  extern template class PRMAggregate< double >;
277 #endif
278 
279  } /* namespace prm */
280 } // namespace gum
281 
283 
284 #endif /* GUM_AGGREGATE_H */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:57
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const
See gum::PRMClassElement::elt_type().
static AggregateType str2enum(const std::string &str)
Static method which returns the AggregateType given its string representation.
Definition: PRMAggregate.h:97
MultiDimImplementation< GUM_SCALAR > * buildImpl() const
Returns a pointer over an empty gum::MultiDimImplementation of the good type for this PRMAggregate...
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:32
AggregateType __agg_type
The AggregateType of this aggregate.
Definition: PRMAggregate.h:258
virtual ~PRMAggregate()
Destructor.
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::_addParent().
Abstract class representing an element of PRM class.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Headers of gum::MultiDimImplementation.
void setLabel(Idx idx)
Set the aggregator&#39;s label.
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant() const
See gum::PRMClassElement::elt_type().
PRMAggregate< GUM_SCALAR > & operator=(const PRMAggregate< GUM_SCALAR > &source)
Copy operator. Don&#39;t use it.
std::shared_ptr< Idx > sharedLabel() const
Returns the shared_ptr holding this Aggregate label.
PRMAggregate(const std::string &name, AggregateType aggType, const PRMType &rvType)
Default constructor.
Header of the Potential class.
std::string __label_value
The AggregateType of this aggregate.
Definition: PRMAggregate.h:269
virtual void addChild(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::_addChild().
const std::string & labelValue() const
See gum::PRMClassElement::elt_type().
std::string toLower(std::string str)
Returns the lowercase version of str.
AggregateType agg_type() const
Returns the aggregate of *this.
This is a decoration of the DiscreteVariable class.
Definition: PRMType.h:60
PRMType * __type
The random variable type of this aggregate It is deleted with the aggregate.
Definition: PRMAggregate.h:262
MultiDimAggregator.
std::shared_ptr< Idx > __label
Some aggregators applies only on a given label. This attribute must have the concerned Idx...
Definition: PRMAggregate.h:267
virtual Potential< GUM_SCALAR > & cpf()
Aggregates don&#39;t have Potential until they are instantiated as PRMAttribute, so this will raise an Op...
Headers of gum::PRMAggregate.
Headers of Class.
AggregateType
The different type of aggregates we can have.
Definition: PRMAggregate.h:77
Headers of gum::PRMClassElement.
Headers of gum::PRMAttribute.
virtual PRMType & type()
See gum::PRMClassElement::type().
bool hasLabel() const
Returns true if the label is defined.
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
Definition: PRMClass.h:63
<agrum/multidim/multiDimImplementation.h>
Size Idx
Type for indexes.
Definition: types.h:50
PRMAttribute is a member of a Class in a PRM.
Definition: PRMAttribute.h:58
Idx label() const
Returns the label&#39;s index on which this aggregate applies.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
Inline implementation of gum::PRMAggregate.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
Headers of gum::PRMScalarAttribute.