aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::prm::PRMInstance< GUM_SCALAR > Class Template Reference

An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem. More...

#include <PRMInstance.h>

+ Inheritance diagram for gum::prm::PRMInstance< GUM_SCALAR >:
+ Collaboration diagram for gum::prm::PRMInstance< GUM_SCALAR >:

Public Member Functions

Constructors & private operators.
 PRMInstance (const std::string &name, PRMClass< GUM_SCALAR > &type)
 Default constructor of an PRMInstance<GUM_SCALAR>. More...
 
virtual ~PRMInstance ()
 Destructor. More...
 
Getters & setters.
virtual prm_type obj_type () const
 Returns the PRM type of this object. More...
 
PRMClass< GUM_SCALAR > & type ()
 Returns the type of this instance. More...
 
const PRMClass< GUM_SCALAR > & type () const
 Returns the type of this instance. More...
 
bool exists (NodeId id) const
 Returns true if id matches an PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 
bool exists (const std::string &name) const
 Returns true if name matches an PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 
PRMAttribute< GUM_SCALAR > & get (NodeId id)
 Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>. More...
 
PRMAttribute< GUM_SCALAR > & get (const std::string &name)
 Given a name returns the related PRMAttribute<GUM_SCALAR>. More...
 
const PRMAttribute< GUM_SCALAR > & get (NodeId id) const
 Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>. More...
 
const PRMAttribute< GUM_SCALAR > & get (const std::string &name) const
 Given a name returns the related PRMClassElement. More...
 
Size size () const
 Returns the number of attributes in this PRMInstance<GUM_SCALAR>. More...
 
Instantiation methods.
void instantiate ()
 Instantiate all nodes which requires it. More...
 
const Bijection< const DiscreteVariable *, const DiscreteVariable *> & bijection () const
 Returns a mapping between DiscreteVariable used in this and the ones used in this PRMInstance<GUM_SCALAR>'s Class<GUM_SCALAR>. More...
 
Reference handling.
void add (NodeId id, PRMInstance< GUM_SCALAR > &instance)
 Add an PRMInstance<GUM_SCALAR> to a given PRMReferenceSlot, PRMSlotChain<GUM_SCALAR> or output node. More...
 
const PRMInstance< GUM_SCALAR > & getInstance (NodeId id) const
 Fast access to the first instance in a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>. More...
 
const Set< PRMInstance< GUM_SCALAR > *> & getInstances (NodeId id) const
 Returns the Set of PRMInstance<GUM_SCALAR> referenced by id. More...
 
bool hasRefAttr (NodeId id) const
 Returns true if id has at least one referring PRMAttribute<GUM_SCALAR>. More...
 
std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > & getRefAttr (NodeId id)
 Returns a vector of pairs of refering attributes of id. More...
 
const std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > & getRefAttr (NodeId id) const
 Returns a vector of pairs of refering attributes of id. More...
 
Getters & setters.
const std::string & name () const
 Returns the name of this object. More...
 
void name (const std::string &name)
 Change the name of the PRM Object. More...
 
Operators
bool operator== (const PRMObject &obj) const
 To PRMObject are equal if they have the same name (which is unique). More...
 
bool operator!= (const PRMObject &obj) const
 To PRMObject are equal if they have the same name (which is unique). More...
 

Classes

class  RefConstIterator
 Nested class to iterate over PRMReferenceSlot and PRMSlotChain<GUM_SCALAR> instantiations. More...
 
class  RefIterator
 Nested class to iterate over PRMReferenceSlot and PRMSlotChain<GUM_SCALAR> instantiations. More...
 

Iterators

typedef NodeProperty< PRMAttribute< GUM_SCALAR > *>::iterator iterator
 Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 
typedef NodeProperty< PRMAttribute< GUM_SCALAR > *>::const_iterator const_iterator
 Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 
typedef 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>. More...
 
typedef 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>. More...
 
iterator begin ()
 Returns an iterator at the begining of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 
const iteratorend ()
 Returns a reference over the iterator at the end of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 
const_iterator begin () const
 Returns an iterator at the beginning of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 
const const_iteratorend () const
 Returns a reference over the iterator at the end of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 
RefIterator begin (NodeId id)
 Returns an iterator at the beginning of the set of PRMInstance<GUM_SCALAR> associated to a given gum::prm::PRMReferenceSlot or gum::prm::PRMSlotChain<GUM_SCALAR>. More...
 
RefConstIterator begin (NodeId id) const
 Returns an iterator at the beginning of the set of PRMInstance<GUM_SCALAR> associated to a given gum::prm::PRMReferenceSlot or gum::prm::PRMSlotChain<GUM_SCALAR>. More...
 
InvRefIterator beginInvRef ()
 Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 
const InvRefIteratorendInvRef ()
 Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 
InvRefConstIterator beginInvRef () const
 Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 
const InvRefConstIteratorendInvRef () const
 Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>. More...
 

Private members.

typedef std::pair< PRMInstance< GUM_SCALAR > *, std::string > pair
 Code alias. More...
 
bool _instantiated_
 True if this instance has been instantiated. More...
 
PRMClass< GUM_SCALAR > * _type_
 The type of this PRMInstance<GUM_SCALAR>. More...
 
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
 The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>. More...
 
NodeProperty< Set< PRMInstance< GUM_SCALAR > *> *> _referenceMap_
 Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type / and the PRMInstance<GUM_SCALAR> associated with it. More...
 
NodeProperty< std::vector< pair > *> _referingAttr_
 The set of pair (instance, attribute) referring an attribute of this instance. More...
 
Bijection< const DiscreteVariable *, const DiscreteVariable *> _bijection_
 A bijection used for MultiDim handling. More...
 

Built-in types.

enum  prm_type : char {
  prm_type::ALL, prm_type::CLASS, prm_type::PRM_INTERFACE, prm_type::CLASS_ELT,
  prm_type::TYPE, prm_type::SYSTEM, prm_type::INSTANCE
}
 Enumeration of the different types of objects handled by a PRM. More...
 
