aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::Instantiation Class Reference

Class for assigning/browsing values to tuples of discrete variables. More...

#include <agrum/tools/multidim/instantiation.h>

+ Inheritance diagram for gum::Instantiation:
+ Collaboration diagram for gum::Instantiation:

Public Member Functions

Constructors / Destructors
 Instantiation ()
 Default constructor: creates an empty tuple. More...
 
 Instantiation (const Instantiation &aI, const bool notifyMaster=true)
 Copy constructor. More...
 
Instantiationoperator= (const Instantiation &aI)
 Copy operator. More...
 
 Instantiation (MultiDimAdressable &aMD)
 Constructor for a Instantiation of all the variables of a MultiDimAdressable. More...
 
 Instantiation (const MultiDimAdressable &aMD)
 Constructor for a Instantiation of all the variables of a MultiDimAdressable. More...
 
 Instantiation (MultiDimAdressable *aMD)
 Constructor for a Instantiation of all the variables of a MultiDimAdressable. More...
 
 Instantiation (const MultiDimAdressable *aMD)
 Constructor for a Instantiation of all the variables of a MultiDimAdressable. More...
 
 ~Instantiation ()
 Destructor. More...
 
Accessors / Modifiers
Idx nbrDim () const final
 Returns the number of variables in the Instantiation. More...
 
void add (const DiscreteVariable &v) final
 Adds a new variable in the Instantiation. More...
 
void erase (const DiscreteVariable &v) final
 Removes a variable from the Instantiation. More...
 
void erase (const std::string &name)
 Returns the number of variables in the Instantiation. More...
 
void clear ()
 Erase all variables from an Instantiation. More...
 
Size domainSize () const final
 Returns the product of the variable's domain size in the Instantiation. More...
 
Idx pos (const DiscreteVariable &v) const final
 Returns the position of the variable v. More...
 
Idx val (Idx i) const
 Returns the current value of the variable at position i. More...
 
Idx val (const DiscreteVariable &var) const
 Returns the current value of a given variable. More...
 
Idx val (const std::string &name) const
 Returns the number of variables in the Instantiation. More...
 
Idx valFromPtr (const DiscreteVariable *pvar) const
 Returns the current value of a given variable. More...
 
const DiscreteVariablevariable (Idx i) const final
 Returns the variable at position i in the tuple. More...
 
const DiscreteVariablevariable (const std::string &name) const final
 Returns the variable with the name. More...
 
InstantiationchgVal (const DiscreteVariable &v, Idx newval)
 Assign newval to variable v in the Instantiation. More...
 
InstantiationchgVal (const DiscreteVariable *v, Idx newval)
 Assign newval to variable v in the Instantiation. More...
 
InstantiationchgVal (Idx varPos, Idx newval)
 Assign newval to variable at position varPos in the Instantiation. More...
 
InstantiationchgVal (const std::string &var, Idx newval)
 Assign newval to variable at position varPos in the Instantiation. More...
 
InstantiationchgVal (const std::string &var, const std::string &newval)
 Assign newval to variable at position varPos in the Instantiation. More...
 
InstantiationsetVals (const Instantiation &i)
 Assign the values from i in the Instantiation. More...
 
void setValsFrom (const HashTable< const DiscreteVariable *, const DiscreteVariable * > &map, const Instantiation &external)
 Assign the values of external in *this, using map as a bijection between external and this variables. More...
 
bool contains (const DiscreteVariable &v) const final
 Indicates whether a given variable belongs to the Instantiation. More...
 
bool contains (const std::string &name) const
 Returns the number of variables in the Instantiation. More...
 
bool contains (const DiscreteVariable *v) const
 Indicates whether a given variable belongs to the Instantiation. More...
 
const Sequence< const DiscreteVariable *> & variablesSequence () const final
 Returns the sequence of DiscreteVariable of this instantiation. More...
 
virtual bool empty () const final
 Returns true if the instantiation is empty. More...
 
Overflow management methods.
bool inOverflow () const
 Indicates whether the current value of the tuple is correct or not. More...
 
void unsetOverflow ()
 Removes the flag overflow. More...
 
void unsetEnd ()
 Alias for unsetOverflow(). More...
 
bool end () const
 Returns true if the Instantiation reached the end. More...
 
bool rend () const
 Returns true if the Instantiation reached the rend. More...
 
Incrementation and decrementation methods
void inc ()
 Operator increment. More...
 
void dec ()
 Operator decrement. More...
 
void incIn (const Instantiation &i)
 Operator increment for the variables in i. More...
 
void decIn (const Instantiation &i)
 Operator decrement for the variables in i. More...
 
void incOut (const Instantiation &i)
 Operator increment for the variables not in i. More...
 
void decOut (const Instantiation &i)
 Operator decrement for the variables not in i. More...
 
void incNotVar (const DiscreteVariable &v)
 Operator increment for vars which are not v. More...
 
void decNotVar (const DiscreteVariable &v)
 Operator decrement for vars which are not v. More...
 
void incVar (const DiscreteVariable &v)
 Operator increment for variable v only. More...
 
void decVar (const DiscreteVariable &v)
 Operator decrement for variable v only. More...
 
Initialization methods
void setFirst ()
 Assign the first values to the tuple of the Instantiation. More...
 
void setLast ()
 Assign the last values in the Instantiation. More...
 
void setFirstIn (const Instantiation &i)
 Assign the first values in the Instantiation for the variables in i. More...
 
void setLastIn (const Instantiation &i)
 Assign the last values in the Instantiation for the variables in i. More...
 
void setFirstOut (const Instantiation &i)
 Assign the first values in the Instantiation for the variables not in i. More...
 
void setLastOut (const Instantiation &i)
 Assign the last values in the Instantiation for the variables not in i. More...
 
void setFirstNotVar (const DiscreteVariable &v)
 Assign the first values to variables different of v. More...
 
void setLastNotVar (const DiscreteVariable &v)
 Assign the last values to variables different of v. More...
 
void setFirstVar (const DiscreteVariable &v)
 Assign the first value in the Instantiation for var v. More...
 
void setLastVar (const DiscreteVariable &v)
 Assign the last value in the Instantiation for var v. More...
 
Notification methods
bool actAsSlave (MultiDimAdressable &aMD)
 Tries to register the Instantiation to a MultiDimAdressable. More...
 
bool forgetMaster ()
 Deassociate the master MultiDimAdressable, if any. More...
 
bool isSlave () const
 Indicates whether the Instantiation has a master. More...
 
bool isMaster (const MultiDimAdressable *m) const
 Indicates whether m is the master of this instantiation. More...
 
bool isMaster (const MultiDimAdressable &m) const
 Indicates whether m is the master of this instantiation. More...
 
void synchronizeWithMaster (const MultiDimAdressable *m)
 Force the variables sequence to be the same as the master one. More...
 
void addWithMaster (const MultiDimAdressable *m, const DiscreteVariable &v)
 Call Instantiation:: add(const DiscreteVariable&) by master. More...
 
void eraseWithMaster (const MultiDimAdressable *m, const DiscreteVariable &v)
 Call Instantiation:: erase(const DiscreteVariable&) by master. More...
 
Operators
bool operator== (const Instantiation &other) const
 operator== More...
 
Instantiationoperator++ ()
 Alias of Instantiation::inc(). More...
 
Instantiationoperator-- ()
 Alias of Instantiation::dec(). More...
 
Instantiationoperator+= (Size depl)
 Calls depl times Instantiation::inc(). More...
 
Instantiationoperator-= (Size depl)
 Calls depl times Instantiation::dec(). More...
 
Various methods
Idx hamming () const
 Returns the hamming distance of this instantiation. More...
 
std::string toString () const
 Give a string version of instantiation. More...
 
void reorder (const Sequence< const DiscreteVariable * > &v)
 Reorder vars of this instantiation giving the order in v. More...
 
void reorder (const Instantiation &i)
 Calls reorder(const Sequence<const DiscreteVariable*>&) with i.variablesSequence() More...
 
Accessors / Modifiers
void replace (const DiscreteVariable &x, const DiscreteVariable &y)
 Replace variables in this multidim. More...
 

Protected Member Functions

virtual void replace_ (const DiscreteVariable *x, const DiscreteVariable *y) final
 Replace x by y. More...
 

Detailed Description

Class for assigning/browsing values to tuples of discrete variables.

Instantiation is designed to assign values to tuples of variables and to efficiently loop over values of subsets of variables. This class can be used in two different flavors:

  • the tuple of variables in the Instantiation is related to a multidimensional array and, when we loop over the possible values of the tuple, we also loop at the same time over the corresponding values in the array.
  • the tuple of variables in the Instantiation is not related to a multidimensional array and we can loop over the possible values of the tuple without looping over values fo any array.

