aGrUM  0.14.2
PRMInstance.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_INSTANCE_H
28 #define GUM_INSTANCE_H
29 
30 #include <set>
31 #include <utility>
32 
33 #include <agrum/core/bijection.h>
34 
37 
38 namespace gum {
39  namespace prm {
40 
41 
59  template < typename GUM_SCALAR >
60  class PRMInstance : public PRMObject {
61  public:
62  // ========================================================================
64  // ========================================================================
66 
80  PRMInstance< GUM_SCALAR >(const std::string& name,
82 
84  virtual ~PRMInstance< GUM_SCALAR >();
85 
87  // ========================================================================
89  // ========================================================================
91 
95  virtual prm_type obj_type() const;
96 
101 
105  const PRMClass< GUM_SCALAR >& type() const;
106 
111  bool exists(NodeId id) const;
112 
117  bool exists(const std::string& name) const;
118 
136 
145  PRMAttribute< GUM_SCALAR >& get(const std::string& name);
146 
163  const PRMAttribute< GUM_SCALAR >& get(NodeId id) const;
164 
173  const PRMAttribute< GUM_SCALAR >& get(const std::string& name) const;
174 
179  Size size() const;
180 
182  // ========================================================================
184  // ========================================================================
186 
199  void instantiate();
200 
214  bijection() const;
215 
217  // ========================================================================
219  // ========================================================================
221 
250  void add(NodeId id, PRMInstance< GUM_SCALAR >& instance);
251 
270 
282 
289  bool hasRefAttr(NodeId id) const;
290 
294  std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
295  getRefAttr(NodeId id);
296 
300  const std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
301  getRefAttr(NodeId id) const;
302 
304  // ========================================================================
306  // ========================================================================
308 
311  typedef
313 
317  iterator begin();
318 
321  const iterator& end();
322 
327 
331  const_iterator begin() const;
332 
335  const const_iterator& end() const;
336 
342  class RefIterator {
343  public:
344  explicit RefIterator(Set< PRMInstance< GUM_SCALAR >* >& set);
345 
346  RefIterator(const RefIterator& from);
347 
348  ~RefIterator();
349 
350  RefIterator& operator=(const RefIterator& from);
351 
353 
354  bool isEnd() const;
355 
356  bool operator!=(const RefIterator& from) const;
357 
358  bool operator==(const RefIterator& from) const;
359 
362 
363  private:
366  };
367 
387 
394  public:
395  explicit RefConstIterator(const Set< PRMInstance< GUM_SCALAR >* >& set);
396 
397  RefConstIterator(const RefConstIterator& from);
398 
399  ~RefConstIterator();
400 
402 
404 
405  bool isEnd() const;
406 
407  bool operator!=(const RefConstIterator& from) const;
408 
409  bool operator==(const RefConstIterator& from) const;
410 
411  const PRMInstance< GUM_SCALAR >& operator*() const;
412  const PRMInstance< GUM_SCALAR >* operator->() const;
413 
414  private:
417  };
418 
437  RefConstIterator begin(NodeId id) const;
438 
439  typedef typename NodeProperty< std::vector<
440  std::pair< PRMInstance< GUM_SCALAR >*, std::string > >* >::iterator
442  typedef typename NodeProperty< std::vector<
443  std::pair< PRMInstance< GUM_SCALAR >*, std::string > >* >::const_iterator
445 
447  const InvRefIterator& endInvRef();
448 
450  const InvRefConstIterator& endInvRef() const;
451 
453  private:
455  PRMInstance(const PRMInstance< GUM_SCALAR >& source);
456 
459 
460  // ========================================================================
462  // ========================================================================
464 
467 
471 
475  void __doInstantiate();
476 
481 
489 
496 
498  // ========================================================================
500  // ========================================================================
502 
505 
508 
512 
517 
519  typedef std::pair< PRMInstance< GUM_SCALAR >*, std::string > pair;
520 
524 
527 
529  };
530 
531 
532 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
533  extern template class PRMInstance< double >;
534 #endif
535 
536 
537  } /* namespace prm */
538 } /* namespace gum */
539 
541 
542 #endif /* GUM_INSTANCE_H */
PRMClass< GUM_SCALAR > * __type
The type of this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:507
const PRMInstance< GUM_SCALAR > & getInstance(NodeId id) const
Fast access to the first instance in a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>.
Unsafe Const Iterators for hashtablesHashTableConstIterator provides a fast but unsafe way to parse H...
Definition: hashTable.h:2462
Set< PRMInstance< GUM_SCALAR > *>::const_iterator __iter
Definition: PRMInstance.h:416
void add(NodeId id, PRMInstance< GUM_SCALAR > &instance)
Add an PRMInstance<GUM_SCALAR> to a given PRMReferenceSlot, PRMSlotChain<GUM_SCALAR> or output node...
PRMInstance(const std::string &name, PRMClass< GUM_SCALAR > &type)
Default constructor of an PRMInstance<GUM_SCALAR>.
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:32
Inline implementation of gum::PRMInstance.
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
Definition: PRMInstance.h:60
void instantiate()
Instantiate all nodes which requires it.
bool operator==(const RefIterator &from) const
Headers of gum::prm::Class<GUM_SCALAR>.
void __addReferingInstance(PRMSlotChain< GUM_SCALAR > *sc, PRMInstance< GUM_SCALAR > *i)
Add this as a referring instance over the attribute pointed by sc in i.
Unsafe Iterators for hashtablesHashTableIterator provides a fast but unsafe way to parse HashTables...
Definition: hashTable.h:2747
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
std::pair< PRMInstance< GUM_SCALAR > *, std::string > pair
Code alias.
Definition: PRMInstance.h:519
Bijection< const DiscreteVariable *, const DiscreteVariable *> __bijection
A bijection used for MultiDim handling.
Definition: PRMInstance.h:526
PRMInstance< GUM_SCALAR > * operator->() const
NodeProperty< std::vector< pair > *> __referingAttr
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:523
bool exists(NodeId id) const
Returns true if id matches an PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
void __doInstantiate()
Starts this instance instantiations.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
bool __instantiated
True if this instance has been instantiated.
Definition: PRMInstance.h:504
Size size() const
Returns the number of attributes in this PRMInstance<GUM_SCALAR>.
NodeProperty< Set< PRMInstance< GUM_SCALAR > *> *> __referenceMap
Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in __type / and...
Definition: PRMInstance.h:516
RefIterator(Set< PRMInstance< GUM_SCALAR > * > &set)
Nested class to iterate over PRMReferenceSlot and PRMSlotChain<GUM_SCALAR> instantiations.
Definition: PRMInstance.h:393
void __copyAttributeCPF(PRMAttribute< GUM_SCALAR > *attr)
Copy the content of an PRMAttribute<GUM_SCALAR> from its Class<GUM_SCALAR> counterpart.
void __instantiateSlotChain(PRMSlotChain< GUM_SCALAR > *sc)
Retrieve all instances referred by sc.
InvRefIterator beginInvRef()
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > & getRefAttr(NodeId id)
Returns a vector of pairs of refering attributes of id.
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:162
PRMInstance< GUM_SCALAR > & operator*() const
void __copyAttribute(PRMAttribute< GUM_SCALAR > *source)
Used at construction to instantiate attributes.
prm_type
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:66
NodeProperty< std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > *>::iterator InvRefIterator
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:441
void __copyAggregates(PRMAggregate< GUM_SCALAR > *source)
Used at construction to instantiate aggregates.
const Bijection< const DiscreteVariable *, const DiscreteVariable *> & bijection() const
Returns a mapping between DiscreteVariable used in this and the ones used in this PRMInstance<GUM_SCA...
Set< PRMInstance< GUM_SCALAR > *> & __set
Definition: PRMInstance.h:364
NodeProperty< std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > *>::const_iterator InvRefConstIterator
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:444
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
virtual prm_type obj_type() const
Returns the PRM type of this object.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
Definition: PRMObject.h:218
Abstract base class for any element defined in a PRM.
Definition: PRMObject.h:53
Set< PRMInstance< GUM_SCALAR > *>::iterator __iter
Definition: PRMInstance.h:365
const iterator & end()
Returns a reference over the iterator at the end of the list of gum::prm::PRMAttribute<GUM_SCALAR> in...
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
Definition: PRMClass.h:63
bool hasRefAttr(NodeId id) const
Returns true if id has at least one referring PRMAttribute<GUM_SCALAR>.
NodeProperty< PRMAttribute< GUM_SCALAR > *>::iterator iterator
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:312
PRMAttribute is a member of a Class in a PRM.
Definition: PRMAttribute.h:58
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
RefIterator & operator=(const RefIterator &from)
iterator begin()
Returns an iterator at the begining of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInst...
Nested class to iterate over PRMReferenceSlot and PRMSlotChain<GUM_SCALAR> instantiations.
Definition: PRMInstance.h:342
const InvRefIterator & endInvRef()
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
Headers of gum::prm::PRMClassElementContainer.
NodeProperty< PRMAttribute< GUM_SCALAR > *>::const_iterator const_iterator
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:326
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Set of pairs of elements with fast search for both elements.
bool operator!=(const RefIterator &from) const
NodeProperty< PRMAttribute< GUM_SCALAR > *> __nodeIdMap
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:511
const Set< PRMInstance< GUM_SCALAR > *> & getInstances(NodeId id) const
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.
const Set< PRMInstance< GUM_SCALAR > *> & __set
Definition: PRMInstance.h:415