static std::string LEFT_CAST ()
 Enumeration of the different types of objects handled by a PRM. More...
 
static std::string RIGHT_CAST ()
 Enumeration of the different types of objects handled by a PRM. More...
 
static std::string enum2str (prm_type type)
 Returns the string representation of a PRMObject. More...
 
static INLINE bool isClass (const PRMObject &obj)
 Returns true if obj_ptr is of type Class. More...
 
static INLINE bool isInterface (const PRMObject &obj)
 Returns true if obj_ptr is of type PRMInterface. More...
 
static INLINE bool isInstance (const PRMObject &obj)
 Returns true if obj_ptr is of type PRMInstance. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::PRMInstance< GUM_SCALAR >

An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.

Before using an PRMInstance for inference YOU MUST call PRMInstance::instantiateSlotChains() and PRMInstance::instantiate() on it before, otherwise DiscreteVariable pointers will be inconsistent and inference will be erroneous. Of course, this must be done once you have set all reference in the current system.

See also
PRMClass PRM PRMClassElement

Definition at line 62 of file PRMInstance.h.

Member Typedef Documentation

◆ const_iterator

template<typename GUM_SCALAR>
typedef NodeProperty< PRMAttribute< GUM_SCALAR >* >::const_iterator gum::prm::PRMInstance< GUM_SCALAR >::const_iterator

Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 323 of file PRMInstance.h.

◆ InvRefConstIterator

template<typename GUM_SCALAR>
typedef NodeProperty< std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >* >::const_iterator gum::prm::PRMInstance< GUM_SCALAR >::InvRefConstIterator

Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 441 of file PRMInstance.h.

◆ InvRefIterator

template<typename GUM_SCALAR>
typedef NodeProperty< std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >* >::iterator gum::prm::PRMInstance< GUM_SCALAR >::InvRefIterator

Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 438 of file PRMInstance.h.

◆ iterator

template<typename GUM_SCALAR>
typedef NodeProperty< PRMAttribute< GUM_SCALAR >* >::iterator gum::prm::PRMInstance< GUM_SCALAR >::iterator

Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 310 of file PRMInstance.h.

◆ pair

template<typename GUM_SCALAR>
typedef std::pair< PRMInstance< GUM_SCALAR >*, std::string > gum::prm::PRMInstance< GUM_SCALAR >::pair
private

Code alias.

Definition at line 515 of file PRMInstance.h.

Member Enumeration Documentation

◆ prm_type

enum gum::prm::PRMObject::prm_type : char
stronginherited

Enumeration of the different types of objects handled by a PRM.

The "all" type is used to tell that we want any kind of PRMType (useful with iterators for example). No PRMObject will ever have "all" as type.

Enumerator
ALL 
CLASS 
PRM_INTERFACE 
CLASS_ELT 
TYPE 
SYSTEM 
INSTANCE 

Definition at line 68 of file PRMObject.h.

68  : char
69  {
70  ALL,
71  CLASS,
72  PRM_INTERFACE,
73  CLASS_ELT,
74  TYPE,
75  SYSTEM,
76  INSTANCE
77  };

Constructor & Destructor Documentation

◆ PRMInstance() [1/2]

template<typename GUM_SCALAR >
gum::prm::PRMInstance< GUM_SCALAR >::PRMInstance ( const std::string &  name,
PRMClass< GUM_SCALAR > &  type 
)

Default constructor of an PRMInstance<GUM_SCALAR>.

When you create an PRMInstance<GUM_SCALAR> all gum::prm::PRMAttribute<GUM_SCALAR> in it's type are added, except for gum::prm::PRMAggregate<GUM_SCALAR> and parameters which are instantiated.

However neither of their children or parents are updated (i.e. DiscreteVariable pointers are inconsistent).

Definition at line 36 of file PRMInstance_tpl.h.

36  :
38  GUM_CONSTRUCTOR(PRMInstance);
39 
40  // First we create attributes for each aggregate in type
41  for (const auto agg: _type_->aggregates())
42  _copyAggregates_(agg);
43 
44  // We add attributes in type by reference for inner ones and by copy for
45  // output ones
46  for (const auto attr: _type_->attributes())
47  _copyAttribute_(attr);
48  }
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:34
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
PRMClass< GUM_SCALAR > * _type_
The type of this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:503
bool _instantiated_
True if this instance has been instantiated.
Definition: PRMInstance.h:500
void _copyAttribute_(PRMAttribute< GUM_SCALAR > *source)
Used at construction to instantiate attributes.
PRMObject(const std::string &name)
Constructor.
Definition: PRMObject.cpp:42
void _copyAggregates_(PRMAggregate< GUM_SCALAR > *source)
Used at construction to instantiate aggregates.

◆ ~PRMInstance()

template<typename GUM_SCALAR >
gum::prm::PRMInstance< GUM_SCALAR >::~PRMInstance ( )
virtual

Destructor.

Definition at line 51 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

51  {
52  GUM_DESTRUCTOR(PRMInstance);
53 
54  for (const auto& elt: _nodeIdMap_)
55  delete elt.second;
56 
57  for (const auto& elt: _referenceMap_)
58  delete elt.second;
59 
60  for (const auto& elt: _referingAttr_)
61  delete elt.second;
62  }
PRMInstance(const std::string &name, PRMClass< GUM_SCALAR > &type)
Default constructor of an PRMInstance<GUM_SCALAR>.
NodeProperty< Set< PRMInstance< GUM_SCALAR > *> *> _referenceMap_
Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type / and t...
Definition: PRMInstance.h:512
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
NodeProperty< std::vector< pair > *> _referingAttr_
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:519
+ Here is the call graph for this function:

◆ PRMInstance() [2/2]

template<typename GUM_SCALAR >
INLINE gum::prm::PRMInstance< GUM_SCALAR >::PRMInstance ( const PRMInstance< GUM_SCALAR > &  source)
private

Copy constructor.

Definition at line 247 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