An Instantiation can be associated/deassociated to a given multidimensional array using the MultiDimAdressable::registerSlave(Instantiation& i) and MultiDimAdressable::unregisterSlave functions. Note that, to be registrable, the Instantiation must have precisely the same variables as the array. As a consequence, adding or removing a variable from a Instantiation associated to an array will unregister it. This behavior is compulsory as, if it were still associated, it would not be possible to retrieve a correct value of the array given a value of the Instantiation. For instance, if M[A,B,C] is an array indexed by Boolean variables A,B,C, Which value of M should be returned if B=0 and C=0? We do not know for sure as we do not know the value of A. Note also that, at any time, you can unregister a Instantiation from its master multidimensional array and you can ask to associate it (provided the tuple of variable match).

To print information about a Instantiation use the following function:

See also
operator<<(std::ostream&, const Instantiation&).

Definition at line 82 of file instantiation.h.

Constructor & Destructor Documentation

◆ Instantiation() [1/6]

gum::Instantiation::Instantiation ( )

Default constructor: creates an empty tuple.

Definition at line 39 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

39  : _master_(nullptr), _overflow_(false) {
40  GUM_CONSTRUCTOR(Instantiation);
41  }
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
+ Here is the call graph for this function:

◆ Instantiation() [2/6]

gum::Instantiation::Instantiation ( const Instantiation aI,
const bool  notifyMaster = true 
)

Copy constructor.

Note that the Instantiation is by default associated to the same MultiDimAdressable as aI. This means that looping over values of the tuple will induce looping over the values of the MultiDimAdressable. Similarly, the value of the tuple is that of aI, and, if the Instantiation is slaved, its master is notified of the value of the Instantiation if notifyMaster is true.

Parameters
aIThe Instantiation we copy.
notifyMasterWhether or not notify master if exits.

Definition at line 98 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

