aGrUM  0.18.1
a C++ library for (probabilistic) graphical models
PRMInstance.h
Go to the documentation of this file.
1 
30 #ifndef GUM_INSTANCE_H
31 #define GUM_INSTANCE_H
32 
33 #include <set>
34 #include <utility>
35 
37 
40 
41 namespace gum {
42  namespace prm {
43 
44 
62  template < typename GUM_SCALAR >
63  class PRMInstance: public PRMObject {
64  public:
65  // ========================================================================
67  // ========================================================================
69 
83  PRMInstance< GUM_SCALAR >(const std::string& name,
85 
87  virtual ~PRMInstance< GUM_SCALAR >();
88 
90  // ========================================================================
92  // ========================================================================
94 
98  virtual prm_type obj_type() const;
99 
104 
108  const PRMClass< GUM_SCALAR >& type() const;
109 
114  bool exists(NodeId id) const;
115 
120  bool exists(const std::string& name) const;
121 
139 
148  PRMAttribute< GUM_SCALAR >& get(const std::string& name);
149 
166  const PRMAttribute< GUM_SCALAR >& get(NodeId id) const;
167 
176  const PRMAttribute< GUM_SCALAR >& get(const std::string& name) const;
177 
182  Size size() const;
183 
185  // ========================================================================
187  // ========================================================================
189 
202  void instantiate();
203 
217  bijection() const;
218 
220  // ========================================================================
222  // ========================================================================
224 
253  void add(NodeId id, PRMInstance< GUM_SCALAR >& instance);
254 
273 
285 
292  bool hasRefAttr(NodeId id) const;
293 
297  std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
298  getRefAttr(NodeId id);
299 
303  const std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
304  getRefAttr(NodeId id) const;
305 
307  // ========================================================================
309  // ========================================================================
311 
314  typedef
316 
320  iterator begin();
321 
324  const iterator& end();
325 
330 
334  const_iterator begin() const;
335 
338  const const_iterator& end() const;
339 
345  class RefIterator {
346  public:
347  explicit RefIterator(Set< PRMInstance< GUM_SCALAR >* >& set);
348 
349  RefIterator(const RefIterator& from);
350 
351  ~RefIterator();
352 
353  RefIterator& operator=(const RefIterator& from);
354 
356 
357  bool isEnd() const;
358 
359  bool operator!=(const RefIterator& from) const;
360 
361  bool operator==(const RefIterator& from) const;
362 
365 
366  private:
369  };
370 
390 
397  public:
398  explicit RefConstIterator(const Set< PRMInstance< GUM_SCALAR >* >& set);
399 
400  RefConstIterator(const RefConstIterator& from);
401 
402  ~RefConstIterator();
403 
405 
407 
408  bool isEnd() const;
409 
410  bool operator!=(const RefConstIterator& from) const;
411 
412  bool operator==(const RefConstIterator& from) const;
413 
414  const PRMInstance< GUM_SCALAR >& operator*() const;
415  const PRMInstance< GUM_SCALAR >* operator->() const;
416 
417  private:
420  };
421 
440  RefConstIterator begin(NodeId id) const;
441 
442  typedef typename NodeProperty< std::vector<
443  std::pair< PRMInstance< GUM_SCALAR >*, std::string > >* >::iterator
445  typedef typename NodeProperty< std::vector<
446  std::pair< PRMInstance< GUM_SCALAR >*, std::string > >* >::const_iterator
448 
450  const InvRefIterator& endInvRef();
451 
453  const InvRefConstIterator& endInvRef() const;
454 
456  private:
458  PRMInstance(const PRMInstance< GUM_SCALAR >& source);
459 
462 
463  // ========================================================================
465  // ========================================================================
467 
470 
474 
478  void doInstantiate__();
479 
484 
492 
499 
501  // ========================================================================
503  // ========================================================================
505 
508 
511 
515 
520 
522  typedef std::pair< PRMInstance< GUM_SCALAR >*, std::string > pair;
523 
527 
530 
532  };
533 
534 
535 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
536  extern template class PRMInstance< double >;
537 #endif
538 
539 
540  } /* namespace prm */
541 } /* namespace gum */
542 
544 
545 #endif /* GUM_INSTANCE_H */
void copyAggregates__(PRMAggregate< GUM_SCALAR > *source)
Used at construction to instantiate aggregates.
NodeProperty< std::vector< pair > *> referingAttr__
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:526
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:2465
void doInstantiate__()
Starts this instance instantiations.
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:35
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
Definition: PRMInstance.h:63
void instantiate()
Instantiate all nodes which requires it.
bool operator==(const RefIterator &from) const
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Unsafe Iterators for hashtablesHashTableIterator provides a fast but unsafe way to parse HashTables...
Definition: hashTable.h:2750
void instantiateSlotChain__(PRMSlotChain< GUM_SCALAR > *sc)
Retrieve all instances referred by sc.
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
std::pair< PRMInstance< GUM_SCALAR > *, std::string > pair
Code alias.
Definition: PRMInstance.h:522
PRMInstance< GUM_SCALAR > * operator->() const
bool exists(NodeId id) const
Returns true if id matches an PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:679
Size size() const
Returns the number of attributes in this PRMInstance<GUM_SCALAR>.
RefIterator(Set< PRMInstance< GUM_SCALAR > * > &set)
Nested class to iterate over PRMReferenceSlot and PRMSlotChain<GUM_SCALAR> instantiations.
Definition: PRMInstance.h:396
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:165
PRMInstance< GUM_SCALAR > & operator*() const
Set< PRMInstance< GUM_SCALAR > *> & set__
Definition: PRMInstance.h:367
prm_type
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:69
void copyAttributeCPF__(PRMAttribute< GUM_SCALAR > *attr)
Copy the content of an PRMAttribute<GUM_SCALAR> from its Class<GUM_SCALAR> counterpart.
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:444
const Set< PRMInstance< GUM_SCALAR > *> & set__
Definition: PRMInstance.h:418
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...
bool instantiated__
True if this instance has been instantiated.
Definition: PRMInstance.h:507
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:447
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1805
virtual prm_type obj_type() const
Returns the PRM type of this object.
Set< PRMInstance< GUM_SCALAR > *>::iterator iter__
Definition: PRMInstance.h:368
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
Definition: PRMObject.h:221
Abstract base class for any element defined in a PRM.
Definition: PRMObject.h:56
Bijection< const DiscreteVariable *, const DiscreteVariable *> bijection__
A bijection used for MultiDim handling.
Definition: PRMInstance.h:529
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:66
Set< PRMInstance< GUM_SCALAR > *>::const_iterator iter__
Definition: PRMInstance.h:419
PRMClass< GUM_SCALAR > * type__
The type of this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:510
void addReferingInstance__(PRMSlotChain< GUM_SCALAR > *sc, PRMInstance< GUM_SCALAR > *i)
Add this as a referring instance over the attribute pointed by sc in i.
bool hasRefAttr(NodeId id) const
Returns true if id has at least one referring PRMAttribute<GUM_SCALAR>.
NodeProperty< PRMAttribute< GUM_SCALAR > *> nodeIdMap__
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:514
void copyAttribute__(PRMAttribute< GUM_SCALAR > *source)
Used at construction to instantiate attributes.
NodeProperty< PRMAttribute< GUM_SCALAR > *>::iterator iterator
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:315
PRMAttribute is a member of a Class in a PRM.
Definition: PRMAttribute.h:61
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
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:345
const InvRefIterator & endInvRef()
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
NodeProperty< Set< PRMInstance< GUM_SCALAR > *> *> referenceMap__
Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type__ / and...
Definition: PRMInstance.h:519
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:329
Size NodeId
Type for node ids.
Definition: graphElements.h:98
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
bool operator!=(const RefIterator &from) const
const Set< PRMInstance< GUM_SCALAR > *> & getInstances(NodeId id) const
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.