247  :
248  PRMObject(source), _type_(source._type_) {
249  GUM_CONS_CPY(PRMInstance);
250  GUM_ERROR(FatalError, "do not copy Instance")
251  }
PRMInstance(const std::string &name, PRMClass< GUM_SCALAR > &type)
Default constructor of an PRMInstance<GUM_SCALAR>.
PRMClass< GUM_SCALAR > * _type_
The type of this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:503
PRMObject(const std::string &name)
Constructor.
Definition: PRMObject.cpp:42
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

Member Function Documentation

◆ _addReferingInstance_()

template<typename GUM_SCALAR >
INLINE void gum::prm::PRMInstance< GUM_SCALAR >::_addReferingInstance_ ( PRMSlotChain< GUM_SCALAR > *  sc,
PRMInstance< GUM_SCALAR > *  i 
)
private

Add this as a referring instance over the attribute pointed by sc in i.

Parameters
scA slot chain pointing over an attribute in i.
iAn instance holding an attribute pointed by sc.

Definition at line 318 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

319  {
320  NodeId id = i->get(sc->lastElt().safeName()).id();
321  std::string name = sc->lastElt().safeName();
322 
323  try {
324  i->_referenceMap_[id]->insert(this);
325  i->_referingAttr_[id]->push_back(std::make_pair(this, sc->lastElt().safeName()));
326  } catch (NotFound&) {
327  i->_referenceMap_.insert(id, new Set< PRMInstance< GUM_SCALAR >* >());
328  i->_referenceMap_[id]->insert(this);
329  i->_referingAttr_.insert(id, new std::vector< pair >());
330  i->_referingAttr_[id]->push_back(std::make_pair(this, sc->lastElt().safeName()));
331  }
332  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ _copyAggregates_()

template<typename GUM_SCALAR >
INLINE void gum::prm::PRMInstance< GUM_SCALAR >::_copyAggregates_ ( PRMAggregate< GUM_SCALAR > *  source)
private

Used at construction to instantiate aggregates.

Definition at line 225 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

225  {
226  auto attr = new PRMScalarAttribute< GUM_SCALAR >(source->name(),
227  source->type(),
228  source->buildImpl());
229  GUM_ASSERT(&(attr->type().variable()) != &(source->type().variable()));
230  attr->setId(source->id());
231  _nodeIdMap_.insert(attr->id(), attr);
232  _bijection_.insert(&(source->type().variable()), &(attr->type().variable()));
233  }
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
Bijection< const DiscreteVariable *, const DiscreteVariable *> _bijection_
A bijection used for MultiDim handling.
Definition: PRMInstance.h:522
+ Here is the call graph for this function:

◆ _copyAttribute_()

template<typename GUM_SCALAR >
INLINE void gum::prm::PRMInstance< GUM_SCALAR >::_copyAttribute_ ( PRMAttribute< GUM_SCALAR > *  source)
private

Used at construction to instantiate attributes.

Parameters
sourceAn attribute in type.

Definition at line 236 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

236  {
237  auto attr = new PRMScalarAttribute< GUM_SCALAR >(source->name(), source->type());
238  GUM_ASSERT(&(attr->type().variable()) != &(source->type().variable()));
239  // The potential is copied when instantiate() is called
240  attr->cpf().fill((GUM_SCALAR)0);
241  attr->setId(source->id());
242  _bijection_.insert(&(source->type().variable()), &(attr->type().variable()));
243  _nodeIdMap_.insert(attr->id(), attr);
244  }
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
Bijection< const DiscreteVariable *, const DiscreteVariable *> _bijection_
A bijection used for MultiDim handling.
Definition: PRMInstance.h:522
+ Here is the call graph for this function:

◆ _copyAttributeCPF_()

template<typename GUM_SCALAR >
INLINE void gum::prm::PRMInstance< GUM_SCALAR >::_copyAttributeCPF_ ( PRMAttribute< GUM_SCALAR > *  attr)
private

Copy the content of an PRMAttribute<GUM_SCALAR> from its Class<GUM_SCALAR> counterpart.

Parameters
attrAn PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
Exceptions
OperationNotAllowedIf the MultiDimImplementation is of an unknown type.

Definition at line 570 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

570  {
571  const auto& type_attr
572  = static_cast< const PRMAttribute< GUM_SCALAR >& >(type().get(attr->safeName()));
573  attr->copyCpf(bijection(), type_attr);
574  GUM_ASSERT(attr->cpf().contains(attr->type().variable()));
575  }
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
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...
+ Here is the call graph for this function:

◆ _doInstantiate_()

template<typename GUM_SCALAR >
void gum::prm::PRMInstance< GUM_SCALAR >::_doInstantiate_ ( )
private

Starts this instance instantiations.

Definition at line 73 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

73  {
74  // First retrieving any referenced instance
75  for (const auto chain: type().slotChains()) {
77  }
78 
79  // Now we need to add referred instance to each input node
80  // For Attributes we first add parents, then we initialize CPF
81  for (const auto attr: type().attributes()) {
82  _copyAttributeCPF_(_nodeIdMap_[(*attr).id()]);
83  }
84 
85  // For PRMAggregate<GUM_SCALAR> we add parents
86  for (const auto agg: type().aggregates()) {
87  PRMAttribute< GUM_SCALAR >& attr = get(agg->safeName());
88 
89  for (const auto node: type().containerDag().parents(agg->id())) {
90  try {
91  attr.addParent(get(node));
92  } catch (NotFound&) {
93  auto elt = &(type().get(node));
94  auto sc = static_cast< PRMSlotChain< GUM_SCALAR >* >(elt);
95 
96  try {
97  const auto& instances = getInstances(sc->id());
98 
99  for (const auto inst: instances) {
100  attr.addParent(inst->get(sc->lastElt().safeName()));
101  }
102  } catch (NotFound&) { // there is no parents for this agg
103  }
104  }
105  }
106  }
107  }
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
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.
const Set< PRMInstance< GUM_SCALAR > *> & getInstances(NodeId id) const
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.
+ Here is the call graph for this function:

◆ _instantiateSlotChain_()

template<typename GUM_SCALAR >
void gum::prm::PRMInstance< GUM_SCALAR >::_instantiateSlotChain_ ( PRMSlotChain< GUM_SCALAR > *  sc)
private

Retrieve all instances referred by sc.

Parameters
scA slot chain of this instance's type.
Exceptions
NotFoundRaised if a reference in sc is not instantiated.

Definition at line 110 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

110  {
111  auto first_id = sc->chain()[0]->id();
112  if (!_referenceMap_.exists(first_id)) { return; }
113  auto set = new Set< PRMInstance< GUM_SCALAR >* >(*(_referenceMap_[first_id]));
114  // We proceed with a width-first run of the slot chain
115  for (Size idx = 1; idx < sc->chain().size() - 1; ++idx) {
116  auto temp = new Set< PRMInstance< GUM_SCALAR >* >();
117  for (auto current: *set) {
118  auto& ref = current->type().get(sc->chain()[idx]->name());
119  for (auto next: *(current->_referenceMap_[ref.id()])) {
120  temp->insert(next);
121  }
122  }
123  delete set;
124  set = temp;
125  }
126 
127  GUM_ASSERT(set->size() > 0);
128  // set contains all the instances references by sc
129  if (_referenceMap_.exists(sc->id())) {
130  delete _referenceMap_[sc->id()];
131  _referenceMap_[sc->id()] = set;
132  } else {
133  _referenceMap_.insert(sc->id(), set);
134  }
135 
136  // Add refering instances
137  for (auto i: *set) {
138  _addReferingInstance_(sc, i);
139  }
140 
141  // If sc is not multiple so it can be added as a parent of an attribute
142  if (!sc->isMultiple()) {
143  // We should have only one instance
144  // Less ugly way to get the single instance in set
145  for (auto instance: *set) {
146  auto& attr = instance->get(sc->lastElt().safeName());
147  _bijection_.insert(&(sc->type().variable()), &(attr.type().variable()));
148  }
149  }
150  }
NodeProperty< Set< PRMInstance< GUM_SCALAR > *> *> _referenceMap_
Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type / and t...
Definition: PRMInstance.h:512
Bijection< const DiscreteVariable *, const DiscreteVariable *> _bijection_
A bijection used for MultiDim handling.
Definition: PRMInstance.h:522
void _addReferingInstance_(PRMSlotChain< GUM_SCALAR > *sc, PRMInstance< GUM_SCALAR > *i)
Add this as a referring instance over the attribute pointed by sc in i.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ add()

template<typename GUM_SCALAR >
void gum::prm::PRMInstance< GUM_SCALAR >::add ( NodeId  id,
PRMInstance< GUM_SCALAR > &  instance 
)

Add an PRMInstance<GUM_SCALAR> to a given PRMReferenceSlot, PRMSlotChain<GUM_SCALAR> or output node.

Three type of nodes can be associated with an PRMInstance<GUM_SCALAR>. When an PRMInstance<GUM_SCALAR> is associated with a PRMReferenceSlot, it represents an arc in the relational skeleton. For a PRMSlotChain<GUM_SCALAR>, it is a placeholder of referenced PRMClassElement by this PRMInstance<GUM_SCALAR>. Finally, for an output node it indicates that an PRMInstance<GUM_SCALAR> has an PRMClassElement referring it.

Parameters
idThe NodeId of a PRMReferenceSlot of this PRMInstance<GUM_SCALAR>.
instanceThe instance added as references by id in this PRMInstance<GUM_SCALAR>.
Exceptions
WrongClassElementRaised if id is not a valid PRMClassElement.
OutOfUpperBoundRaised if no more PRMInstance<GUM_SCALAR> can be added to id.
PRMTypeErrorRaised if instance's type isn't compatible with the reference's type.
NotFoundIf there is no PRMClassElement given id.

Definition at line 153 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

153  {
154  PRMClassElement< GUM_SCALAR >* elt = 0;
155 
156  try {
157  elt = &(type().get(id));
158  } catch (NotFound&) {
159  GUM_ERROR(NotFound, "no ClassElement<GUM_SCALAR> matches the given id")
160  }
161 
162  switch (elt->elt_type()) {
164  PRMReferenceSlot< GUM_SCALAR >* ref = static_cast< PRMReferenceSlot< GUM_SCALAR >* >(elt);
165 
166  // Checking if instance's type is legal
167  if (!instance.type().isSubTypeOf(ref->slotType())) {
168  GUM_ERROR(PRMTypeError,
169  "given Instance type is not a proper "
170  "subclass of the ReferenceSlot<GUM_SCALAR> slot type");
171  }
172 
173  // Checking the reference's size limit
174  if (_referenceMap_.exists(id)
175  && (!static_cast< PRMReferenceSlot< GUM_SCALAR >& >(type().get(id)).isArray())
176  && (_referenceMap_[id]->size() == 1)) {
177  GUM_ERROR(OutOfUpperBound, "ReferenceSlot<GUM_SCALAR> size limit reached")
178  }
179 
180  break;
181  }
182 
184  PRMSlotChain< GUM_SCALAR >& sc
185  = static_cast< PRMSlotChain< GUM_SCALAR >& >(type().get(id));
186 
187  // Checking if instance's type is legal
188  if (!instance.type().isSubTypeOf(sc.end())) {
189  GUM_ERROR(PRMTypeError,
190  "given Instance type is not a proper "
191  "subclass of the ClassElementContainer pointed"
192  " by the SlotChain<GUM_SCALAR>");
193  }
194 
195  // Checking the reference's size limit
196  if (_referenceMap_.exists(id)
197  && (!static_cast< PRMSlotChain< GUM_SCALAR >& >(type().get(id)).isMultiple())
198  && (_referenceMap_[id]->size() == 1)) {
199  GUM_ERROR(OutOfUpperBound, "SlotChain<GUM_SCALAR> size limit reached")
200  }
201 
202  break;
203  }
204 
205  default: {
206  if (!type().isOutputNode(*elt)) {
207  GUM_ERROR(WrongClassElement, "given ClassElement<GUM_SCALAR> is not an output node")
208  }
209  }
210  }
211 
212  if (!_referenceMap_.exists(id)) {
213  _referenceMap_.insert(id, new Set< PRMInstance< GUM_SCALAR >* >());
214  }
215 
216  _referenceMap_[id]->insert(&instance);
217  }
NodeProperty< Set< PRMInstance< GUM_SCALAR > *> *> _referenceMap_
Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type / and t...
Definition: PRMInstance.h:512
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
Size size() const
Returns the number of attributes in this PRMInstance<GUM_SCALAR>.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ begin() [1/4]

