59 template < GUM_Numeric GUM_SCALAR >
66 template < GUM_Numeric GUM_SCALAR >
69 bool delayInheritance) :
73 if (!delayInheritance) {
79 template < GUM_Numeric GUM_SCALAR >
82 bool delayInheritance) :
90 template < GUM_Numeric GUM_SCALAR >
94 bool delayInheritance) :
98 if (!delayInheritance) {
107 for (
const auto elt: set) {
115 template < GUM_Numeric GUM_SCALAR >
118 impl->_addImplementation_(
this);
121 for (
auto ref: impl->referenceSlots()) {
122 _dag_.addNodeWithId(ref->id());
125 for (
auto attr: impl->attributes()) {
126 _dag_.addNodeWithId(attr->id());
132 template < GUM_Numeric GUM_SCALAR >
145 template < GUM_Numeric GUM_SCALAR >
163 template < GUM_Numeric GUM_SCALAR >
167 for (
const auto c_refslot:
_superClass_->_referenceSlots_) {
171 c_refslot->isArray());
173 ref->setId(c_refslot->id());
175 if (!
_dag_.existsNode(ref->id())) {
_dag_.addNodeWithId(ref->id()); }
189 template < GUM_Numeric GUM_SCALAR >
195 c_param->valueType(),
200 param->setId(c_param->id());
201 _dag_.addNodeWithId(param->id());
208 template < GUM_Numeric GUM_SCALAR >
214 auto attr = c_attr->newFactory(*
this);
216 _bijection_->insert(&(c_attr->type().variable()), &(attr->type().variable()));
217 attr->setId(c_attr->id());
219 _dag_.addNodeWithId(attr->id());
231 _nameMap_.insert(attr->safeName(), attr);
236 template < GUM_Numeric GUM_SCALAR >
254 agg->
setId(c_agg->id());
255 _dag_.addNodeWithId(agg->
id());
267 template < GUM_Numeric GUM_SCALAR >
277 auto chain = c_sc->chain();
279 chain.setAtPos(0,
_nameMap_[c_sc->chain().front()->name()]);
282 _bijection_->insert(&(c_sc->type().variable()), &(sc->type().variable()));
283 sc->setId(c_sc->id());
284 _dag_.addNodeWithId(sc->id());
295 template < GUM_Numeric GUM_SCALAR >
316 template < GUM_Numeric GUM_SCALAR >
340 c_param->valueType(),
345 param->setId(c_param->id());
354 auto attr = c_attr->newFactory(*
this);
356 bij.
insert(&(c_attr->type().variable()), &(attr->type().variable()));
357 attr->setId(c_attr->id());
365 _nameMap_.insert(attr->safeName(), attr);
382 agg->
setId(c_agg->id());
397 c_refslot->isArray());
399 ref->
setId(c_refslot->id());
421 sc->
setId(c_slotchain->id());
440 a->copyCpf(bij, *attr);
445 template < GUM_Numeric GUM_SCALAR >
452 while (current != 0) {
453 if (current == &(cec))
return true;
469 if (impl->isSubTypeOf(i))
return true;
481 template < GUM_Numeric GUM_SCALAR >
483 auto p_tail =
_nameMap_.tryGet(tail_name);
484 auto p_head =
_nameMap_.tryGet(head_name);
486 if (!p_tail || !p_head) {
495 "a PRMReferenceSlot<GUM_SCALAR> can "
496 "not on neither side of an arc");
502 "illegal insertion of an arc between two SlotChain<GUM_SCALAR>")
518 sc->
end().setOutputNode(sc->
end().get(sc->
lastElt().safeName()),
true);
522 template < GUM_Numeric GUM_SCALAR >
531 template < GUM_Numeric GUM_SCALAR >
534 const auto& i_elt = i->
get(elt->
name());
538 if (!(is_attr || is_agg)) {
546 if (elt->
type() != i_elt.type()) {
547 if (!this->
exists(i_elt.safeName())) {
550 elt = &(this->
get(i_elt.safeName()));
554 if (!
_dag_.existsNode(i_elt.id())) {
559 if (elt->
id() != i_elt.id()) {
561 for (
auto child:
_dag_.children(elt->
id())) {
562 _dag_.addArc(i_elt.id(), child);
567 elt->
setId(i_elt.id());
571 template < GUM_Numeric GUM_SCALAR >
580 template < GUM_Numeric GUM_SCALAR >
583 auto& i_elt = i->
get(ref->
name());
584 if (i_elt.elt_type() != ref->
elt_type()) {
588 if (!ref->
slotType().isSubTypeOf(i_ref.slotType())) {
592 if (!
_dag_.exists(i_ref.id())) {
594 "class " << this->
name() <<
" does not respect interface " << i->
name()
595 <<
" implementation");
598 if (ref->
id() != i_ref.id()) {
_dag_.eraseNode(ref->
id()); }
600 ref->
setId(i_ref.id());
604 template < GUM_Numeric GUM_SCALAR >
608 "name " << elt->
name() <<
" already used by another ClassElement");
612 _dag_.addNodeWithId(elt->
id());
677 template < GUM_Numeric GUM_SCALAR >
682 while (parent->type().isSubType()) {
698 _dag_.addNodeWithId(child->
id());
706 _dag_.addArc(parent->id(), child->
id());
712 template < GUM_Numeric GUM_SCALAR >
722 if (overloaded == overloader) {
770 return overloader->
id();
773 template < GUM_Numeric GUM_SCALAR >
776 _dag_.eraseParents(overloaded->
id());
779 if (overloader->
type() != overloaded->
type()) {
781 _dag_.addNodeWithId(overloader->
id());
788 overloader->
setId(overloaded->
id());
799 template < GUM_Numeric GUM_SCALAR >
803 overloader->
setId(overloaded->
id());
811 std::vector< PRMSlotChain< GUM_SCALAR >* > toRemove, toAdd;
819 if ((slotchain->chain().atPos(0) == overloaded)) {
823 auto elt = ++(slotchain->chain().begin());
825 while (elt != slotchain->chain().end()) {
836 if (seq.
back()->type() != slotchain->lastElt().type()) {
840 .get(slotchain->lastElt().safeName())));
842 std::string dot =
".";
844 for (
Size i = 0; i < seq.
size() - 1; ++i) {
845 sc_name += seq.
atPos(i)->name() + dot;
848 sc_name += seq.
back()->safeName();
850 sc->
setId(slotchain->id());
853 auto& elt =
get(child);
856 auto& old_type = slotchain->lastElt().
type();
857 auto& new_type = sc->
lastElt().type();
858 attr.swap(old_type, new_type);
868 toRemove.push_back(slotchain);
871 slotchain->chain().setAtPos(0, overloader);
876 for (
const auto torem: toRemove) {
882 for (
const auto toadd: toAdd) {
894 template < GUM_Numeric GUM_SCALAR >
897 overloader->
setId(overloaded->
id());
906 template < GUM_Numeric GUM_SCALAR >
916 _dag_.addNodeWithId(child->
id());
931 template < GUM_Numeric GUM_SCALAR >
936 ext->findAllSubtypes_(set);
940 template < GUM_Numeric GUM_SCALAR >
949 if (impl->exists(elt->
name())) {
960 template < GUM_Numeric GUM_SCALAR >
970 template < GUM_Numeric GUM_SCALAR >
975 template < GUM_Numeric GUM_SCALAR >
980 template < GUM_Numeric GUM_SCALAR >
985 template < GUM_Numeric GUM_SCALAR >
988 if (!p) {
GUM_ERROR(
NotFound,
"no ClassElement<GUM_SCALAR> with the given NodeId") }
992 template < GUM_Numeric GUM_SCALAR >
996 GUM_ERROR(
NotFound,
"no ClassElement<GUM_SCALAR> with the given NodeId (" <<
id <<
")");
1001 template < GUM_Numeric GUM_SCALAR >
1010 template < GUM_Numeric GUM_SCALAR >
1019 template < GUM_Numeric GUM_SCALAR >
1024 template < GUM_Numeric GUM_SCALAR >
1030 template < GUM_Numeric GUM_SCALAR >
1037 prefix(
std::string{s}.append(ref.name()).append(
".")),
1038 c(static_cast< const
PRMClass< GUM_SCALAR >* >(&(ref.slotType()))),
depth(d) {}
1041 template < GUM_Numeric GUM_SCALAR >
1047 params.
insert(p->name(), p);
1050 std::queue< ParamScopeData< GUM_SCALAR > > queue;
1058 while (!queue.empty()) {
1059 auto data = queue.front();
1062 if (data.depth < 5) {
1063 for (
const auto p: data.c->parameters()) {
1064 params.
insert(data.prefix + p->name(), p);
1067 for (
const auto ref: data.c->referenceSlots()) {
1081 template < GUM_Numeric GUM_SCALAR >
1086 template < GUM_Numeric GUM_SCALAR >
1091 template < GUM_Numeric GUM_SCALAR >
1096 template < GUM_Numeric GUM_SCALAR >
1105 template < GUM_Numeric GUM_SCALAR >
1114 template < GUM_Numeric GUM_SCALAR >
1119 template < GUM_Numeric GUM_SCALAR >
1124 template < GUM_Numeric GUM_SCALAR >
1129 template < GUM_Numeric GUM_SCALAR >
1135 template < GUM_Numeric GUM_SCALAR >
1142 template < GUM_Numeric GUM_SCALAR >
1155 const auto& new_slot_type
1157 const auto& old_slot_type
1160 if (!new_slot_type.isSubTypeOf(old_slot_type)) {
return false; }
1180 template < GUM_Numeric GUM_SCALAR >
1185 template < GUM_Numeric GUM_SCALAR >
1190 template < GUM_Numeric GUM_SCALAR >
1201 template < GUM_Numeric GUM_SCALAR >
1207 if (i->isOutputNode(elt)) {
return true; }
Headers of gum::prm::Class<GUM_SCALAR>.
Headers of gum::prm::PRMInterface.
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
The base class for all directed edges.
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
Set of pairs of elements with fast search for both elements.
Base class for discrete random variable.
Exception : a similar element already exists.
Base class for all aGrUM's exceptions.
Exception : fatal (unknown ?) error.
The class for generic Hash Tables.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Exception : the element we looked for cannot be found.
Exception : operation not allowed.
const Key & atPos(Idx i) const
Returns the object at the pos i.
void insert(const Key &k)
Insert an element at the end of the sequence.
void erase(const Key &k)
Remove an element from the sequence.
const Key & back() const
Returns the last element of the sequence.
void setAtPos(Idx i, const Key &newKey)
Change the value.
Size size() const noexcept
Returns the size of the sequence.
The generic class for storing (ordered) sequences of objects.
PRMType & type() override
See gum::PRMClassElement::type().
std::shared_ptr< Idx > sharedLabel() const
Returns the shared_ptr holding this Aggregate label.
void setLabel(Idx idx)
Set the aggregator's label.
PRMAttribute is a member of a Class in a PRM.
virtual void overload(PRMAttribute< GUM_SCALAR > *source)
Set this as overload of source (necessayr to preserver internal pointers for MultiDims).
virtual void copyCpf(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bif, const PRMAttribute< GUM_SCALAR > &source)=0
See gum::PRMClassElement::elt_type().
virtual void setAsCastDescendant(PRMAttribute< GUM_SCALAR > *attr)=0
Define attr as a cast descendant of this PRMAttribute.
PRMType & type() override=0
See gum::PRMClassElement::type().
PRMAttribute< GUM_SCALAR > * getCastDescendant() const override=0
Returns a proper cast descendant of this PRMAttribute.
PRMClassElementContainer(std::string_view name)
Default constructor.
virtual const DAG & containerDag() const
Returns the gum::DAG of this PRMClassElementContainer.
virtual void copyIOFlags_(const PRMClassElementContainer< GUM_SCALAR > &c)
Copy the IO Flags of c in this PRMClassElementContainer.
virtual std::pair< bool, bool > & getIOFlag_(const PRMClassElement< GUM_SCALAR > &elt)
Returns the IO flags of a PRMClassElement<GUM_SCALAR>.
virtual bool exists(std::string_view name) const
Returns true if a member with the given name exists in this PRMClassElementContainer or in the PRMCla...
virtual void setIOFlag_(const PRMClassElement< GUM_SCALAR > &elt, const std::pair< bool, bool > &flags)
Defines the IO flags of a PRMClassElement<GUM_SCALAR>.
virtual void setInputNode(const PRMClassElement< GUM_SCALAR > &elt, bool b)
Set the input flag value of id at b.
Abstract class representing an element of PRM class.
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
static INLINE bool isParameter(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMParameter.
virtual ClassElementType elt_type() const =0
Return the type of class element this object is.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
virtual void setId(NodeId id)
Used to assign the id of this element.
static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMSlotChain.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
Set< PRMReferenceSlot< GUM_SCALAR > * > _referenceSlots_
The sequence of PRMReferenceSlot<GUM_SCALAR>.
void _overloadReference_(PRMReferenceSlot< GUM_SCALAR > *overloader, PRMReferenceSlot< GUM_SCALAR > *overloaded)
Overloads a reference slot.
bool _checkOverloadLegality_(const PRMClassElement< GUM_SCALAR > *overloaded, const PRMClassElement< GUM_SCALAR > *overloader)
Return true of overloaded can be overload by overloader.
PRMClass< GUM_SCALAR > * _superClass_
The alternate PRMClassElementContainer<GUM_SCALAR> searched for elements defined in this....
bool isSubTypeOf(const PRMClassElementContainer< GUM_SCALAR > &cec) const override
Test if this Class<GUM_SCALAR> is a subclass of cec.
void initializeInheritance()
const Set< PRMClass< GUM_SCALAR > * > & extensions() const
Returns the set of Class<GUM_SCALAR> which are direct sub-Class<GUM_SCALAR> of this Class<GUM_SCALAR>...
bool isCastDescendant(std::string_view safe_name) const
Return true if the attribute named safe_name is a cast descendant.
const Set< PRMInterface< GUM_SCALAR > * > & implements() const
Returns the Set of PRMInterface<GUM_SCALAR> implemented by this Class<GUM_SCALAR>.
void _addCastDescendants_(PRMClassElement< GUM_SCALAR > *attr)
Recursively adds cast descendant of attr in this Class<GUM_SCALAR>.
void _checkInterfaces_(PRMClassElement< GUM_SCALAR > *elt)
Check that a given element respects all the class interfaces.
Bijection< const DiscreteVariable *, const DiscreteVariable * > * _bijection_
The bijection between variables in super and variables in this The bijection's firsts are attributes ...
NodeId add(PRMClassElement< GUM_SCALAR > *elt) override
See gum::prm::add(PRMClassElement<GUM_SCALAR>*).
~PRMClass() override
Destructor.
void _overloadAggregate_(PRMAggregate< GUM_SCALAR > *overloader, PRMClassElement< GUM_SCALAR > *overloaded)
Overloads an aggregate.
Set< PRMSlotChain< GUM_SCALAR > * > _slotChains_
The set of gum::PRMSlotChain<GUM_SCALAR>s.
void _checkInterface_(PRMClassElement< GUM_SCALAR > *elt, PRMInterface< GUM_SCALAR > *i)
Check that a given element respects a specific interface.
const Set< PRMReferenceSlot< GUM_SCALAR > * > & referenceSlots() const
Returns the set of PRMReferenceSlot<GUM_SCALAR> of this Class<GUM_SCALAR>.
PRMClassElement< GUM_SCALAR > & get(NodeId id) override
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
const Set< PRMSlotChain< GUM_SCALAR > * > & slotChains() const
Returns the set of PRMSlotChain<GUM_SCALAR> of this Class<GUM_SCALAR>.
void _implementInterfaces_(bool delayInheritance)
Proceed with the implementation of interfaces.
void addArc(std::string_view tail, std::string_view head) override
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::addArc().
void updateDescendants_(const PRMClassElement< GUM_SCALAR > &elt) override
See gum::prm::PRMClassElementContainer<GUM_SCALAR>(constPRMClassElement<GUM_SCALAR>&).
void findAllSubtypes_(Set< PRMClassElementContainer< GUM_SCALAR > * > &set) override
Fills set with all the subtypes of this Class<GUM_SCALAR>.
NodeId overload(PRMClassElement< GUM_SCALAR > *elt) override
See gum::prm::overload(PRMClassElement<GUM_SCALAR>*).
const Set< PRMParameter< GUM_SCALAR > * > & parameters() const
Returns the set of parameters of this Class<GUM_SCALAR>.
DAG _dag_
The dag representing dependencies between formal attributes and slots.
void _checkRefInterface_(PRMReferenceSlot< GUM_SCALAR > *elt, PRMInterface< GUM_SCALAR > *i)
Check that a given element respects a specific interface.
const DAG & dag_() const override
returns a constant reference over this interface's dag.
PRMClass(std::string_view name)
Default constructor.
PRMObject::prm_type obj_type() const override
Implementation of pure virtual method of PRMObject.
void inheritReferenceSlots()
NodeProperty< PRMClassElement< GUM_SCALAR > * > _nodeIdMap_
Mapping between node's id and their name (being an attribute or a slot). Used for fast access to a me...
const Set< PRMAggregate< GUM_SCALAR > * > & aggregates() const
Returns the set of PRMAggregate<GUM_SCALAR> of this Class<GUM_SCALAR>.
Set< PRMAggregate< GUM_SCALAR > * > _aggregates_
The sequence of aggregate.
void _addExtension_(PRMClass< GUM_SCALAR > *c)
This method is called when a sub-Class<GUM_SCALAR> of this Class<GUM_SCALAR> is created.
void _overloadParameter_(PRMParameter< GUM_SCALAR > *overloader, PRMParameter< GUM_SCALAR > *overloaded)
Overloads a parameter.
PRMClassElement< GUM_SCALAR > & operator[](NodeId id) override
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::operator[](NodeId).
void _inheritClass_(const PRMClass< GUM_SCALAR > &c)
Proceed with the copy when this inherits c.
const Set< PRMAttribute< GUM_SCALAR > * > & attributes() const
Returns the set of PRMAttribute<GUM_SCALAR> of this Class<GUM_SCALAR>.
Set< PRMParameter< GUM_SCALAR > * > _parameters_
The Set of parameters in this Class<GUM_SCALAR>.
bool isOutputNode(const PRMClassElement< GUM_SCALAR > &elt) const override
Returns true if elt is an output node.
void _addIOInterfaceFlags_(PRMClassElement< GUM_SCALAR > *elt)
Check if elt is present in an implementation. If it is, its IO flags are updated.
Set< PRMClass< GUM_SCALAR > * > _extensions_
The set of Class<GUM_SCALAR> which are extension of this Class<GUM_SCALAR> (i.e. direct subtypes).
HashTable< std::string, PRMClassElement< GUM_SCALAR > * > _nameMap_
Mapping between a member's name and itself. Used for fast access to a member given it's name.
friend class PRMInterface< GUM_SCALAR >
void completeInheritance(std::string_view attr)
void _overloadAttribute_(PRMAttribute< GUM_SCALAR > *overloader, PRMAttribute< GUM_SCALAR > *overloaded)
Overloads an attribute.
const PRMClass< GUM_SCALAR > & super() const
Returns the super Class<GUM_SCALAR> of this Class<GUM_SCALAR>.
Set< PRMAttribute< GUM_SCALAR > * > _attributes_
The sequence of PRMAttribute<GUM_SCALAR>s.
HashTable< std::string, const PRMParameter< GUM_SCALAR > * > scope() const
Returns all the parameters in the scope of this class.
void _checkRefInterfaces_(PRMReferenceSlot< GUM_SCALAR > *elt)
Check that a given element respects all the class interfaces.
Set< PRMInterface< GUM_SCALAR > * > * _implements_
The Set of implemented interface of this.
An PRMInterface is implemented by a Class<GUM_SCALAR> and defines a set of PRMReferenceSlot<GUM_SCALA...
PRMClassElement< GUM_SCALAR > & get(NodeId id) override
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
const std::string & name() const
Returns the name of this object.
prm_type
Enumeration of the different types of objects handled by a PRM.
static INLINE bool isClass(const PRMObject &obj)
Returns true if obj_ptr is of type Class.
virtual prm_type obj_type() const =0
Returns the type of this object.
PRMParameter is a member of a Class in a PRM.
ParameterType valueType() const
See gum::PRMClassElement::elt_type().
A PRMReferenceSlot represent a relation between two PRMClassElementContainer.
PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const override
Implementation of the pure virtual method of PRMObject.
PRMClassElementContainer< GUM_SCALAR > & slotType()
Returns the type of this slot, which is a PRMClassElementContainer (it is not the type of PRMObject).
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
PRMType & type() override
This is similar to the following call: this->lastElt().type().
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
PRMClassElementContainer< GUM_SCALAR > & end()
Returns the PRMClassElement<GUM_SCALAR>Container over which this slot chain ends.
PRMType & superType()
Returns the super type of this type.
bool isSubTypeOf(const PRMType &super) const
Returns true if this is a subtype of super.
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
const std::string & name() const
Returns the name of this object.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
namespace for all probabilistic relational models entities
NodeId nextNodeId()
Returns the next value of an unique counter for PRM's node id.
gum is the global namespace for all aGrUM entities
const PRMClass< GUM_SCALAR > * c
ParamScopeData(std::string_view s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)