aGrUM  0.14.2
PRMSystem.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_SYSTEM_H
28 #define GUM_SYSTEM_H
29 
30 #include <utility>
31 #include <string>
32 
33 #include <agrum/core/hashTable.h>
34 #include <agrum/core/sequence.h>
35 #include <agrum/core/set.h>
36 
37 #include <agrum/graphs/diGraph.h>
38 
40 
44 
45 namespace gum {
46  namespace prm {
47 
55  template < typename GUM_SCALAR >
56  class PRMSystem : public PRMObject {
57  public:
58  // ========================================================================
60  // ========================================================================
62 
64  explicit PRMSystem(const std::string& name);
65 
67  virtual ~PRMSystem();
68 
70  // ========================================================================
72  // ========================================================================
74 
76  const DiGraph& skeleton() const;
77 
83  PRMInstance< GUM_SCALAR >& get(NodeId id);
84 
90  const PRMInstance< GUM_SCALAR >& get(NodeId id) const;
91 
92  NodeId get(const PRMInstance< GUM_SCALAR >& i) const;
93 
94  /* @todo should be removed ?
95  void addArc( const std::string& u,
96  const std::string& v,
97  const std::string& ref );*/
98 
100  // ========================================================================
102  // ========================================================================
104 
106  virtual PRMObject::prm_type obj_type() const;
107 
109  Size size() const;
110 
113  bool exists(const std::string& name) const;
114 
118  bool isInstantiated(const PRMClass< GUM_SCALAR >& c) const;
119 
121  bool isInstance(const std::string& name) const;
122 
124  bool isArray(const std::string& name) const;
125 
130  void groundedBN(BayesNetFactory< GUM_SCALAR >& factory) const;
131 
133  void instantiate();
134 
136  // ========================================================================
138  // ========================================================================
140 
143  PRMInstance< GUM_SCALAR >& get(const std::string& name);
144 
147  const PRMInstance< GUM_SCALAR >& get(const std::string& name) const;
148 
151  const Set< PRMInstance< GUM_SCALAR >* >&
152  get(const PRMClass< GUM_SCALAR >& type) const;
153 
157  NodeId add(PRMInstance< GUM_SCALAR >* i);
158 
160  // ========================================================================
162  // ========================================================================
164 
167  const Sequence< PRMInstance< GUM_SCALAR >* >&
168  getArray(const std::string& name) const;
169 
172  PRMClassElementContainer< GUM_SCALAR >&
173  getArrayType(const std::string& name);
174 
177  const PRMClassElementContainer< GUM_SCALAR >&
178  getArrayType(const std::string& name) const;
179 
186  NodeId add(const std::string& array, PRMInstance< GUM_SCALAR >* i);
187 
194  NodeId add(const std::string& array, PRMInstance< GUM_SCALAR >& i);
195 
200  void addArray(const std::string& array,
201  PRMClassElementContainer< GUM_SCALAR >& type);
202 
204  // ========================================================================
206  // ========================================================================
208 
210  typedef
212 
214  iterator begin();
215 
218  const iterator& end();
219 
223 
225  const_iterator begin() const;
226 
229  const const_iterator& end() const;
230 
232  typedef
234 
238  array_iterator begin(const std::string& a);
239 
243  const array_iterator& end(const std::string& a);
244 
248 
252  const_array_iterator begin(const std::string& a) const;
253 
257  const const_array_iterator& end(const std::string& a) const;
258 
260  private:
262  PRMSystem(const PRMSystem< GUM_SCALAR >& from);
263 
266 
267  // ========================================================================
269  // ========================================================================
271 
274 
278 
281 
285 
288  typedef std::pair< PRMClassElementContainer< GUM_SCALAR >*,
291 
295 
297  // ========================================================================
299  // ========================================================================
301 
307  void __groundRef(const PRMInstance< GUM_SCALAR >& instance,
308  BayesNetFactory< GUM_SCALAR >& factory) const;
309 
314  void __groundAttr(const PRMInstance< GUM_SCALAR >& instance,
315  BayesNetFactory< GUM_SCALAR >& factory) const;
316 
325  void __groundPotential(const PRMInstance< GUM_SCALAR >& instance,
326  const PRMAttribute< GUM_SCALAR >& attr,
327  BayesNetFactory< GUM_SCALAR >& factory) const;
328 
335  const std::string& name,
336  BayesNetFactory< GUM_SCALAR >& factory) const;
338  };
339 
340 
341 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
342  extern template class PRMSystem< double >;
343 #endif
344 
345 
346  } /* namespace prm */
347 
348 } /* namespace gum */
349 
351 
352 #endif // GUM_SYSTEM_H
void __groundPotential(const PRMInstance< GUM_SCALAR > &instance, const PRMAttribute< GUM_SCALAR > &attr, BayesNetFactory< GUM_SCALAR > &factory) const
Method which copy node&#39;s Potential of an PRMInstance to the grounded Bayesian Network.
Base classes for oriented graphs.
Unsafe Const Iterators for hashtablesHashTableConstIterator provides a fast but unsafe way to parse H...
Definition: hashTable.h:2462
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
Sets of elements (i.e.
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:32
PRMClassElementContainer< GUM_SCALAR > & getArrayType(const std::string &name)
Returns the type of the given array.
iterator begin()
Returns an iterator over the instances in this system.
virtual ~PRMSystem()
Destructor.
Definition: PRMSystem_tpl.h:42
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
Definition: PRMInstance.h:60
NodeProperty< PRMInstance< GUM_SCALAR > *>::iterator iterator
Iterator over the PRMInstance of this PRMSystem.
Definition: PRMSystem.h:211
Headers of gum::prm::Class<GUM_SCALAR>.
Unsafe Iterators for hashtablesHashTableIterator provides a fast but unsafe way to parse HashTables...
Definition: hashTable.h:2747
bool isInstantiated(const PRMClass< GUM_SCALAR > &c) const
Returns true if the given Class<GUM_SCALAR> has at least one PRMInstance in this PRMSystem.
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1019
Abstract class representing an element of PRM class.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
PRMSystem(const std::string &name)
Default constructor.
Definition: PRMSystem_tpl.h:37
NodeId add(PRMInstance< GUM_SCALAR > *i)
Add an PRMInstance to this system.
Definition: PRMSystem_tpl.h:56
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:162
PRMSystem< GUM_SCALAR > & operator=(const PRMSystem< GUM_SCALAR > &from)
Copy operator. Don&#39;t use it.
const DiGraph & skeleton() const
Returns the relation skeleton of this PRMSystem.
prm_type
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:66
bool isInstance(const std::string &name) const
Returns true if an PRMInstance with the given name exists.
virtual PRMObject::prm_type obj_type() const
Returns the PRM type of this object.
void __groundAgg(const PRMClassElement< GUM_SCALAR > &elt, const std::string &name, BayesNetFactory< GUM_SCALAR > &factory) const
Ground an aggregator with the given name in the grounded IBayesNet.
Headers of the BayesNetFactory class.
HashTable< PRMClass< GUM_SCALAR > *, Set< PRMInstance< GUM_SCALAR > *> *> __instanceMap
Mapping between a class and all it&#39;s PRMInstance in this system.
Definition: PRMSystem.h:284
NodeProperty< PRMInstance< GUM_SCALAR > *>::const_iterator const_iterator
Constant Iterator over the PRMInstance of this PRMSystem.
Definition: PRMSystem.h:222
void groundedBN(BayesNetFactory< GUM_SCALAR > &factory) const
Returns the grounded Bayesian Network of this system.
Definition: PRMSystem_tpl.h:79
DiGraph __skeleton
The relational skeleton of this PRMSystem.
Definition: PRMSystem.h:273
Base class for all oriented graphs.
Definition: diGraph.h:108
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition: PRMObject.h:226
HashTable< std::string, PRMInstance< GUM_SCALAR > *> __nameMap
The mapping between PRMInstance and their names.
Definition: PRMSystem.h:280
Sequence< PRMInstance< GUM_SCALAR > *>::iterator array_iterator
Iterator over the PRMInstance in an array in this PRMSystem.
Definition: PRMSystem.h:233
void instantiate()
Instantiate all the PRMInstance in this PRMSystem.
std::pair< PRMClassElementContainer< GUM_SCALAR > *, Sequence< PRMInstance< GUM_SCALAR > *> *> model_pair
Typedef of the pair of a Class<GUM_SCALAR> and the sequence of it&#39;s instantiation.
Definition: PRMSystem.h:290
Sequence< PRMInstance< GUM_SCALAR > *>::const_iterator const_array_iterator
Iterator over the PRMInstance in an array in this PRMSystem.
Definition: PRMSystem.h:247
Headers of gum::prm::PRMInstance<GUM_SCALAR>
bool exists(const std::string &name) const
Retruns true either if name is an instance or an array in this PRMSystem.
void __groundRef(const PRMInstance< GUM_SCALAR > &instance, BayesNetFactory< GUM_SCALAR > &factory) const
Method which ground PRMReferenceSlot of an PRMInstance and add arcs in the IBayesNet.
Size size() const
Returns the number of PRMInstance in this PRMSystem.
bool isArray(const std::string &name) const
Returns true if an array with the given name exists.
const Sequence< PRMInstance< GUM_SCALAR > *> & getArray(const std::string &name) const
Returns the sequence of instances of a given array.
NodeProperty< PRMInstance< GUM_SCALAR > *> __nodeIdMap
The maping between PRMInstance and their NodeId in the relational skeleton of this PRMSystem...
Definition: PRMSystem.h:277
PRMAttribute is a member of a Class in a PRM.
Definition: PRMAttribute.h:58
HashTable< std::string, model_pair > __arrayMap
Mapping between arrays and their name. The first element of the pair is the type of the array...
Definition: PRMSystem.h:294
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
const iterator & end()
Returns a iterator at the end of the set of PRMInstance in this PRMSystem.
void __groundAttr(const PRMInstance< GUM_SCALAR > &instance, BayesNetFactory< GUM_SCALAR > &factory) const
Method which ground Atttributes and Aggregators of an PRMInstance.
Definition: PRMSystem_tpl.h:99
Inline implementation of PRMSystem.
void addArray(const std::string &array, PRMClassElementContainer< GUM_SCALAR > &type)
Add an array of instances in this system. If the array doesn&#39;t exists it is created.
Class hash tables iterators.
Headers of PRMObject.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
A factory class to ease BayesNet construction.
Definition: BayesNet.h:43