template<typename GUM_SCALAR >
INLINE PRMInstance< GUM_SCALAR >::iterator gum::prm::PRMInstance< GUM_SCALAR >::begin ( )

Returns an iterator at the begining of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 369 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

369  {
370  return _nodeIdMap_.begin();
371  }
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
+ Here is the call graph for this function:

◆ begin() [2/4]

template<typename GUM_SCALAR >
INLINE PRMInstance< GUM_SCALAR >::const_iterator gum::prm::PRMInstance< GUM_SCALAR >::begin ( ) const

Returns an iterator at the beginning of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 380 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

380  {
381  return _nodeIdMap_.begin();
382  }
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
+ Here is the call graph for this function:

◆ begin() [3/4]

template<typename GUM_SCALAR >
INLINE PRMInstance< GUM_SCALAR >::RefIterator gum::prm::PRMInstance< GUM_SCALAR >::begin ( NodeId  id)

Returns an iterator at the beginning of the set of PRMInstance<GUM_SCALAR> associated to a given gum::prm::PRMReferenceSlot or gum::prm::PRMSlotChain<GUM_SCALAR>.

Parameters
idA gum::prm::PRMReferenceSlot or gum::prm::PRMSlotChain<GUM_SCALAR> in this PRMInstance<GUM_SCALAR> type.
Exceptions
NotFoundRaised if no gum::prm::PRMClassElement in this PRMInstance<GUM_SCALAR> type matches id.
WrongClassElementRaised if id is neither a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>.