98  :
99  MultiDimInterface(), _master_(0), _overflow_(false) {
100  // for debugging purposes
101  GUM_CONS_CPY(Instantiation);
102  // copy the content of aI
103  _vars_ = aI._vars_;
104  _vals_ = aI._vals_;
105  _overflow_ = aI._overflow_;
106 
107  if (aI._master_ && notifyMaster) actAsSlave(*aI._master_);
108  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
bool actAsSlave(MultiDimAdressable &aMD)
Tries to register the Instantiation to a MultiDimAdressable.
+ Here is the call graph for this function:

◆ Instantiation() [3/6]

gum::Instantiation::Instantiation ( MultiDimAdressable aMD)

Constructor for a Instantiation of all the variables of a MultiDimAdressable.

The variables of the Instantiation are those of aMD (actually, they are shared in memory). All the variables of aMD belong to the tuple of variables to be instantiated.

Note that the Instantiation is by default associated to aMD, i.e., looping over values of the tuple will induce looping over the values of aMD. The value given to the tuple is the first possible value, that is, (0,...,0). If the Instantiation is slaved, its master is notified of the value of the Instantiation.

Parameters
aMDThe array the variables of which are those of the Instantiation.

Definition at line 67 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

67  : _master_(0), _overflow_(false) {
68  // for debugging purposes
69  GUM_CONSTRUCTOR(Instantiation);
70  _init_(&d);
71  }
void _init_(MultiDimAdressable *master)
Initialize this Instantiation.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
+ Here is the call graph for this function:

◆ Instantiation() [4/6]

gum::Instantiation::Instantiation ( const MultiDimAdressable aMD)

Constructor for a Instantiation of all the variables of a MultiDimAdressable.

The variables of the Instantiation are those of aMD (actually, they are shared in memory). All the variables of aMD belong to the tuple of variables to be instantiated.

Note that the Instantiation is by default associated to aMD, i.e., looping over values of the tuple will induce looping over the values of aMD. The value given to the tuple is the first possible value, that is, (0,...,0). If the Instantiation is slaved, its master is notified of the value of the Instantiation.

Parameters
aMDThe array the variables of which are those of the Instantiation.

Definition at line 73 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

73  : _master_(0), _overflow_(false) {
74  // for debugging purposes
75  GUM_CONSTRUCTOR(Instantiation);
76  _init_(const_cast< MultiDimAdressable* >(&d));
77  }
void _init_(MultiDimAdressable *master)
Initialize this Instantiation.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
+ Here is the call graph for this function:

◆ Instantiation() [5/6]

gum::Instantiation::Instantiation ( MultiDimAdressable aMD)

Constructor for a Instantiation of all the variables of a MultiDimAdressable.

The variables of the Instantiation are those of aMD (actually, they are shared in memory). All the variables of aMD belong to the tuple of variables to be instantiated.

Note that the Instantiation is by default associated to aMD, i.e., looping over values of the tuple will induce looping over the values of aMD. The value given to the tuple is the first possible value, that is, (0,...,0). If the Instantiation is slaved, its master is notified of the value of the Instantiation.

Parameters
aMDThe array the variables of which are those of the Instantiation.

Definition at line 80 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

80  : _master_(0), _overflow_(false) {
81  // for debugging purposes
82  GUM_CONSTRUCTOR(Instantiation);
83 
84  if (d) _init_(d);
85  }
void _init_(MultiDimAdressable *master)
Initialize this Instantiation.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
+ Here is the call graph for this function:

◆ Instantiation() [6/6]

gum::Instantiation::Instantiation ( const MultiDimAdressable aMD)

Constructor for a Instantiation of all the variables of a MultiDimAdressable.

The variables of the Instantiation are those of aMD (actually, they are shared in memory). All the variables of aMD belong to the tuple of variables to be instantiated.

Note that the Instantiation is by default associated to aMD, i.e., looping over values of the tuple will induce looping over the values of aMD. The value given to the tuple is the first possible value, that is, (0,...,0). If the Instantiation is slaved, its master is notified of the value of the Instantiation.

Parameters
aMDThe array the variables of which are those of the Instantiation.

Definition at line 90 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

90  : _master_(0), _overflow_(false) {
91  // for debugging purposes
92  GUM_CONSTRUCTOR(Instantiation);
93 
94  if (const_d) _init_(const_cast< MultiDimAdressable* >(const_d));
95  }
void _init_(MultiDimAdressable *master)
Initialize this Instantiation.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
+ Here is the call graph for this function:

◆ ~Instantiation()

gum::Instantiation::~Instantiation ( )

Destructor.

Definition at line 44 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

44  {
45  GUM_DESTRUCTOR(Instantiation);
46  // unregister the Instantiation from its _master_
47 
48  if (_master_) _master_->unregisterSlave(*this);
49  }
virtual bool unregisterSlave(Instantiation &i)=0
Unregister i as a slave of this MultiDimAdressable.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
+ Here is the call graph for this function:

Member Function Documentation

◆ _add_()

INLINE void gum::Instantiation::_add_ ( const DiscreteVariable v)
private

Adds a new var to the sequence of vars.

If variable v already belongs to the Instantiation tuple of variables, then nothing is done. In particular, no exception is thrown in this case.

Warning
note that this function does not deassociate the Instantiation from its master MultiDimAdressable, if any. To do so, use function add instead.
this function does not notify the master MultiDimAdressable, if any. Use in addition function chgVal or chgVal if need be.
variable v is known to the Instantiation only by a pointer to it. As a result, this is not a copy of v that is used by Instantiation but rather v itself. As such, v should never be deleted from memory until the Instantiation is removed.
Parameters
vThe new var.
Exceptions
DuplicateElementRaised if v is already in this Instantiation.

Definition at line 762 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

762  {
763  _vars_.insert(&v);
764  _vals_.push_back(0);
765  _overflow_ = false;
766  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
+ Here is the call graph for this function:

◆ _chgVal_()

INLINE void gum::Instantiation::_chgVal_ ( Idx  varPos,
Idx  newVal 
)
private

Modifies internally the value of a given variable of the sequence.

In addition to modifying the value of the variable, the Instantiation informs its master MultiDimAdressable of the modification.

Parameters
varPosThe variable to change.
newValThe variable new value.

Definition at line 44 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

44  {
45  Idx oldVal = _vals_[varPos];
46  _vals_[varPos] = newVal;
47 
48  _masterChangeNotification_(varPos, newVal, oldVal);
49  }
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
void _masterChangeNotification_(Idx varPos, Idx newVal, Idx oldVal) const
+ Here is the call graph for this function:

◆ _erase_()

INLINE void gum::Instantiation::_erase_ ( const DiscreteVariable v)
private

Removes a variable from the sequence of vars.

If variable v does not belong to the Instantiation tuple of variables, then nothing is done. In particular, no exception is thrown in this case.

Warning
this function does not notify the master MultiDimAdressable, if any.
note that this function does not deassociate the Instantiation from its master MultiDimAdressable, if any. To do so, use function removeDim instead.
Parameters
vThe variable to be erased from the tuple.

Definition at line 769 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

769  {
770  // get the position of the variable
771  Idx pos = _vars_.pos(&v);
772  _vars_.erase(&v);
773  _vals_.erase(_vals_.begin() + pos);
774  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
+ Here is the call graph for this function:

◆ _init_()

void gum::Instantiation::_init_ ( MultiDimAdressable master)
private

Initialize this Instantiation.

Parameters
masterThis Instantiation's master.

Definition at line 51 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

51  {
52  // for speed issues
53  GUM_ASSERT(master != nullptr);
54 
55  const Sequence< const DiscreteVariable* >& v = master->variablesSequence();
56  _vars_.resize(v.size());
57  _vals_.reserve(v.size());
58  // fill the instantiation
59 
60  for (const auto var: v)
61  _add_(*var);
62 
63  actAsSlave(master->getMasterRef());
64  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
void _add_(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
bool actAsSlave(MultiDimAdressable &aMD)
Tries to register the Instantiation to a MultiDimAdressable.
+ Here is the call graph for this function:

◆ _masterChangeNotification_()

void gum::Instantiation::_masterChangeNotification_ ( Idx  varPos,
Idx  newVal,
Idx  oldVal 
) const
private

Definition at line 189 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

189  {
190  if (_master_) _master_->changeNotification(*this, _vars_[varPos], oldVal, newVal);
191  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
virtual void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval)=0
Listen to changes in a given Instantiation.
+ Here is the call graph for this function:

◆ _masterDecNotification_()

void gum::Instantiation::_masterDecNotification_ ( ) const
private

Definition at line 203 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

203  {
204  if (_master_) _master_->setDecNotification(*this);
205  }
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
virtual void setDecNotification(const Instantiation &i)=0
Listen to increment in each recorded Instantiation.
+ Here is the call graph for this function:

◆ _masterFirstNotification_()

void gum::Instantiation::_masterFirstNotification_ ( ) const
private

Definition at line 193 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

193  {
195  }
virtual void setFirstNotification(const Instantiation &i)=0
Listen to setFirst in a given Instantiation.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
+ Here is the call graph for this function:

◆ _masterIncNotification_()

void gum::Instantiation::_masterIncNotification_ ( ) const
private

Definition at line 197 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

197  {
198  if (_master_) _master_->setIncNotification(*this);
199  }
virtual void setIncNotification(const Instantiation &i)=0
Listen to increment in a given Instantiation.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
+ Here is the call graph for this function:

◆ _masterLastNotification_()

void gum::Instantiation::_masterLastNotification_ ( ) const
private

Definition at line 200 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

200  {
202  }
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
virtual void setLastNotification(const Instantiation &i)=0
Listen to setLast in a given Instantiation.
+ Here is the call graph for this function:

◆ _notifiedDimChanged_()

void gum::Instantiation::_notifiedDimChanged_ ( const Sequence< const DiscreteVariable * > &  v)
private

This function is called by the master (if any) when changes arise in its vars list.

Warning
No implementation of this method?
Parameters
vthe new vars list

◆ _reorder_()

INLINE void gum::Instantiation::_reorder_ ( const Sequence< const DiscreteVariable * > &  v)
private

Reorder vars of this instantiation giving the order in v.

In the new order variables common to v and *this are placed first, then variables only in *this.

The variables only in v are ignored.

Parameters
vThe new order of variables in this Instantiation.

Definition at line 736 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

736  {
737  Idx max = original.size();
738  Idx position = 0;
739  for (Idx i = 0; i < max; ++i) {
740  const DiscreteVariable* pv = original.atPos(i);
741 
742  if (contains(pv)) {
743  auto p = pos(*pv);
744  GUM_ASSERT(p >= position); // this var should not be
745  // already placed.
746  _swap_(position, p);
747  position++;
748  }
749  }
750  }
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
void _swap_(Idx i, Idx j)
Swap two variables in the Instantiation.
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
+ Here is the call graph for this function:

◆ _swap_()

INLINE void gum::Instantiation::_swap_ ( Idx  i,
Idx  j 
)
private

Swap two variables in the Instantiation.

Parameters
iThe first variable.
jThe second variable.

Definition at line 714 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

714  {
715  if (i == j) return;
716 
717  _vars_.swap(i, j);
718 
719  Idx v;
720  v = _vals_[i];
721  _vals_[i] = _vals_[j];
722  _vals_[j] = v;
723  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ actAsSlave()

bool gum::Instantiation::actAsSlave ( MultiDimAdressable aMD)

Tries to register the Instantiation to a MultiDimAdressable.

The function will actually register the Instantiation if and only if it has precisely the same variables as the MultiDimAdressable (by precisely, we mean a physical equality, that is, the variables are at the same places in memory).

Parameters
aMDThe multidimensional array which will be the master of *this
Returns
Returns true if and only if the Instantiation has been associated successfully to aMD.
Exceptions
OperationNotAllowedRaised if this instantiation has already a master.

Definition at line 231 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

231  {
232  // if _master_ : not allowed
233  if (_master_ != nullptr) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
234 
235  _master_ = &aMD;
236 
237  // perform the registration
238  if (aMD.registerSlave(*this)) {
239  return true;
240  } else {
241  _master_ = nullptr;
242  return false;
243  }
244  }
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ add()

INLINE void gum::Instantiation::add ( const DiscreteVariable v)
finalvirtual

Adds a new variable in the Instantiation.

If variable v already belongs to the Instantiation tuple of variables, then DuplicateElement is thrown in this case. The value of the new variable is set to that of index 0, that is, the first possible value for the variable. Since an instantiation must share the same set of variables with his master an OperationNotAllowed is raised if you try to add a variable of a slaved instantiation.

Warning
Variable v is known to the Instantiation only by a pointer to it. As a result, this is not a copy of v that is used by the Instantiation, but rather v itself. As such, v should never be deleted from memory until the Instantiation is removed.
Parameters
vThe new variable added to this Instantiation.
Exceptions
DuplicateElementRaised if v is already in this Instantiation.
InvalidArgumentRaised if the name of v is already used in this Instantiation.
OperationNotAllowedRaised if this is a slave Instantiation.

Implements gum::MultiDimInterface.

Definition at line 121 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

121  {
122  // if _master_ : not allowed
123  if (_master_) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
124 
125  // check if the variable already belongs to the tuple of variables
126  // of the Instantiation
127  if (_vars_.exists(&v)) {
128  GUM_ERROR(DuplicateElement, "Var <" << v.name() << "> already exists in this instantiation")
129  }
130 
131  for (const auto& vv: _vars_) {
132  if (vv->name() == v.name()) {
133  GUM_ERROR(InvalidArgument,
134  "Var with name <" << v.name() << "> already exists in this instantiation");
135  }
136  }
137 
138  // actually add the new dimension
139  _add_(v);
140  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
void _add_(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ addWithMaster()

INLINE void gum::Instantiation::addWithMaster ( const MultiDimAdressable m,
const DiscreteVariable v 
)

Call Instantiation:: add(const DiscreteVariable&) by master.

Parameters
mThe master of this instantiation.
vThe varaible to add.
Exceptions
OperationNotAllowedRaised if m is not hte master of this instantiation.

Definition at line 754 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

754  {
755  if (m != _master_) { GUM_ERROR(OperationNotAllowed, "only master can do this") }
756 
757  _add_(v);
758  }
void _add_(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ chgVal() [1/5]

INLINE Instantiation & gum::Instantiation::chgVal ( const DiscreteVariable v,
Idx  newval 
)

Assign newval to variable v in the Instantiation.

Consider the values of v as an array indexed from 0 to n of values (which might be anything from real numbers to strings, etc). Parameter newval indicates the index in this array of the new value taken by v.

In addition to modifying the value of the variable, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

Parameters
vThe variable whose value is assigned.
newvalThe index of the value assigned.
Returns
Returns a reference to *this in order to chain the chgVal.
Exceptions
NotFoundRaised if variable v does not belong to the instantiation.
OutOfBoundRaised if newval is not a possible value for v.

Definition at line 52 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

52  {
53  try {
54  // check that the variable does belong to the instantiation and that the
55  // new
56  // value is possible.
57  Idx varPos = _vars_.pos(&v); // throws NotFound if v doesn't belong to this
58 
59  if (newVal >= v.domainSize()) { GUM_ERROR(OutOfBounds, "") }
60 
61  // if we were in overflow, indicate that we are not anymore
62  _overflow_ = false;
63 
64  _chgVal_(varPos, newVal);
65 
66  return *this;
67  } catch (NotFound&) {
68  std::string name = "instantiation does not contain this DiscreteVariable: ";
69  GUM_ERROR(NotFound, name + v.name())
70  }
71  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ chgVal() [2/5]

INLINE Instantiation & gum::Instantiation::chgVal ( const DiscreteVariable v,
Idx  newval 
)

Assign newval to variable v in the Instantiation.

Consider the values of v as an array indexed from 0 to n of values (which might be anything from real numbers to strings, etc). Parameter newval indicates the index in this array of the new value taken by v.

In addition to modifying the value of the variable, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

Parameters
vThe variable whose value is assigned.
newvalThe index of the value assigned.
Returns
Returns a reference to *this in order to chain the chgVal.
Exceptions
NotFoundRaised if variable v does not belong to the instantiation.
OutOfBoundRaised if newval is not a possible value for v.

Definition at line 73 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

73  {
74  try {
75  // check that the variable does belong to the instantiation and that the
76  // new
77  // value is possible.
78  Idx varPos = _vars_.pos(v); // throws NotFound if v doesn't belong to this
79 
80  if (newVal >= v->domainSize()) { GUM_ERROR(OutOfBounds, "") }
81 
82  // if we were in overflow, indicate that we are not anymore
83  _overflow_ = false;
84 
85  _chgVal_(varPos, newVal);
86 
87  return *this;
88  } catch (NotFound&) {
89  std::string name = "instantiation does not contain this DiscreteVariable: ";
90  GUM_ERROR(NotFound, name + v->name())
91  }
92  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ chgVal() [3/5]

INLINE Instantiation & gum::Instantiation::chgVal ( Idx  varPos,
Idx  newval 
)

Assign newval to variable at position varPos in the Instantiation.

Consider the values of v as an array indexed from 0 to n of values (which might be anything from real numbers to strings, etc). Parameter newval indicates the index in this array of the new value taken by v.

In addition to modifying the value of the variable, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

Parameters
varPosThe index of the variable whose value is assigned in the tuple of variables of the Instantiation.
newvalThe index of the value assigned.
Returns
A reference to *this in order to chain the chgVal.
Exceptions
NotFoundRaised if the variable does not belong to this
OutOfBoundRaised if newval is not a possible value for the variable

Definition at line 95 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

95  {
96  // check that the variable does belong to the instantiation and that the new
97  // value is possible.
98  if (_vals_.size() <= varPos) { GUM_ERROR(NotFound, "") }
99 
100  if (newVal >= _vars_[varPos]->domainSize()) { GUM_ERROR(OutOfBounds, "") }
101 
102  // if we were in overflow, indicate that we are not anymore
103  _overflow_ = false;
104 
105  _chgVal_(varPos, newVal);
106 
107  return *this;
108  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ chgVal() [4/5]

INLINE Instantiation & gum::Instantiation::chgVal ( const std::string &  var,
Idx  newval 
)

Assign newval to variable at position varPos in the Instantiation.

Consider the values of v as an array indexed from 0 to n of values (which might be anything from real numbers to strings, etc). Parameter newval indicates the index in this array of the new value taken by v.

In addition to modifying the value of the variable, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

Parameters
varthe name of the variable whose value is assigned in the tuple of variables of the Instantiation.
newvalThe index of the value assigned.
Returns
A reference to *this in order to chain the chgVal.
Exceptions
NotFoundRaised if the variable does not belong to this
NotFoundRaised if newval is not a possible value for the variable

Definition at line 110 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

110  {
111  return chgVal(variable(var), newVal);
112  }
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
+ Here is the call graph for this function:

◆ chgVal() [5/5]

INLINE Instantiation & gum::Instantiation::chgVal ( const std::string &  var,
const std::string &  newval 
)

Assign newval to variable at position varPos in the Instantiation.

Consider the values of v as an array indexed from 0 to n of values (which might be anything from real numbers to strings, etc). Parameter newval indicates the index in this array of the new value taken by v.

In addition to modifying the value of the variable, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

Parameters
varthe name of the variable whose value is assigned in the tuple of variables of the Instantiation.
newvalThe label of the value assigned.
Returns
A reference to *this in order to chain the chgVal.
Exceptions
NotFoundRaised if the variable does not belong to this
OutOfBoundRaised if newval is not a possible value for the variable

Definition at line 114 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

114  {
115  const auto& vv = variable(var);
116  Idx pos = vv.index(newVal);
117  return chgVal(vv, pos);
118  }
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
+ Here is the call graph for this function:

◆ clear()

INLINE void gum::Instantiation::clear ( )

Erase all variables from an Instantiation.

Exceptions
OperationNotAllowedRaised if the instantiation is a slave.

Definition at line 157 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

157  {
158  if (_master_) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
159 
160  _vars_.clear();
161  _vals_.clear();
162  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ contains() [1/3]

INLINE bool gum::Instantiation::contains ( const DiscreteVariable v) const
finalvirtual

Indicates whether a given variable belongs to the Instantiation.

Parameters
vThe variable for which the test is made.
Returns
Returns true if v is in the Instantiation.

Implements gum::MultiDimInterface.

Definition at line 34 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

34 { return _vars_.exists(&v); }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
+ Here is the call graph for this function:

◆ contains() [2/3]

INLINE bool gum::Instantiation::contains ( const std::string &  name) const

Returns the number of variables in the Instantiation.

Returns
Returns the number of variables in the Instantiation.

Definition at line 36 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

36  {
37  return contains(variable(name));
38  }
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
+ Here is the call graph for this function:

◆ contains() [3/3]

INLINE bool gum::Instantiation::contains ( const DiscreteVariable v) const

Indicates whether a given variable belongs to the Instantiation.

Parameters
vA pointer on the variable for which the test is made.
Returns
Returns true if *v is in the Instantiation.

Definition at line 41 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

41 { return _vars_.exists(v); }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
+ Here is the call graph for this function:

◆ dec()

INLINE void gum::Instantiation::dec ( )

Operator decrement.

Note that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). If the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. If we already reached the end() or the rend() of the possible values, function inc() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Usage example:

for(Instantiation i.setLast();! i.rend(); i.dec()) {
// code
}

Definition at line 263 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

263  {
264  Size p = nbrDim();
265  if (p == 0) { _overflow_ = true; }
266 
267  if (_overflow_) return;
268  p -= 1;
269  Idx cpt = 0;
270  // if we are in overflow, do nothing
271 
272  // perform the increment
273  while (true) {
274  Idx v = _vals_[cpt];
275 
276  if (v == 0) {
277  _vals_[cpt] = _vars_[cpt]->domainSize() - 1;
278 
279  if (cpt == p) {
280  _overflow_ = true;
281 
283 
284  return;
285  } else
286  ++cpt;
287  } else {
288  --_vals_[cpt];
289  break;
290  }
291  }
292 
294  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
void _masterDecNotification_() const
void _masterLastNotification_() const
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ decIn()

INLINE void gum::Instantiation::decIn ( const Instantiation i)

Operator decrement for the variables in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated.

Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). Finally, let us mention that the value of instantiation i is not taken into account, that is, only the variables belonging to i are taken into account. The next value of *this is thus computed w.r.t. to the current value of *this. If we already reached the end() or the rend() of the possible values, function incIn() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
iThe set of variables to decrement in this Instantiation.

Definition at line 392 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

392  {
393  Size p = i.nbrDim() - 1;
394  Idx i_cpt = 0;
395  // if we are in overflow, do nothing
396 
397  if (_overflow_) return;
398 
399  while (true) {
400  // verify that _vars_[cpt] belongs to i before incrementing its value
401  const DiscreteVariable& v = i.variable(i_cpt);
402 
403  if (!contains(v)) {
404  if (i_cpt == p) {
405  _overflow_ = true;
406  return;
407  } else
408  ++i_cpt;
409  } else {
410  Idx cpt = pos(v);
411  Idx iv = _vals_[cpt];
412 
413  if (iv == 0) {
414  _chgVal_(cpt, _vars_[cpt]->domainSize() - 1);
415 
416  if (i_cpt == p) {
417  _overflow_ = true;
418  return;
419  } else
420  ++i_cpt;
421  } else {
422  _chgVal_(cpt, iv - 1);
423  return;
424  }
425  }
426  }
427  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ decNotVar()

INLINE void gum::Instantiation::decNotVar ( const DiscreteVariable v)

Operator decrement for vars which are not v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated.

Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). If we already reached the end() or the rend() of the possible values, function incNotVar() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
vThe varaible not to decrement in this Instantiation.

Definition at line 583 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

583  {
584  Size p = nbrDim() - 1;
585  Idx cpt = 0;
586  // if we are in overflow, do nothing
587 
588  if (_overflow_) return;
589 
590  while (true) {
591  if (_vars_[cpt] == &v) {
592  if (cpt == p) {
593  _overflow_ = true;
594  return;
595  } else
596  ++cpt;
597  } else {
598  Idx iv = _vals_[cpt];
599 
600  if (iv == 0) {
601  _chgVal_(cpt, _vars_[cpt]->domainSize() - 1);
602 
603  if (cpt == p) {
604  _overflow_ = true;
605  return;
606  } else
607  ++cpt;
608  } else {
609  _chgVal_(cpt, iv - 1);
610  return;
611  }
612  }
613  }
614  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ decOut()

INLINE void gum::Instantiation::decOut ( const Instantiation i)

Operator decrement for the variables not in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). Finally, let us mention that the value of instantiation i is not taken into account, that is, only the variables not belonging to i are taken into account. The next value of *this is thus computed w.r.t. to the current value of *this. If we already reached the end() or the rend() of the possible values, function incerr() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
iThe set of variables to not decrement in this Instantiation.

Definition at line 496 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

496  {
497  Size p = nbrDim() - 1;
498  Idx cpt = 0;
499  // if we are in overflow, do nothing
500 
501  if (_overflow_) return;
502 
503  while (true) {
504  if (i.contains(_vars_[cpt])) {
505  if (cpt == p) {
506  _overflow_ = true;
507  return;
508  } else
509  ++cpt;
510  } else {
511  Idx v = _vals_[cpt];
512 
513  if (v == 0) {
514  _chgVal_(cpt, _vars_[cpt]->domainSize() - 1);
515 
516  if (cpt == p) {
517  _overflow_ = true;
518  return;
519  } else
520  ++cpt;
521  } else {
522  _chgVal_(cpt, v - 1);
523  return;
524  }
525  }
526  }
527  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ decVar()

INLINE void gum::Instantiation::decVar ( const DiscreteVariable v)

Operator decrement for variable v only.

This function decrement only variable v. Trying to decrement the last possible value results in an overflow (no exception is thrown in this case). If we already reached the end() or the rend() of the possible values, function incVar() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
vThe variable to decrement in this Instantiation.
Exceptions
NotFoundRaised if variable v does not belong to the Instantiation.

Definition at line 669 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

669  {
670  // get the position of the variable
671  Idx cpt = _vars_.pos(&v);
672  // if we are in overflow, do nothing
673 
674  if (_overflow_) return;
675 
676  Idx p = _vals_[cpt];
677 
678  if (p == 0) {
679  _chgVal_(cpt, v.domainSize() - 1);
680  _overflow_ = true;
681  } else {
682  _chgVal_(cpt, p - 1);
683  }
684  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
+ Here is the call graph for this function:

◆ domainSize()

INLINE Size gum::Instantiation::domainSize ( ) const
finalvirtual

Returns the product of the variable's domain size in the Instantiation.

Returns
Returns the product of the variable's domain size in the Instantiation.

Implements gum::MultiDimInterface.

Definition at line 166 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

166  {
167  Size s = 1;
168 
169  for (const auto var: _vars_)
170  s *= var->domainSize();
171 
172  return s;
173  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ empty()

INLINE bool gum::Instantiation::empty ( ) const
finalvirtual

Returns true if the instantiation is empty.

Returns
Returns true if the instantiation is empty.

Implements gum::MultiDimInterface.

Definition at line 777 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

777 { return _vals_.empty(); }
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ end()

INLINE bool gum::Instantiation::end ( ) const

Returns true if the Instantiation reached the end.

Function end() should be used as in:

for(Instantiation i.setFirst();! i.end(); ++i) {
// code
}
Returns
Returns true if the Instantiation reached the end.

Definition at line 218 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

218 { return inOverflow(); }
bool inOverflow() const
Indicates whether the current value of the tuple is correct or not.
+ Here is the call graph for this function:

◆ erase() [1/2]

INLINE void gum::Instantiation::erase ( const DiscreteVariable v)
finalvirtual

Removes a variable from the Instantiation.

If variable v does not belong to the Instantiation tuple of variables, then NotFound is thrown. Since an instantiation must share the same set of variables with his master an OperationNotAllowed is raised if you try to remove a variable from a slaved instantiation.

Parameters
vThe variable to remove from this Instantiation.
Exceptions
NotFoundRaised if v does not belong to this Instantiation.
OperationNotAllowedRaised if the instantiation is a slave.

Implements gum::MultiDimInterface.

Definition at line 143 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

143  {
144  // if _master_ : not allowed
145  if (_master_) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
146 
147  // check that the variable does actually belong to the Instantiation
148  if (!_vars_.exists(&v)) { GUM_ERROR(NotFound, "Var does not exist in this instantiation") }
149 
150  // actually delete the dimension
151  _erase_(v);
152  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
void _erase_(const DiscreteVariable &v)
Removes a variable from the sequence of vars.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ erase() [2/2]

INLINE void gum::Instantiation::erase ( const std::string &  name)

Returns the number of variables in the Instantiation.

Returns
Returns the number of variables in the Instantiation.

Definition at line 154 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

154 { erase(variable(name)); }
void erase(const DiscreteVariable &v) final
Removes a variable from the Instantiation.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
+ Here is the call graph for this function:

◆ eraseWithMaster()

void gum::Instantiation::eraseWithMaster ( const MultiDimAdressable m,
const DiscreteVariable v 
)

Call Instantiation:: erase(const DiscreteVariable&) by master.

Parameters
mThe master of this instantiation.
vThe variable to remove.
Exceptions
OperationNotAllowedRaised if m is not the master of this instantiation.

Definition at line 222 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

222  {
223  if (m != _master_) { GUM_ERROR(OperationNotAllowed, "only master can do this") }
224 
225  _erase_(v);
226 
228  }
void _erase_(const DiscreteVariable &v)
Removes a variable from the sequence of vars.
virtual void setChangeNotification(const Instantiation &i)=0
Listen to an assignment of a value in a Instantiation.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ forgetMaster()

bool gum::Instantiation::forgetMaster ( )

Deassociate the master MultiDimAdressable, if any.

Returns
Returns true if and only if the Instantiation has been unregistered.

Definition at line 208 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

208  {
209  if (_master_) {
210  _master_->unregisterSlave(*this);
211  _master_ = nullptr;
212  }
213  return true;
214  }
virtual bool unregisterSlave(Instantiation &i)=0
Unregister i as a slave of this MultiDimAdressable.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
+ Here is the call graph for this function:

◆ hamming()

Idx gum::Instantiation::hamming ( ) const

Returns the hamming distance of this instantiation.

Returns
Returns the hamming distance of this instantiation.

Definition at line 160 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

160  {
161  Idx res = 0;
162 
163  for (const auto var: _vars_)
164  res += val(*var);
165 
166  return res;
167  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
Idx val(Idx i) const
Returns the current value of the variable at position i.
+ Here is the call graph for this function:

◆ inc()

INLINE void gum::Instantiation::inc ( )

Operator increment.

Note that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). If the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. If we already reached the end() or the rend() of the possible values, function inc() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Usage example:

for(Instantiation i.setFirst();! i.end(); i.inc()) {
// code
}

Definition at line 231 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

231  {
232  Size p = nbrDim();
233  if (p == 0) { _overflow_ = true; }
234 
235  if (_overflow_) return;
236  p -= 1;
237  Idx cpt = 0;
238  // if we are in overflow, do nothing
239 
240  // perform the increment
241  while (true) {
242  Idx v = _vals_[cpt];
243 
244  if (v + 1 == _vars_[cpt]->domainSize()) {
245  _vals_[cpt] = 0;
246 
247  if (cpt == p) {
248  _overflow_ = true;
250  return;
251  } else
252  ++cpt;
253  } else {
254  ++_vals_[cpt];
255  break;
256  }
257  }
258 
260  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void _masterFirstNotification_() const
void _masterIncNotification_() const
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ incIn()

INLINE void gum::Instantiation::incIn ( const Instantiation i)

Operator increment for the variables in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated.

Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). Finally, let us mention that the value of instantiation i is not taken into account, that is, only the variables belonging to i are taken into account. The next value of *this is thus computed w.r.t. to the current value of *this. If we already reached the end() or the rend() of the possible values, function incIn() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
iThe set of variables to increment in this Instantiation.

Definition at line 347 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

347  {
348  // if i is empty, overflow and do nothing
349  if (i.nbrDim() == 0) {
350  _overflow_ = true;
351  return;
352  }
353 
354  // if we are in overflow, do nothing
355  if (_overflow_) return;
356 
357  Size p = i.nbrDim() - 1;
358 
359  Idx i_cpt = 0;
360 
361  while (true) {
362  // verify that _vars_[cpt] belongs to i before incrementing its value
363  const DiscreteVariable& v = i.variable(i_cpt);
364 
365  if (!contains(v)) {
366  if (i_cpt == p) {
367  _overflow_ = true;
368  return;
369  } else
370  ++i_cpt;
371  } else {
372  Idx cpt = pos(v);
373  Idx iv = _vals_[cpt];
374 
375  if (iv + 1 == _vars_[cpt]->domainSize()) {
376  _chgVal_(cpt, 0);
377 
378  if (i_cpt == p) {
379  _overflow_ = true;
380  return;
381  } else
382  ++i_cpt;
383  } else {
384  _chgVal_(cpt, iv + 1);
385  return;
386  }
387  }
388  }
389  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ incNotVar()

INLINE void gum::Instantiation::incNotVar ( const DiscreteVariable v)

Operator increment for vars which are not v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). If we already reached the end() or the rend() of the possible values, function incNotVar() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
vThe variable not to increment in this Instantiation.

Definition at line 549 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

549  {
550  Size p = nbrDim() - 1;
551  Idx cpt = 0;
552  // if we are in overflow, do nothing
553 
554  if (_overflow_) return;
555 
556  while (true) {
557  if (_vars_[cpt] == &v) {
558  if (cpt == p) {
559  _overflow_ = true;
560  return;
561  } else
562  ++cpt;
563  } else {
564  Idx iv = _vals_[cpt];
565 
566  if (iv + 1 == _vars_[cpt]->domainSize()) {
567  _chgVal_(cpt, 0);
568 
569  if (cpt == p) {
570  _overflow_ = true;
571  return;
572  } else
573  ++cpt;
574  } else {
575  _chgVal_(cpt, iv + 1);
576  return;
577  }
578  }
579  }
580  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ incOut()

INLINE void gum::Instantiation::incOut ( const Instantiation i)

Operator increment for the variables not in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated.

Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). Finally, let us mention that the value of instantiation i is not taken into account, that is, only the variables not belonging to i are taken into account. The next value of *this is thus computed w.r.t. to the current value of *this. If we already reached the end() or the rend() of the possible values, function incerr() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
iThe set of variable to not increment in this Instantiation.

Definition at line 462 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

462  {
463  Size p = nbrDim() - 1;
464  Idx cpt = 0;
465  // if we are in overflow, do nothing
466 
467  if (_overflow_) return;
468 
469  while (true) {
470  if (i.contains(_vars_[cpt])) {
471  if (cpt == p) {
472  _overflow_ = true;
473  return;
474  } else
475  ++cpt;
476  } else {
477  Idx v = _vals_[cpt];
478 
479  if (v + 1 == _vars_[cpt]->domainSize()) {
480  _chgVal_(cpt, 0);
481 
482  if (cpt == p) {
483  _overflow_ = true;
484  return;
485  } else
486  ++cpt;
487  } else {
488  _chgVal_(cpt, v + 1);
489  return;
490  }
491  }
492  }
493  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ incVar()

INLINE void gum::Instantiation::incVar ( const DiscreteVariable v)

Operator increment for variable v only.

This function increment only variable v. Trying to increment the last possible value results in an overflow (no exception is thrown in this case). If we already reached the end() or the rend() of the possible values, function incVar() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
vThe variable to increment in this Instantiation.
Exceptions
NotFoundRaised if variable v does not belong to the Instantiation.

Definition at line 651 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

651  {
652  // get the position of the variable
653  Idx cpt = _vars_.pos(&v);
654  // if we are in overflow, do nothing
655 
656  if (_overflow_) return;
657 
658  Idx p = _vals_[cpt];
659 
660  if (p + 1 == v.domainSize()) {
661  _chgVal_(cpt, 0);
662  _overflow_ = true;
663  } else {
664  _chgVal_(cpt, p + 1);
665  }
666  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
+ Here is the call graph for this function:

◆ inOverflow()

INLINE bool gum::Instantiation::inOverflow ( ) const

Indicates whether the current value of the tuple is correct or not.

The function inOverflow() is used to flag overflowed operation (for instance, ++ on the last value or – on the first value will produce an incorrect value of the tuple. Hence inOverflow() is used as an end()/rend() function for loops on Instantiation.

for(Instantiation i.setFirst(); !i.inOverflow(); ++i) {
// code...
}

Definition at line 215 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

215 { return _overflow_; }
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
+ Here is the call graph for this function:

◆ isMaster() [1/2]

INLINE bool gum::Instantiation::isMaster ( const MultiDimAdressable m) const

Indicates whether m is the master of this instantiation.

Returns
Returns true if m is the master of this instantiation.

Definition at line 702 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

702 { return (_master_ == m); }
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
+ Here is the call graph for this function:

◆ isMaster() [2/2]

INLINE bool gum::Instantiation::isMaster ( const MultiDimAdressable m) const

Indicates whether m is the master of this instantiation.

Returns
Returns true if m is the master of this instantiation.

Definition at line 705 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

705 { return isMaster(&m); }
bool isMaster(const MultiDimAdressable *m) const
Indicates whether m is the master of this instantiation.
+ Here is the call graph for this function:

◆ isSlave()

INLINE bool gum::Instantiation::isSlave ( ) const

Indicates whether the Instantiation has a master.

Returns
Returns true if the Instantiation has a master.

Definition at line 699 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

699 { return (_master_ != nullptr); }
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
+ Here is the call graph for this function:

◆ nbrDim()

INLINE Idx gum::Instantiation::nbrDim ( ) const
finalvirtual

Returns the number of variables in the Instantiation.

Returns
Returns the number of variables in the Instantiation.

Implements gum::MultiDimInterface.

Definition at line 179 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

179 { return _vars_.size(); }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
+ Here is the call graph for this function:

◆ operator++()

INLINE Instantiation & gum::Instantiation::operator++ ( )

Alias of Instantiation::inc().

Returns
Returns this Instantiation.

Definition at line 297 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

297  {
298  inc();
299  return *this;
300  }
void inc()
Operator increment.
+ Here is the call graph for this function:

◆ operator+=()

INLINE Instantiation & gum::Instantiation::operator+= ( Size  depl)

Calls depl times Instantiation::inc().

Returns
Returns this Instantiation.

Definition at line 309 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

309  {
310  for (Idx i = 0; i < depl; i++)
311  inc();
312 
313  return *this;
314  }
void inc()
Operator increment.
+ Here is the call graph for this function:

◆ operator--()

INLINE Instantiation & gum::Instantiation::operator-- ( )

Alias of Instantiation::dec().

Returns
Returns this Instantiation.

Definition at line 303 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

303  {
304  dec();
305  return *this;
306  }
void dec()
Operator decrement.
+ Here is the call graph for this function:

◆ operator-=()

INLINE Instantiation & gum::Instantiation::operator-= ( Size  depl)

Calls depl times Instantiation::dec().

Returns
Returns this Instantiation.

Definition at line 317 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

317  {
318  for (Idx i = 0; i < depl; i++)
319  dec();
320 
321  return *this;
322  }
void dec()
Operator decrement.
+ Here is the call graph for this function:

◆ operator=()

Instantiation & gum::Instantiation::operator= ( const Instantiation aI)

Copy operator.

If this is a slave but not with the same as aI's master: if aI and this does not share the same variables then an OperationNotAllowed will we be raised. Otherwise calls this->setVals( aI ).

If this is not a slave, copies aI.

Parameters
aIThe Instantiation to copy.
Exceptions
OperationNotAllowedRaised if copy is not allowed.

Definition at line 111 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

111  {
112  if (_master_) {
113  if (!aI.isMaster(_master_)) { // aI as the same master.
114  if (nbrDim() != aI.nbrDim()) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
115 
116  for (Idx i = 0; i < nbrDim(); i++) {
117  if ((!contains(aI.variable(i))) || (!aI.contains(variable(i)))) {
118  GUM_ERROR(OperationNotAllowed, "in slave Instantiation")
119  }
120  }
121  }
122 
123  setVals(aI);
124  } else {
125  // copy the content of aI
126  _vars_ = aI._vars_;
127  _vals_ = aI._vals_;
128  _overflow_ = aI._overflow_;
129 
130  if (aI._master_) actAsSlave(*aI._master_);
131  }
132 
133  return *this;
134  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Instantiation & setVals(const Instantiation &i)
Assign the values from i in the Instantiation.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
bool actAsSlave(MultiDimAdressable &aMD)
Tries to register the Instantiation to a MultiDimAdressable.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ operator==()

INLINE bool gum::Instantiation::operator== ( const Instantiation other) const

operator==

Definition at line 801 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

801  {
802  if (inOverflow() && other.inOverflow()) return true;
803  if (other.nbrDim() != nbrDim()) return false;
804  for (const auto& k: variablesSequence()) {
805  if (!other.contains(k)) return false;
806  if (val(*k) != other.val(*k)) return false;
807  }
808  return true;
809  }
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns the sequence of DiscreteVariable of this instantiation.
Idx val(Idx i) const
Returns the current value of the variable at position i.
bool inOverflow() const
Indicates whether the current value of the tuple is correct or not.
+ Here is the call graph for this function:

◆ pos()

INLINE Idx gum::Instantiation::pos ( const DiscreteVariable v) const
finalvirtual

Returns the position of the variable v.

Returns
Returns the position of the variable v.
Parameters
vThe variable for which its position is return.
Exceptions
NotFoundRaised if v does not belong to the instantiation.

Implements gum::MultiDimInterface.

Definition at line 176 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

176 { return _vars_.pos(&k); }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
+ Here is the call graph for this function:

◆ rend()

INLINE bool gum::Instantiation::rend ( ) const

Returns true if the Instantiation reached the rend.

Function end() should be used as in:

for(Instantiation i.setLast();! i.rend(); --i) {
// code
}
Returns
Returns true if the Instantiation reached the rend.

Definition at line 221 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

221 { return inOverflow(); }
bool inOverflow() const
Indicates whether the current value of the tuple is correct or not.
+ Here is the call graph for this function:

◆ reorder() [1/2]

INLINE void gum::Instantiation::reorder ( const Sequence< const DiscreteVariable * > &  v)

Reorder vars of this instantiation giving the order in v.

In the new order variables common to v and *this are placed first, then variables only in *this.

The variables only in v are ignored.

Parameters
vThe new order of variables for this Instantiation.
Exceptions
OperationNotAllowedif slave instantiation

Definition at line 727 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

727  {
728  if (_master_ != nullptr) {
729  GUM_ERROR(OperationNotAllowed, "Reordering impossible in slave instantiation")
730  }
731 
732  _reorder_(original);
733  }
void _reorder_(const Sequence< const DiscreteVariable * > &v)
Reorder vars of this instantiation giving the order in v.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ reorder() [2/2]

INLINE void gum::Instantiation::reorder ( const Instantiation i)

Calls reorder(const Sequence<const DiscreteVariable*>&) with i.variablesSequence()

Parameters
iThe sequence of variables with which to reorder this Instantiation.

Definition at line 430 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

430 { reorder(i.variablesSequence()); }
void reorder(const Sequence< const DiscreteVariable * > &v)
Reorder vars of this instantiation giving the order in v.
+ Here is the call graph for this function:

◆ replace()

INLINE void gum::MultiDimInterface::replace ( const DiscreteVariable x,
const DiscreteVariable y 
)
inherited

Replace variables in this multidim.

If x is in this MultiDim and y has the same domain size, then x will be replace by y in this MultiDim.

Parameters
xThe variable in this which will be replaced.
yThe variable replacing y.
Exceptions
NotFoundRaised if x does not belong to this MultiDim.
OperationNotAllowedIf y and x are not interchangeable.
DuplicateElementIf y is already in this MultiDim.

Definition at line 35 of file multiDimInterface_inl.h.

References gum::Set< Key, Alloc >::emplace().

35  {
36  if (!contains(x)) { GUM_ERROR(NotFound, "could not find the variable") }
37 
38  if (contains(y)) { GUM_ERROR(DuplicateElement, "variable " << y << " already in MultiDim") }
39 
40  if (x.domainSize() != y.domainSize()) {
41  GUM_ERROR(OperationNotAllowed, "incompatible variables")
42  }
43 
44  replace_(&x, &y);
45  }
virtual bool contains(const DiscreteVariable &v) const =0
Returns true if var is in *this.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y)=0
This is called by MultiDimContainer::replace() to proceed with the replacing between x and y...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ replace_()

INLINE void gum::Instantiation::replace_ ( const DiscreteVariable x,
const DiscreteVariable y 
)
finalprotectedvirtual

Replace x by y.

Parameters
xThe variable to replace.
yThe variable replacing x.

Implements gum::MultiDimInterface.

Definition at line 780 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

780  {
781  _vars_.setAtPos(_vars_.pos(x), y);
782  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
+ Here is the call graph for this function:

◆ setFirst()

INLINE void gum::Instantiation::setFirst ( )

Assign the first values to the tuple of the Instantiation.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Definition at line 325 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

325  {
326  _overflow_ = false;
327  Size s = nbrDim();
328 
329  for (Idx p = 0; p < s; ++p)
330  _vals_[p] = 0;
331 
333  }
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void _masterFirstNotification_() const
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ setFirstIn()

INLINE void gum::Instantiation::setFirstIn ( const Instantiation i)

Assign the first values in the Instantiation for the variables in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. Note also that the value of instantiation i is not taken into account, that is, only the variables not belonging to i are taken into account. This function naturally unsets the overFlow flag.

Parameters
iThe variables to which their first value is assigned in this Instantiation.

Definition at line 433 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

433  {
434  _overflow_ = false;
435  Idx s = nbrDim();
436 
437  for (Size p = 0; p < s; ++p)
438  if (i.contains(_vars_[p])) _chgVal_(p, 0);
439  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ setFirstNotVar()

INLINE void gum::Instantiation::setFirstNotVar ( const DiscreteVariable v)

Assign the first values to variables different of v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Parameters
vTha variable that will not be set to its first value in this Instantiation.

Definition at line 617 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

617  {
618  _overflow_ = false;
619  Idx s = nbrDim();
620 
621  for (Size p = 0; p < s; ++p) {
622  if (_vars_[p] == &v) {
623  Idx oldval = _vals_[p];
624  setFirst();
625  _chgVal_(p, oldval);
626  return;
627  }
628  }
629 
630  setFirst();
631  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
void setFirst()
Assign the first values to the tuple of the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ setFirstOut()

INLINE void gum::Instantiation::setFirstOut ( const Instantiation i)

Assign the first values in the Instantiation for the variables not in i.

Note that, if the Instantiation is related to a qum::MultiDimAdressable, then the corresponding value in the latter is updated. Note also that the value of instantiation i is not taken into account, that is, only the variables not belonging to i are taken into account. This function naturally unsets the overFlow flag.

Parameters
iThe variable that will not be set to their first value in this Instantiation.

Definition at line 531 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

531  {
532  _overflow_ = false;
533  Idx s = nbrDim();
534 
535  for (Size p = 0; p < s; ++p)
536  if (!i.contains(_vars_[p])) _chgVal_(p, 0);
537  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ setFirstVar()

INLINE void gum::Instantiation::setFirstVar ( const DiscreteVariable v)

Assign the first value in the Instantiation for var v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Parameters
vThe variable that will be set to its first value in this Instantiation.

Definition at line 687 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

687  {
688  _overflow_ = false;
689  _chgVal_(_vars_.pos(&v), 0);
690  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
+ Here is the call graph for this function:

◆ setLast()

INLINE void gum::Instantiation::setLast ( )

Assign the last values in the Instantiation.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Definition at line 336 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

336  {
337  _overflow_ = false;
338  Size s = nbrDim();
339 
340  for (Idx p = 0; p < s; ++p)
341  _vals_[p] = _vars_[p]->domainSize() - 1;
342 
344  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
void _masterLastNotification_() const
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ setLastIn()

INLINE void gum::Instantiation::setLastIn ( const Instantiation i)

Assign the last values in the Instantiation for the variables in i.

Where Di is the domain size of variable i in the Instantiation) for the i vars.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. Note also that the value of instantiation i is not taken into account, that is, only the variables belonging to i are taken into account. This function naturally unsets the overFlow flag.

Parameters
iThe variables to which their last value is assigned in this Instantiation.

Definition at line 453 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

453  {
454  _overflow_ = false;
455  Idx s = nbrDim();
456 
457  for (Size p = 0; p < s; ++p)
458  if (i.contains(_vars_[p])) _chgVal_(p, _vars_[p]->domainSize() - 1);
459  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ setLastNotVar()

INLINE void gum::Instantiation::setLastNotVar ( const DiscreteVariable v)

Assign the last values to variables different of v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Parameters
vThe variable that will not be set to its last value in this Instantiation.

Definition at line 634 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

634  {
635  _overflow_ = false;
636  Idx s = nbrDim();
637 
638  for (Size p = 0; p < s; ++p) {
639  if (_vars_[p] == &v) {
640  Idx oldval = _vals_[p];
641  setLast();
642  _chgVal_(p, oldval);
643  return;
644  }
645  }
646 
647  setLast();
648  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void setLast()
Assign the last values in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ setLastOut()

INLINE void gum::Instantiation::setLastOut ( const Instantiation i)

Assign the last values in the Instantiation for the variables not in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. Note also that the value of instantiation i is not taken into account, that is, only the variables not belonging to i are taken into account. This function naturally unsets the overFlow flag.

Parameters
iThe variables that will not be set to their last value in this Instantiation.

Definition at line 540 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

540  {
541  _overflow_ = false;
542  Idx s = nbrDim();
543 
544  for (Size p = 0; p < s; ++p)
545  if (!i.contains(_vars_[p])) _chgVal_(p, _vars_[p]->domainSize() - 1);
546  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ setLastVar()

INLINE void gum::Instantiation::setLastVar ( const DiscreteVariable v)

Assign the last value in the Instantiation for var v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Parameters
vThe variable that will be set to its last value in this Instantiation.

Definition at line 693 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

693  {
694  _overflow_ = false;
695  _chgVal_(_vars_.pos(&v), v.domainSize() - 1);
696  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
+ Here is the call graph for this function:

◆ setVals()

INLINE Instantiation & gum::Instantiation::setVals ( const Instantiation i)

Assign the values from i in the Instantiation.

For any variable in i and in *this, value of the variable in i is assigned to the variable in *this.

In addition of modifying the value of the variables in *this, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

If no variables in i matches, then no value is changed.

Warning
Variables has to be "the same". Therefore chgValIn is usefull in a same domain variables (for instance a BN). However two identical variables will not be recognized as same (for instance between 2 BNs).
See also
Instantiation::setValsFrom for this kind of utilisation.
Parameters
iA Instantiation in which the new values are searched.
Returns
Returns a reference to *this in order to chain the chgVal.

Definition at line 442 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

442  {
443  _overflow_ = false;
444  Idx s = i.nbrDim();
445 
446  for (Size p = 0; p < s; ++p)
447  if (contains(i.variable(p))) _chgVal_(pos(i.variable(p)), i.val(p));
448 
449  return *this;
450  }
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ setValsFrom()

void gum::Instantiation::setValsFrom ( const HashTable< const DiscreteVariable *, const DiscreteVariable * > &  map,
const Instantiation external 
)

Assign the values of external in *this, using map as a bijection between external and this variables.

Parameters
mapKeys are variables in external.
externalAn instantiation used to change the values in j.
Exceptions
NotFoundRaised if a variable in external does not point to a variable in *this or in external.

Definition at line 169 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

171  {
172  for (const auto& elt: map) {
173  const DiscreteVariable& var = *elt.second;
174 
175  try {
176  Idx val = external.val(*elt.first);
177 
178  try {
179  chgVal(var, val);
180  } catch (NotFound&) {
181  GUM_ERROR(NotFound, var.name() << " : missing variable in instantiation")
182  }
183  } catch (NotFound&) {
184  GUM_ERROR(NotFound, var.name() << " : missing variable in external instantiation")
185  }
186  }
187  }
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
Idx val(Idx i) const
Returns the current value of the variable at position i.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ synchronizeWithMaster()

void gum::Instantiation::synchronizeWithMaster ( const MultiDimAdressable m)

Force the variables sequence to be the same as the master one.

The master should be a friend to notify dimensions changes friend class MultiDimAdressable.

Parameters
mThe master of this instantiation.
Exceptions
OperationNotAllowedRaised if m is not the master of instantiation.

Definition at line 216 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

216  {
217  if (m != _master_) { GUM_ERROR(OperationNotAllowed, "only master can do this") }
218 
220  }
void _reorder_(const Sequence< const DiscreteVariable * > &v)
Reorder vars of this instantiation giving the order in v.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const =0
Returns a const ref to the sequence of DiscreteVariable*.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ toString()

std::string gum::Instantiation::toString ( ) const

Give a string version of instantiation.

Returns
Returns a string version of instantiation.

Definition at line 137 of file instantiation.cpp.

References gum::Set< Key, Alloc >::emplace().

137  {
138  std::stringstream sstr;
139  // check if the value of the instantiation is correct
140 
141  if (_overflow_) { sstr << "<invalid>"; }
142 
143  sstr << "<";
144 
145  bool first = true;
146 
147  for (const auto var: _vars_) {
148  if (!first) sstr << "|";
149 
150  first = false;
151  sstr << var->name() << ":" << var->label(val(*var));
152  }
153 
154  sstr << ">";
155 
156  return sstr.str();
157  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
Idx val(Idx i) const
Returns the current value of the variable at position i.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
+ Here is the call graph for this function:

◆ unsetEnd()

INLINE void gum::Instantiation::unsetEnd ( )

Alias for unsetOverflow().

See also
unsetOverflow().

Definition at line 228 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

228 { _overflow_ = false; }
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
+ Here is the call graph for this function:

◆ unsetOverflow()

INLINE void gum::Instantiation::unsetOverflow ( )

Removes the flag overflow.

See full documentation for details. (Recommended).

When we use multiple inner loops w.r.t. a given Instantiation, it may happen that one inner loop reaches the end() of the Instantiation while the outer loops do not have reached it. This means that the inner loop has toggled the overflow flag. To enable the other loops to go on, we must unset this flag using function unsetOverflow(). For instance, assume that Prob represents probability P(b|a,c), then normalizing this proba can be performed using the following code:

// assume the probability has been defined somewhere:
MultiDimArray<double> Prob;
// create 2 instantiations for the 2 necessary loops
Instantiation i(Prob), j;
j << a << c;
double delta;
// outer loop: loop over the values of b
for(i.setFirstIn(j); !i.end(); i.incIn(j))
{
delta = 0.0;
// inner loop: loop over the values of a and c
for(i.setFirstOut(j); !i.end(); i.incerr(j))
delta += dd[i];
for(i.setFirstOut(j); !i.end(); i.incerr(j))
dd[i] /= delta;
// indicate that the end() reached after looping over a and c does not
// correspond to an end() for the loop w.r.t. b
i.unsetOverflow();
}

Definition at line 225 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

225 { _overflow_ = false; }
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
+ Here is the call graph for this function:

◆ val() [1/3]

INLINE Idx gum::Instantiation::val ( Idx  i) const

Returns the current value of the variable at position i.

Warning
For speed issues, the function does not actually check whether the overflow flag is set before returning the current value of the variable as, usually, it is not necessary. If need be, use function inOverflow() to check.
Parameters
iThe index of the variable.
Returns
Returns the current value of the variable at position i.
Exceptions
NotFoundRaised if the element cannot be found.

Definition at line 182 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

182  {
183  if (i >= _vals_.size()) {
184  GUM_ERROR(NotFound, i << " is out of bound index for the instantiation.")
185  }
186 
187  return _vals_[i];
188  }
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ val() [2/3]

INLINE Idx gum::Instantiation::val ( const DiscreteVariable var) const

Returns the current value of a given variable.

Warning
For speed issues, the function does not actually check whether the overflow flag is set before returning the current value of the variable as, usually, it is not necessary. If need be, use function inOverflow() to check.
Parameters
varThe variable the value of which we wish to know.
Returns
Returns the current value of a given variable.
Exceptions
NotFoundRaised it var does not belong to the instantiation.

Definition at line 191 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

191  {
192  return _vals_[_vars_.pos(&var)];
193  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ val() [3/3]

INLINE Idx gum::Instantiation::val ( const std::string &  name) const

Returns the number of variables in the Instantiation.

Returns
Returns the number of variables in the Instantiation.

Definition at line 195 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

195 { return val(variable(name)); }
Idx val(Idx i) const
Returns the current value of the variable at position i.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
+ Here is the call graph for this function:

◆ valFromPtr()

INLINE Idx gum::Instantiation::valFromPtr ( const DiscreteVariable pvar) const

Returns the current value of a given variable.

Warning
For speed issues, the function does not actually check whether the overflow flag is set before returning the current value of the variable as, usually, it is not necessary. If need be, use function inOverflow() to check.
Parameters
pvarThe variable for which the value is returned.
Returns
Returns the current value of a given variable.
Exceptions
NotFoundRaised if var does not belong to the instantiation.

Definition at line 199 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

199  {
200  return _vals_[_vars_.pos(pvar)];
201  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ variable() [1/2]

INLINE const DiscreteVariable & gum::Instantiation::variable ( Idx  i) const
finalvirtual

Returns the variable at position i in the tuple.

Parameters
iThe index of the variable
Returns
Returns the variable at position i in the tuple.
Exceptions
NotFoundRaised if the element cannot be found.

Implements gum::MultiDimInterface.

Definition at line 204 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

204 { return *(_vars_.atPos(i)); }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
+ Here is the call graph for this function:

◆ variable() [2/2]

INLINE const DiscreteVariable & gum::Instantiation::variable ( const std::string &  name) const
finalvirtual

Returns the variable with the name.

Parameters
nameThe index of the variable
Returns
Returns the variable qith the name in the tuple. This function is not O(1)
Exceptions
NotFoundRaised if the element cannot be found.

Implements gum::MultiDimInterface.

Definition at line 206 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

206  {
207  for (const auto& v: _vars_) {
208  if (v->name() == name) return *v;
209  }
210 
211  GUM_ERROR(NotFound, "'" << name << "' can not be found in the instantiation.")
212  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ variablesSequence()

INLINE const Sequence< const DiscreteVariable *> & gum::Instantiation::variablesSequence ( ) const
finalvirtual

Returns the sequence of DiscreteVariable of this instantiation.

Returns
Returns the sequence of DiscreteVariable of this instantiation.

Implements gum::MultiDimInterface.

Definition at line 708 of file instantiation_inl.h.

References gum::Set< Key, Alloc >::emplace().

708  {
709  return _vars_;
710  }
Sequence< const DiscreteVariable *> _vars_
The tuple of variables to be instantiated.
+ Here is the call graph for this function:

Member Data Documentation

◆ _master_

MultiDimAdressable* gum::Instantiation::_master_
private

The master, if any, contains precisely the set of variables to be instantiated.

Definition at line 1127 of file instantiation.h.

◆ _overflow_

bool gum::Instantiation::_overflow_
private

Indicates whether the current value of the tuple is valid when we loop sufficiently over values of the tuple, we may have browsed all the possible values and we have to know in a way or another that the tuple contains no more value. This is precisely the meaning of Boolean overflow.

Definition at line 1140 of file instantiation.h.

◆ _vals_

std::vector< Idx > gum::Instantiation::_vals_
private

The current instantiation: the value of the tuple.

Definition at line 1133 of file instantiation.h.

◆ _vars_

Sequence< const DiscreteVariable* > gum::Instantiation::_vars_
private

The tuple of variables to be instantiated.

Definition at line 1130 of file instantiation.h.


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