Definition at line 392 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

392  {
393  try {
394  return PRMInstance< GUM_SCALAR >::RefIterator(*(_referenceMap_[id]));
395  } catch (NotFound&) { GUM_ERROR(NotFound, "no referred instances from this NodeId") }
396  }
NodeProperty< Set< PRMInstance< GUM_SCALAR > *> *> _referenceMap_
Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type / and t...
Definition: PRMInstance.h:512
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ begin() [4/4]

template<typename GUM_SCALAR >
INLINE PRMInstance< GUM_SCALAR >::RefConstIterator gum::prm::PRMInstance< GUM_SCALAR >::begin ( NodeId  id) const

Returns an iterator at the beginning of the set of PRMInstance<GUM_SCALAR> associated to a given gum::prm::PRMReferenceSlot or gum::prm::PRMSlotChain<GUM_SCALAR>.

Parameters
idA gum::prm::PRMReferenceSlot or gum::prm::PRMSlotChain<GUM_SCALAR> in this PRMInstance<GUM_SCALAR> type.
Exceptions
NotFoundRaised if no gum::prm::PRMClassElement in this PRMInstance<GUM_SCALAR> type matches id.
WrongClassElementRaised if id is neither a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>.

Definition at line 400 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

400  {
401  try {
402  return PRMInstance< GUM_SCALAR >::RefConstIterator(*(_referenceMap_[id]));
403  } catch (NotFound&) { GUM_ERROR(NotFound, "no referred instances from this NodeId") }
404  }
NodeProperty< Set< PRMInstance< GUM_SCALAR > *> *> _referenceMap_
Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type / and t...
Definition: PRMInstance.h:512
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ beginInvRef() [1/2]

template<typename GUM_SCALAR >
INLINE PRMInstance< GUM_SCALAR >::InvRefIterator gum::prm::PRMInstance< GUM_SCALAR >::beginInvRef ( )

Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 530 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

530  {
531  return _referingAttr_.begin();
532  }
NodeProperty< std::vector< pair > *> _referingAttr_
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:519
+ Here is the call graph for this function:

◆ beginInvRef() [2/2]

template<typename GUM_SCALAR >
INLINE PRMInstance< GUM_SCALAR >::InvRefConstIterator gum::prm::PRMInstance< GUM_SCALAR >::beginInvRef ( ) const

Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 542 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

542  {
543  return _referingAttr_.begin();
544  }
NodeProperty< std::vector< pair > *> _referingAttr_
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:519
+ Here is the call graph for this function:

◆ bijection()

template<typename GUM_SCALAR >
INLINE const Bijection< const DiscreteVariable *, const DiscreteVariable *> & gum::prm::PRMInstance< GUM_SCALAR >::bijection ( ) const

Returns a mapping between DiscreteVariable used in this and the ones used in this PRMInstance<GUM_SCALAR>'s Class<GUM_SCALAR>.

MultiDims require distinctive DiscreteVariable pointers, thus interface attributes are always instantiated to prevent multiple insertion of the same DiscreteVariable pointer in a MultiDim.

Returns
Returns a bijection in which first elements are DiscreteVariable in this->type() and the second are in this.

Definition at line 336 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

336  {
337  return _bijection_;
338  }
Bijection< const DiscreteVariable *, const DiscreteVariable *> _bijection_
A bijection used for MultiDim handling.
Definition: PRMInstance.h:522
+ Here is the call graph for this function:

◆ end() [1/2]

template<typename GUM_SCALAR >
INLINE const PRMInstance< GUM_SCALAR >::iterator & gum::prm::PRMInstance< GUM_SCALAR >::end ( )

Returns a reference over the iterator at the end of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 374 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

374  {
375  return _nodeIdMap_.end();
376  }
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
+ Here is the call graph for this function:

◆ end() [2/2]

template<typename GUM_SCALAR >
INLINE const PRMInstance< GUM_SCALAR >::const_iterator & gum::prm::PRMInstance< GUM_SCALAR >::end ( ) const

Returns a reference over the iterator at the end of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 386 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

386  {
387  return _nodeIdMap_.end();
388  }
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
+ Here is the call graph for this function:

◆ endInvRef() [1/2]

template<typename GUM_SCALAR >
INLINE const PRMInstance< GUM_SCALAR >::InvRefIterator & gum::prm::PRMInstance< GUM_SCALAR >::endInvRef ( )

Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 536 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

536  {
537  return _referingAttr_.end();
538  }
NodeProperty< std::vector< pair > *> _referingAttr_
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:519
+ Here is the call graph for this function:

◆ endInvRef() [2/2]

template<typename GUM_SCALAR >
INLINE const PRMInstance< GUM_SCALAR >::InvRefConstIterator & gum::prm::PRMInstance< GUM_SCALAR >::endInvRef ( ) const

Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 548 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

548  {
549  return _referingAttr_.end();
550  }
NodeProperty< std::vector< pair > *> _referingAttr_
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:519
+ Here is the call graph for this function:

◆ enum2str()

static std::string gum::prm::PRMObject::enum2str ( prm_type  type)
inlinestaticinherited

Returns the string representation of a PRMObject.

Definition at line 83 of file PRMObject.h.

83  {
84  switch (type) {
85  case prm_type::CLASS:
86  return "PRMType::CLASS";
87 
89  return "PRMType::CLASS_ELT";
90 
91  case prm_type::TYPE:
92  return "PRMType::TYPE";
93 
94  case prm_type::SYSTEM:
95  return "PRMType::SYSTEM";
96 
97  case prm_type::INSTANCE:
98  return "PRMType::INSTANCE";
99 
101  return "PRMType::PRM_INTERFACE";
102 
103  default:
104  return "unknown";
105  }
106  }

◆ exists() [1/2]

template<typename GUM_SCALAR >
INLINE bool gum::prm::PRMInstance< GUM_SCALAR >::exists ( NodeId  id) const

Returns true if id matches an PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 275 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

275  {
276  return _nodeIdMap_.exists(id);
277  }
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
+ Here is the call graph for this function:

◆ exists() [2/2]

template<typename GUM_SCALAR >
INLINE bool gum::prm::PRMInstance< GUM_SCALAR >::exists ( const std::string &  name) const

Returns true if name matches an PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.

Definition at line 280 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

280  {
281  return _type_->exists(name) && exists(_type_->get(name).id());
282  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
PRMClass< GUM_SCALAR > * _type_
The type of this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:503
bool exists(NodeId id) const
Returns true if id matches an PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
+ Here is the call graph for this function:

◆ get() [1/4]

template<typename GUM_SCALAR >
INLINE PRMAttribute< GUM_SCALAR > & gum::prm::PRMInstance< GUM_SCALAR >::get ( NodeId  id)

Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.

Recall that PRMAggregate<GUM_SCALAR> are instantiated as PRMAttribute<GUM_SCALAR> when an PRMInstance<GUM_SCALAR> is created. Thus any random variable contained in this PRMInstance<GUM_SCALAR> is mapped to an PRMAttribute<GUM_SCALAR>.

Parameters
idThe PRMAttribute<GUM_SCALAR> id.
Returns
Returns a constant reference on an PRMAttribute<GUM_SCALAR>.
Exceptions
NotFoundRaised if no PRMAttribute<GUM_SCALAR> matches name.

Definition at line 285 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

285  {
286  try {
287  return *(_nodeIdMap_[id]);
288  } catch (NotFound&) {
289  GUM_ERROR(NotFound, "no PRMAttribute<GUM_SCALAR> with the given NodeId")
290  }
291  }
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ get() [2/4]

template<typename GUM_SCALAR >
INLINE PRMAttribute< GUM_SCALAR > & gum::prm::PRMInstance< GUM_SCALAR >::get ( const std::string &  name)

Given a name returns the related PRMAttribute<GUM_SCALAR>.

Parameters
nameThe PRMAttribute<GUM_SCALAR>'s name.
Returns
Returns a reference over the PRMAttribute<GUM_SCALAR>.
Exceptions
NotFoundRaised if there is no PRMAttribute<GUM_SCALAR> named n.

Definition at line 303 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

303  {
304  try {
305  return *(_nodeIdMap_[type().get(name).id()]);
306  } catch (NotFound&) { GUM_ERROR(NotFound, "no PRMAttribute<GUM_SCALAR> with the given name") }
307  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ get() [3/4]

template<typename GUM_SCALAR >
INLINE const PRMAttribute< GUM_SCALAR > & gum::prm::PRMInstance< GUM_SCALAR >::get ( NodeId  id) const

Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.

Recall that PRMAggregate<GUM_SCALAR> are instantiated has PRMAttribute<GUM_SCALAR> when an PRMInstance<GUM_SCALAR> is created. Thus any random variable contained in this PRMInstance<GUM_SCALAR> is mapped to an PRMAttribute<GUM_SCALAR>.

Parameters
idThe PRMAttribute<GUM_SCALAR> id.
Returns
Returns a constant reference on an PRMAttribute<GUM_SCALAR>.
Exceptions
NotFoundRaised if no PRMAttribute<GUM_SCALAR> matches name.

Definition at line 294 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

294  {
295  try {
296  return *(_nodeIdMap_[id]);
297  } catch (NotFound&) {
298  GUM_ERROR(NotFound, "no PRMAttribute<GUM_SCALAR> with the given NodeId")
299  }
300  }
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ get() [4/4]

template<typename GUM_SCALAR >
INLINE const PRMAttribute< GUM_SCALAR > & gum::prm::PRMInstance< GUM_SCALAR >::get ( const std::string &  name) const

Given a name returns the related PRMClassElement.

Parameters
nameThe PRMClassElement's name.
Returns
Returns a constant reference over the PRMClassElement.
Exceptions
NotFoundRaised if there is no PRMClassElement named n.

Definition at line 311 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

311  {
312  try {
313  return *(_nodeIdMap_[type().get(name).id()]);
314  } catch (NotFound&) { GUM_ERROR(NotFound, "no PRMAttribute<GUM_SCALAR> with the given name") }
315  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ getInstance()

template<typename GUM_SCALAR >
INLINE const PRMInstance< GUM_SCALAR > & gum::prm::PRMInstance< GUM_SCALAR >::getInstance ( NodeId  id) const

Fast access to the first instance in a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>.

This is equivalent to **(this->getInstance(id).begin()) and should be use when dealing with non multiple PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>.

Parameters
idThe NodeId of a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
Exceptions
NotFoundRaised if there is no PRMClassElement given id.
UndefinedElementRaised if no PRMInstance<GUM_SCALAR> are referenced by id.

Definition at line 342 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

342  {
343  try {
344  if (_referenceMap_[id]->size() > 0) {
345  return **(_referenceMap_[id]->begin());
346  } else {
347  GUM_ERROR(UndefinedElement, "no Instance associated with the given NodeId")
348  }
349  } catch (NotFound&) {
350  GUM_ERROR(NotFound,
351  "no ReferenceSlot<GUM_SCALAR> or SlotChain<GUM_SCALAR> "
352  "matches the given NodeId");
353  }
354  }
NodeProperty< Set< PRMInstance< GUM_SCALAR > *> *> _referenceMap_
Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type / and t...
Definition: PRMInstance.h:512
Size size() const
Returns the number of attributes in this PRMInstance<GUM_SCALAR>.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ getInstances()

template<typename GUM_SCALAR >
INLINE const Set< PRMInstance< GUM_SCALAR > *> & gum::prm::PRMInstance< GUM_SCALAR >::getInstances ( NodeId  id) const

Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.

Parameters
idThe NodeId of a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR> in this.
Returns
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.
Exceptions
NotFoundIf there is no PRMClassElement given id.

Definition at line 358 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

358  {
359  try {
360  return *(_referenceMap_[id]);
361  } catch (NotFound&) {
362  GUM_ERROR(NotFound,
363  "no ReferenceSlot<GUM_SCALAR> or SlotChain<GUM_SCALAR> "
364  "matches the given NodeId");
365  }
366  }
NodeProperty< Set< PRMInstance< GUM_SCALAR > *> *> _referenceMap_
Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type / and t...
Definition: PRMInstance.h:512
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ getRefAttr() [1/2]

template<typename GUM_SCALAR >
INLINE std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > & gum::prm::PRMInstance< GUM_SCALAR >::getRefAttr ( NodeId  id)

Returns a vector of pairs of refering attributes of id.

Definition at line 554 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

554  {
555  return *(_referingAttr_[id]);
556  }
NodeProperty< std::vector< pair > *> _referingAttr_
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:519
+ Here is the call graph for this function:

◆ getRefAttr() [2/2]

template<typename GUM_SCALAR >
INLINE const std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > & gum::prm::PRMInstance< GUM_SCALAR >::getRefAttr ( NodeId  id) const

Returns a vector of pairs of refering attributes of id.

Definition at line 560 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

560  {
561  return *(_referingAttr_[id]);
562  }
NodeProperty< std::vector< pair > *> _referingAttr_
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:519
+ Here is the call graph for this function:

◆ hasRefAttr()

template<typename GUM_SCALAR >
INLINE bool gum::prm::PRMInstance< GUM_SCALAR >::hasRefAttr ( NodeId  id) const

Returns true if id has at least one referring PRMAttribute<GUM_SCALAR>.

Parameters
idA NodeId.
Returns
returns true if is has at least one referring PRMAttribute<GUM_SCALAR>.

Definition at line 565 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

565  {
566  return _referingAttr_.exists(id) && (!_referingAttr_[id]->empty());
567  }
NodeProperty< std::vector< pair > *> _referingAttr_
The set of pair (instance, attribute) referring an attribute of this instance.
Definition: PRMInstance.h:519
+ Here is the call graph for this function:

◆ instantiate()

template<typename GUM_SCALAR >
void gum::prm::PRMInstance< GUM_SCALAR >::instantiate ( )

Instantiate all nodes which requires it.

All attributes are now instantiated, which means they have a different DiscreteVariable pointer. This methods however still connects attributes of different instance together.

Warning
Be aware that this method will delete a large part of this instance attribute's CPF. Furthermore, the instantiated attribute's type will change (but will not be deleted).

Definition at line 65 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

65  {
66  if (!_instantiated_) {
67  _instantiated_ = true;
69  }
70  }
void _doInstantiate_()
Starts this instance instantiations.
bool _instantiated_
True if this instance has been instantiated.
Definition: PRMInstance.h:500
+ Here is the call graph for this function:

◆ isClass()

static INLINE bool gum::prm::PRMObject::isClass ( const PRMObject obj)
inlinestaticinherited

Returns true if obj_ptr is of type Class.

Definition at line 109 of file PRMObject.h.

References gum::prm::PRMObject::PRMObject().

109 { return obj.obj_type() == prm_type::CLASS; }
+ Here is the call graph for this function:

◆ isInstance()

static INLINE bool gum::prm::PRMObject::isInstance ( const PRMObject obj)
inlinestaticinherited

Returns true if obj_ptr is of type PRMInstance.

Definition at line 117 of file PRMObject.h.

References gum::prm::PRMObject::PRMObject().

117  {
118  return obj.obj_type() == prm_type::INSTANCE;
119  }
+ Here is the call graph for this function:

◆ isInterface()

static INLINE bool gum::prm::PRMObject::isInterface ( const PRMObject obj)
inlinestaticinherited

Returns true if obj_ptr is of type PRMInterface.

Definition at line 112 of file PRMObject.h.

References gum::prm::PRMObject::PRMObject().

112  {
113  return obj.obj_type() == prm_type::PRM_INTERFACE;
114  }
+ Here is the call graph for this function:

◆ LEFT_CAST()

static std::string gum::prm::PRMObject::LEFT_CAST ( )
inlinestaticinherited

Enumeration of the different types of objects handled by a PRM.

The "all" type is used to tell that we want any kind of PRMType (useful with iterators for example). No PRMObject will ever have "all" as type.

Definition at line 79 of file PRMObject.h.

79 { return "("; }

◆ name() [1/2]

INLINE const std::string & gum::prm::PRMObject::name ( ) const
inherited

Returns the name of this object.

Definition at line 34 of file PRMObject_inl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

34 { return _name_; }
std::string _name_
Definition: PRMObject.h:205
+ Here is the call graph for this function:

◆ name() [2/2]

INLINE void gum::prm::PRMObject::name ( const std::string &  name)
inherited

Change the name of the PRM Object.

Warning
Don't do this unless you know what you are doing !

Definition at line 38 of file PRMObject_inl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

38 { _name_ = name; }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
std::string _name_
Definition: PRMObject.h:205
+ Here is the call graph for this function:

◆ obj_type()

template<typename GUM_SCALAR >
INLINE PRMObject::prm_type gum::prm::PRMInstance< GUM_SCALAR >::obj_type ( ) const
virtual

Returns the PRM type of this object.

Implements gum::prm::PRMObject.

Definition at line 260 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

+ Here is the call graph for this function:

◆ operator!=()

INLINE bool gum::prm::PRMObject::operator!= ( const PRMObject obj) const
inherited

To PRMObject are equal if they have the same name (which is unique).

Definition at line 46 of file PRMObject_inl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

46 { return _name_ != obj.name(); }
std::string _name_
Definition: PRMObject.h:205
+ Here is the call graph for this function:

◆ operator=()

template<typename GUM_SCALAR >
INLINE PRMInstance< GUM_SCALAR > & gum::prm::PRMInstance< GUM_SCALAR >::operator= ( const PRMClass< GUM_SCALAR > &  from)
private

Copy operator. Don't use it.

Definition at line 255 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

255  {
256  GUM_ERROR(FatalError, "do not copy Instance")
257  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ operator==()

INLINE bool gum::prm::PRMObject::operator== ( const PRMObject obj) const
inherited

To PRMObject are equal if they have the same name (which is unique).

Definition at line 42 of file PRMObject_inl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

42 { return _name_ == obj.name(); }
std::string _name_
Definition: PRMObject.h:205
+ Here is the call graph for this function:

◆ RIGHT_CAST()

static std::string gum::prm::PRMObject::RIGHT_CAST ( )
inlinestaticinherited

Enumeration of the different types of objects handled by a PRM.

The "all" type is used to tell that we want any kind of PRMType (useful with iterators for example). No PRMObject will ever have "all" as type.

Definition at line 80 of file PRMObject.h.

80 { return ")"; }

◆ size()

template<typename GUM_SCALAR >
INLINE Size gum::prm::PRMInstance< GUM_SCALAR >::size ( ) const

Returns the number of attributes in this PRMInstance<GUM_SCALAR>.

Returns
the number of attributes in this PRMInstance<GUM_SCALAR>.

Definition at line 220 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

220  {
221  return _nodeIdMap_.size();
222  }
NodeProperty< PRMAttribute< GUM_SCALAR > *> _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Definition: PRMInstance.h:507
+ Here is the call graph for this function:

◆ type() [1/2]

template<typename GUM_SCALAR >
INLINE PRMClass< GUM_SCALAR > & gum::prm::PRMInstance< GUM_SCALAR >::type ( )

Returns the type of this instance.

Definition at line 265 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

265  {
266  return *_type_;
267  }
PRMClass< GUM_SCALAR > * _type_
The type of this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:503
+ Here is the call graph for this function:

◆ type() [2/2]

template<typename GUM_SCALAR >
INLINE const PRMClass< GUM_SCALAR > & gum::prm::PRMInstance< GUM_SCALAR >::type ( ) const

Returns the type of this instance.

Definition at line 270 of file PRMInstance_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

270  {
271  return *_type_;
272  }
PRMClass< GUM_SCALAR > * _type_
The type of this PRMInstance<GUM_SCALAR>.
Definition: PRMInstance.h:503
+ Here is the call graph for this function:

Member Data Documentation

◆ _bijection_

template<typename GUM_SCALAR>
Bijection< const DiscreteVariable*, const DiscreteVariable* > gum::prm::PRMInstance< GUM_SCALAR >::_bijection_
private

A bijection used for MultiDim handling.

Definition at line 522 of file PRMInstance.h.

◆ _instantiated_

template<typename GUM_SCALAR>
bool gum::prm::PRMInstance< GUM_SCALAR >::_instantiated_
private

True if this instance has been instantiated.

Definition at line 500 of file PRMInstance.h.

◆ _nodeIdMap_

template<typename GUM_SCALAR>
NodeProperty< PRMAttribute< GUM_SCALAR >* > gum::prm::PRMInstance< GUM_SCALAR >::_nodeIdMap_
private

The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.

Definition at line 507 of file PRMInstance.h.

◆ _referenceMap_

template<typename GUM_SCALAR>
NodeProperty< Set< PRMInstance< GUM_SCALAR >* >* > gum::prm::PRMInstance< GUM_SCALAR >::_referenceMap_
private

Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type / and the PRMInstance<GUM_SCALAR> associated with it.

Definition at line 512 of file PRMInstance.h.

◆ _referingAttr_

template<typename GUM_SCALAR>
NodeProperty< std::vector< pair >* > gum::prm::PRMInstance< GUM_SCALAR >::_referingAttr_
private

The set of pair (instance, attribute) referring an attribute of this instance.

Definition at line 519 of file PRMInstance.h.

◆ _type_

template<typename GUM_SCALAR>
PRMClass< GUM_SCALAR >* gum::prm::PRMInstance< GUM_SCALAR >::_type_
private

The type of this PRMInstance<GUM_SCALAR>.

Definition at line 503 of file PRMInstance.h.


The documentation for this class was generated from the following files: