aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
instantiation_inl.h
Go to the documentation of this file.
1 
31 
32 namespace gum {
33 
34  // indicates whether a given variable belongs to the Instantiation
35  INLINE bool Instantiation::contains(const DiscreteVariable& v) const {
36  return __vars.exists(&v);
37  }
38 
39  INLINE bool Instantiation::contains(const std::string& name) const {
40  return contains(variable(name));
41  }
42 
43  // indicates whether a given variable belongs to the Instantiation
44  INLINE bool Instantiation::contains(const DiscreteVariable* v) const {
45  return __vars.exists(v);
46  }
47 
48  // modifies internally the value of a given variable of the sequence
49  INLINE void Instantiation::__chgVal(Idx varPos, Idx newVal) {
50  Idx oldVal = __vals[varPos];
51  __vals[varPos] = newVal;
52 
53  __masterChangeNotification(varPos, newVal, oldVal);
54  }
55 
56  // modifies the value of a given variable of the sequence (external function)
58  Idx newVal) {
59  try {
60  // check that the variable does belong to the instantiation and that the
61  // new
62  // value is possible.
63  Idx varPos = __vars.pos(&v); // throws NotFound if v doesn't belong to this
64 
65  if (newVal >= v.domainSize()) { GUM_ERROR(OutOfBounds, ""); }
66 
67  // if we were in overflow, indicate that we are not anymore
68  __overflow = false;
69 
70  __chgVal(varPos, newVal);
71 
72  return *this;
73  } catch (NotFound&) {
74  std::string name = "instantiation does not contain this DiscreteVariable: ";
75  GUM_ERROR(NotFound, name + v.name());
76  }
77  }
78 
80  Idx newVal) {
81  try {
82  // check that the variable does belong to the instantiation and that the
83  // new
84  // value is possible.
85  Idx varPos = __vars.pos(v); // throws NotFound if v doesn't belong to this
86 
87  if (newVal >= v->domainSize()) { GUM_ERROR(OutOfBounds, ""); }
88 
89  // if we were in overflow, indicate that we are not anymore
90  __overflow = false;
91 
92  __chgVal(varPos, newVal);
93 
94  return *this;
95  } catch (NotFound&) {
96  std::string name = "instantiation does not contain this DiscreteVariable: ";
97  GUM_ERROR(NotFound, name + v->name());
98  }
99  }
100 
101  // modifies the value of a given variable of the sequence (external function)
102  INLINE Instantiation& Instantiation::chgVal(Idx varPos, Idx newVal) {
103  // check that the variable does belong to the instantiation and that the new
104  // value is possible.
105  if (__vals.size() <= varPos) { GUM_ERROR(NotFound, ""); }
106 
107  if (newVal >= __vars[varPos]->domainSize()) { GUM_ERROR(OutOfBounds, ""); }
108 
109  // if we were in overflow, indicate that we are not anymore
110  __overflow = false;
111 
112  __chgVal(varPos, newVal);
113 
114  return *this;
115  }
116 
117  INLINE Instantiation& Instantiation::chgVal(const std::string& var, Idx newVal) {
118  return chgVal(variable(var), newVal);
119  }
120 
121  INLINE Instantiation& Instantiation::chgVal(const std::string& var,
122  const std::string& newVal) {
123  const auto& vv = variable(var);
124  Idx pos = vv.index(newVal);
125  return chgVal(vv, pos);
126  }
127 
128  // adds a new var to the sequence of vars
129  INLINE void Instantiation::add(const DiscreteVariable& v) {
130  // if __master : not allowed
131  if (__master) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation"); }
132 
133  // check if the variable already belongs to the tuple of variables
134  // of the Instantiation
135  if (__vars.exists(&v)) {
137  "Var <" << v.name() << "> already exists in this instantiation");
138  }
139 
140  for (const auto& vv: __vars) {
141  if (vv->name() == v.name()) {
143  "Var with name <" << v.name()
144  << "> already exists in this instantiation");
145  }
146  }
147 
148  // actually add the new dimension
149  __add(v);
150  }
151 
152  // removes a variable from the sequence of vars
153  INLINE void Instantiation::erase(const DiscreteVariable& v) {
154  // if __master : not allowed
155  if (__master) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation"); }
156 
157  // check that the variable does actually belong to the Instantiation
158  if (!__vars.exists(&v)) {
159  GUM_ERROR(NotFound, "Var does not exist in this instantiation");
160  }
161 
162  // actually delete the dimension
163  __erase(v);
164  }
165 
166  INLINE void Instantiation::erase(const std::string& name) {
167  erase(variable(name));
168  }
169 
170  // removes everything
171  INLINE void Instantiation::clear() {
172  if (__master) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation"); }
173 
174  __vars.clear();
175  __vals.clear();
176  }
177 
178  // @brief returns the product of the size of the domains of the variables
179  // belonging to the matrix
181  // @todo enhance the cplxity with a member domainSize ?
182  Size s = 1;
183 
184  for (const auto var: __vars)
185  s *= var->domainSize();
186 
187  return s;
188  }
189 
190  // returns the index of a var
191  INLINE Idx Instantiation::pos(const DiscreteVariable& k) const {
192  return __vars.pos(&k);
193  }
194 
195  // returns the number of vars in the sequence
196  INLINE Idx Instantiation::nbrDim() const { return __vars.size(); }
197 
198  // returns the current value of a given variable
199  INLINE Idx Instantiation::val(Idx i) const {
200  if (i >= __vals.size()) {
201  GUM_ERROR(NotFound, i << " is out of bound index for the instantiation.");
202  }
203 
204  return __vals[i];
205  }
206 
207  // returns the current value of a given variable
208  INLINE Idx Instantiation::val(const DiscreteVariable& var) const {
209  return __vals[__vars.pos(&var)];
210  }
211  // returns the current value of a given variable
212  INLINE Idx Instantiation::val(const std::string& name) const {
213  return val(variable(name));
214  }
215 
216 
217  // returns the current value of a given variable
218  INLINE Idx Instantiation::valFromPtr(const DiscreteVariable* pvar) const {
219  return __vals[__vars.pos(pvar)];
220  }
221 
222  // returns the variable at position i in the tuple
224  return *(__vars.atPos(i));
225  }
226  // returns the variable with name in the tuple
227  INLINE const DiscreteVariable&
228  Instantiation::variable(const std::string& name) const {
229  for (const auto& v: __vars) {
230  if (v->name() == name) return *v;
231  }
232 
233  GUM_ERROR(NotFound, "'" << name << "' can not be found in the instantiation.")
234  }
235 
236  // indicates whether the current value of the tuple is correct or not
237  INLINE bool Instantiation::inOverflow() const { return __overflow; }
238 
239  // end() just is a synonym for inOverflow()
240  INLINE bool Instantiation::end() const { return inOverflow(); }
241 
242  // rend() just is a synonym for inOverflow()
243  INLINE bool Instantiation::rend() const { return inOverflow(); }
244 
245  // indicates that the current value is correct even if it should be in
246  // overflow
247  INLINE void Instantiation::unsetOverflow() { __overflow = false; }
248 
249  // alias for unsetOverflow
250  INLINE void Instantiation::unsetEnd() { __overflow = false; }
251 
252  // operator ++
253  INLINE void Instantiation::inc() {
254  Size p = nbrDim();
255  if (p == 0) { __overflow = true; }
256 
257  if (__overflow) return;
258  p -= 1;
259  Idx cpt = 0;
260  // if we are in overflow, do nothing
261 
262  // perform the increment
263  while (true) {
264  Idx v = __vals[cpt];
265 
266  if (v + 1 == __vars[cpt]->domainSize()) {
267  __vals[cpt] = 0;
268 
269  if (cpt == p) {
270  __overflow = true;
272  return;
273  } else
274  ++cpt;
275  } else {
276  ++__vals[cpt];
277  break;
278  }
279  }
280 
282  }
283 
284  // operator --
285  INLINE void Instantiation::dec() {
286  Size p = nbrDim();
287  if (p == 0) { __overflow = true; }
288 
289  if (__overflow) return;
290  p -= 1;
291  Idx cpt = 0;
292  // if we are in overflow, do nothing
293 
294  // perform the increment
295  while (true) {
296  Idx v = __vals[cpt];
297 
298  if (v == 0) {
299  __vals[cpt] = __vars[cpt]->domainSize() - 1;
300 
301  if (cpt == p) {
302  __overflow = true;
303 
305 
306  return;
307  } else
308  ++cpt;
309  } else {
310  --__vals[cpt];
311  break;
312  }
313  }
314 
316  }
317 
318  // operator ++
320  inc();
321  return *this;
322  }
323 
324  // operator --
326  dec();
327  return *this;
328  }
329 
330  // operator +=
332  //@todo : this code should be improved !!!
333  for (Idx i = 0; i < depl; i++)
334  inc();
335 
336  return *this;
337  }
338 
339  // operator -=
341  //@todo : this code should be improved !!!
342  for (Idx i = 0; i < depl; i++)
343  dec();
344 
345  return *this;
346  }
347 
348  // assign the (0,0,...) first value to the tuple of the Instantiation.
349  INLINE void Instantiation::setFirst() {
350  __overflow = false;
351  Size s = nbrDim();
352 
353  for (Idx p = 0; p < s; ++p)
354  __vals[p] = 0;
355 
357  }
358 
359  // put the (D1-1,D2-1,...) last value in the Instantiation
360  INLINE void Instantiation::setLast() {
361  __overflow = false;
362  Size s = nbrDim();
363 
364  for (Idx p = 0; p < s; ++p)
365  __vals[p] = __vars[p]->domainSize() - 1;
366 
368  }
369 
370  // operator ++ limited only to the variables in i
371  INLINE void Instantiation::incIn(const Instantiation& i) {
372  // if i is empty, overflow and do nothing
373  if (i.nbrDim() == 0) {
374  __overflow = true;
375  return;
376  }
377 
378  // if we are in overflow, do nothing
379  if (__overflow) return;
380 
381  Size p = i.nbrDim() - 1;
382 
383  Idx i_cpt = 0;
384 
385  while (true) {
386  // verify that __vars[cpt] belongs to i before incrementing its value
387  const DiscreteVariable& v = i.variable(i_cpt);
388 
389  if (!contains(v)) {
390  if (i_cpt == p) {
391  __overflow = true;
392  return;
393  } else
394  ++i_cpt;
395  } else {
396  Idx cpt = pos(v);
397  Idx iv = __vals[cpt];
398 
399  if (iv + 1 == __vars[cpt]->domainSize()) {
400  __chgVal(cpt, 0);
401 
402  if (i_cpt == p) {
403  __overflow = true;
404  return;
405  } else
406  ++i_cpt;
407  } else {
408  __chgVal(cpt, iv + 1);
409  return;
410  }
411  }
412  }
413  }
414 
415  // operator -- limited only to the variables in i
416  INLINE void Instantiation::decIn(const Instantiation& i) {
417  Size p = i.nbrDim() - 1;
418  Idx i_cpt = 0;
419  // if we are in overflow, do nothing
420 
421  if (__overflow) return;
422 
423  while (true) {
424  // verify that __vars[cpt] belongs to i before incrementing its value
425  const DiscreteVariable& v = i.variable(i_cpt);
426 
427  if (!contains(v)) {
428  if (i_cpt == p) {
429  __overflow = true;
430  return;
431  } else
432  ++i_cpt;
433  } else {
434  Idx cpt = pos(v);
435  Idx iv = __vals[cpt];
436 
437  if (iv == 0) {
438  __chgVal(cpt, __vars[cpt]->domainSize() - 1);
439 
440  if (i_cpt == p) {
441  __overflow = true;
442  return;
443  } else
444  ++i_cpt;
445  } else {
446  __chgVal(cpt, iv - 1);
447  return;
448  }
449  }
450  }
451  }
452 
453  // reorder vars in *this
454  INLINE void Instantiation::reorder(const Instantiation& i) {
456  }
457 
458  // put the (0,0,...) first value in the Instantiation for the variables in i
459  INLINE void Instantiation::setFirstIn(const Instantiation& i) {
460  __overflow = false;
461  Idx s = nbrDim();
462 
463  for (Size p = 0; p < s; ++p)
464  if (i.contains(__vars[p])) __chgVal(p, 0);
465  }
466 
467  // change values with those in i
469  __overflow = false;
470  Idx s = i.nbrDim();
471 
472  for (Size p = 0; p < s; ++p)
473  if (contains(i.variable(p))) __chgVal(pos(i.variable(p)), i.val(p));
474 
475  return *this;
476  }
477 
478  // put the (D1-1,D2-1,...) lastvalue in the Instantiation for variables in i
479  INLINE void Instantiation::setLastIn(const Instantiation& i) {
480  __overflow = false;
481  Idx s = nbrDim();
482 
483  for (Size p = 0; p < s; ++p)
484  if (i.contains(__vars[p])) __chgVal(p, __vars[p]->domainSize() - 1);
485  }
486 
487  // operator ++ for the variables not in i
488  INLINE void Instantiation::incOut(const Instantiation& i) {
489  Size p = nbrDim() - 1;
490  Idx cpt = 0;
491  // if we are in overflow, do nothing
492 
493  if (__overflow) return;
494 
495  while (true) {
496  if (i.contains(__vars[cpt])) {
497  if (cpt == p) {
498  __overflow = true;
499  return;
500  } else
501  ++cpt;
502  } else {
503  Idx v = __vals[cpt];
504 
505  if (v + 1 == __vars[cpt]->domainSize()) {
506  __chgVal(cpt, 0);
507 
508  if (cpt == p) {
509  __overflow = true;
510  return;
511  } else
512  ++cpt;
513  } else {
514  __chgVal(cpt, v + 1);
515  return;
516  }
517  }
518  }
519  }
520 
521  // operator -- for the variables not in i
522  INLINE void Instantiation::decOut(const Instantiation& i) {
523  Size p = nbrDim() - 1;
524  Idx cpt = 0;
525  // if we are in overflow, do nothing
526 
527  if (__overflow) return;
528 
529  while (true) {
530  if (i.contains(__vars[cpt])) {
531  if (cpt == p) {
532  __overflow = true;
533  return;
534  } else
535  ++cpt;
536  } else {
537  Idx v = __vals[cpt];
538 
539  if (v == 0) {
540  __chgVal(cpt, __vars[cpt]->domainSize() - 1);
541 
542  if (cpt == p) {
543  __overflow = true;
544  return;
545  } else
546  ++cpt;
547  } else {
548  __chgVal(cpt, v - 1);
549  return;
550  }
551  }
552  }
553  }
554 
555  // put the (0,0,...) first val in the Instantiation for the variables not in
556  // i
558  __overflow = false;
559  Idx s = nbrDim();
560 
561  for (Size p = 0; p < s; ++p)
562  if (!i.contains(__vars[p])) __chgVal(p, 0);
563  }
564 
565  // put the (D1-1,D2-1,...) lastvalue in the Instantiation for vars not in i
566  INLINE void Instantiation::setLastOut(const Instantiation& i) {
567  __overflow = false;
568  Idx s = nbrDim();
569 
570  for (Size p = 0; p < s; ++p)
571  if (!i.contains(__vars[p])) __chgVal(p, __vars[p]->domainSize() - 1);
572  }
573 
574  // operator ++ for vars which are not v.
576  Size p = nbrDim() - 1;
577  Idx cpt = 0;
578  // if we are in overflow, do nothing
579 
580  if (__overflow) return;
581 
582  while (true) {
583  if (__vars[cpt] == &v) {
584  if (cpt == p) {
585  __overflow = true;
586  return;
587  } else
588  ++cpt;
589  } else {
590  Idx iv = __vals[cpt];
591 
592  if (iv + 1 == __vars[cpt]->domainSize()) {
593  __chgVal(cpt, 0);
594 
595  if (cpt == p) {
596  __overflow = true;
597  return;
598  } else
599  ++cpt;
600  } else {
601  __chgVal(cpt, iv + 1);
602  return;
603  }
604  }
605  }
606  }
607 
608  // operator -- for vars which are not v.
610  Size p = nbrDim() - 1;
611  Idx cpt = 0;
612  // if we are in overflow, do nothing
613 
614  if (__overflow) return;
615 
616  while (true) {
617  if (__vars[cpt] == &v) {
618  if (cpt == p) {
619  __overflow = true;
620  return;
621  } else
622  ++cpt;
623  } else {
624  Idx iv = __vals[cpt];
625 
626  if (iv == 0) {
627  __chgVal(cpt, __vars[cpt]->domainSize() - 1);
628 
629  if (cpt == p) {
630  __overflow = true;
631  return;
632  } else
633  ++cpt;
634  } else {
635  __chgVal(cpt, iv - 1);
636  return;
637  }
638  }
639  }
640  }
641 
642  // assign the (0,0,...) first value to variables which are not v.
644  __overflow = false;
645  Idx s = nbrDim();
646 
647  for (Size p = 0; p < s; ++p) {
648  if (__vars[p] == &v) {
649  Idx oldval = __vals[p];
650  setFirst();
651  __chgVal(p, oldval);
652  return;
653  }
654  }
655 
656  setFirst();
657  }
658 
659  // put the (D1-1,D2-1,...) lastvalue in the Instantiation for vars != v
661  __overflow = false;
662  Idx s = nbrDim();
663 
664  for (Size p = 0; p < s; ++p) {
665  if (__vars[p] == &v) {
666  Idx oldval = __vals[p];
667  setLast();
668  __chgVal(p, oldval);
669  return;
670  }
671  }
672 
673  setLast();
674  }
675 
676  // operator ++ for variable v only
677  INLINE void Instantiation::incVar(const DiscreteVariable& v) {
678  // get the position of the variable
679  Idx cpt = __vars.pos(&v);
680  // if we are in overflow, do nothing
681 
682  if (__overflow) return;
683 
684  Idx p = __vals[cpt];
685 
686  if (p + 1 == v.domainSize()) {
687  __chgVal(cpt, 0);
688  __overflow = true;
689  } else {
690  __chgVal(cpt, p + 1);
691  }
692  }
693 
694  // operator -- for variable v only
695  INLINE void Instantiation::decVar(const DiscreteVariable& v) {
696  // get the position of the variable
697  Idx cpt = __vars.pos(&v);
698  // if we are in overflow, do nothing
699 
700  if (__overflow) return;
701 
702  Idx p = __vals[cpt];
703 
704  if (p == 0) {
705  __chgVal(cpt, v.domainSize() - 1);
706  __overflow = true;
707  } else {
708  __chgVal(cpt, p - 1);
709  }
710  }
711 
712  // assign the first value in the Instantiation for var v.
714  __overflow = false;
715  __chgVal(__vars.pos(&v), 0);
716  }
717 
718  // assign the last value to var v.
720  __overflow = false;
721  __chgVal(__vars.pos(&v), v.domainSize() - 1);
722  }
723 
724  // indicates whether the Instantiation has a master MultiDimAdressable
725  INLINE bool Instantiation::isSlave() const { return (__master != nullptr); }
726 
727  // indicates wether the MultiDimAdressable* m is the master
728  INLINE bool Instantiation::isMaster(const MultiDimAdressable* m) const {
729  return (__master == m);
730  }
731 
732  // indicates wether the MultiDimAdressable* m is the master
733  INLINE bool Instantiation::isMaster(const MultiDimAdressable& m) const {
734  return isMaster(&m);
735  }
736 
737  // returns the sequence of DiscreteVariable
740  return __vars;
741  }
742 
743 
744  // replace 2 vars in the Instantiation
745  INLINE void Instantiation::__swap(Idx i, Idx j) {
746  if (i == j) return;
747 
748  __vars.swap(i, j);
749 
750  Idx v;
751  v = __vals[i];
752  __vals[i] = __vals[j];
753  __vals[j] = v;
754  }
755 
756  // reordering
757  INLINE
758  void
760  if (__master != nullptr) {
762  "Reordering impossible in slave instantiation");
763  }
764 
765  __reorder(original);
766  }
767 
768  INLINE
770  const Sequence< const DiscreteVariable* >& original) {
771  Idx max = original.size();
772  Idx position = 0;
773  for (Idx i = 0; i < max; ++i) {
774  const DiscreteVariable* pv = original.atPos(i);
775 
776  if (contains(pv)) {
777  auto p = pos(*pv);
778  GUM_ASSERT(p >= position); // this var should not be
779  // already placed.
780  __swap(position, p);
781  position++;
782  }
783  }
784  }
785 
786 
787  // add new dim by master
789  const DiscreteVariable& v) {
790  if (m != __master) {
791  GUM_ERROR(OperationNotAllowed, "only master can do this");
792  }
793 
794  __add(v);
795  }
796 
797 
798  // adds a new var to the sequence of vars
799  INLINE void Instantiation::__add(const DiscreteVariable& v) {
800  __vars.insert(&v);
801  __vals.push_back(0);
802  __overflow = false;
803  }
804 
805  // removes a variable from the sequence of vars
806  INLINE void Instantiation::__erase(const DiscreteVariable& v) {
807  // get the position of the variable
808  Idx pos = __vars.pos(&v);
809  __vars.erase(&v);
810  __vals.erase(__vals.begin() + pos);
811  }
812 
813  // is this empty ?
814  INLINE bool Instantiation::empty() const { return __vals.empty(); }
815 
816  // Replace x by y.
818  const DiscreteVariable* y) {
819  __vars.setAtPos(__vars.pos(x), y);
820  }
821 
825  Size h = Size(0);
826  for (const DiscreteVariable* k:
827  key.variablesSequence()) // k are unique only by address (not by name)
829 
830  return h;
831  }
832 
835  INLINE Size
837  return castToSize(key) & this->_hash_mask;
838  }
839 
840  INLINE bool Instantiation::operator==(const Instantiation& other) const {
841  if (inOverflow() && other.inOverflow()) return true;
842  if (other.nbrDim() != nbrDim()) return false;
843  for (const auto& k: variablesSequence()) {
844  if (!other.contains(k)) return false;
845  if (val(*k) != other.val(*k)) return false;
846  }
847  return true;
848  }
849 } /* namespace gum */
void __erase(const DiscreteVariable &v)
Removes a variable from the sequence of vars.
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
void decIn(const Instantiation &i)
Operator decrement for the variables in i.
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
void addWithMaster(const MultiDimAdressable *m, const DiscreteVariable &v)
Call Instantiation::__add(const DiscreteVariable&) by master.
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 __masterDecNotification() const
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:38
void setLast()
Assign the last values in the Instantiation.
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1022
void setLastIn(const Instantiation &i)
Assign the last values in the Instantiation for the variables in i.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void unsetOverflow()
Removes the flag overflow.
void __masterIncNotification() const
void dec()
Operator decrement.
bool operator==(const Instantiation &other) const
operator==
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
void reorder(const Sequence< const DiscreteVariable * > &v)
Reorder vars of this instantiation giving the order in v.
Class template representing hashing function of LpCol.
Definition: hashFunc.h:471
Base class for discrete random variable.
void setLastOut(const Instantiation &i)
Assign the last values in the Instantiation for the variables not in i.
void incNotVar(const DiscreteVariable &v)
Operator increment for vars which are not v.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
Definition: agrum.h:25
void incVar(const DiscreteVariable &v)
Operator increment for variable v only.
Instantiation & setVals(const Instantiation &i)
Assign the values from i in the Instantiation.
const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns the sequence of DiscreteVariable of this instantiation.
void setFirstNotVar(const DiscreteVariable &v)
Assign the first values to variables different of v.
void unsetEnd()
Alias for unsetOverflow().
void decOut(const Instantiation &i)
Operator decrement for the variables not in i.
Idx val(Idx i) const
Returns the current value of the variable at position i.
Instantiation & operator--()
Alias of Instantiation::dec().
virtual Size domainSize() const =0
Instantiation & operator++()
Alias of Instantiation::inc().
bool rend() const
Returns true if the Instantiation reached the rend.
void incOut(const Instantiation &i)
Operator increment for the variables not in i.
void setFirstIn(const Instantiation &i)
Assign the first values in the Instantiation for the variables in i.
void clear()
Erase all variables from an Instantiation.
void inc()
Operator increment.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
void setFirstVar(const DiscreteVariable &v)
Assign the first value in the Instantiation for var v.
void __reorder(const Sequence< const DiscreteVariable * > &v)
Reorder vars of this instantiation giving the order in v.
Instantiation & operator-=(Size depl)
Calls depl times Instantiation::dec().
virtual bool empty() const final
Returns true if the instantiation is empty.
void __masterFirstNotification() const
void incIn(const Instantiation &i)
Operator increment for the variables in i.
void setLastNotVar(const DiscreteVariable &v)
Assign the last values to variables different of v.
void __masterLastNotification() const
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
Abstract base class for all multi dimensionnal addressable.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
bool isMaster(const MultiDimAdressable *m) const
Indicates whether m is the master of this instantiation.
Instantiation & operator+=(Size depl)
Calls depl times Instantiation::inc().
void setLastVar(const DiscreteVariable &v)
Assign the last value in the Instantiation for var v.
void setFirst()
Assign the first values to the tuple of the Instantiation.
void __swap(Idx i, Idx j)
Swap two variables in the Instantiation.
Size Idx
Type for indexes.
Definition: types.h:53
bool inOverflow() const
Indicates whether the current value of the tuple is correct or not.
void decNotVar(const DiscreteVariable &v)
Operator decrement for vars which are not v.
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
void erase(const DiscreteVariable &v) final
Removes a variable from the Instantiation.
bool isSlave() const
Indicates whether the Instantiation has a master.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y) final
Replace x by y.
const std::string & name() const
returns the name of the variable
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
void __add(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
void decVar(const DiscreteVariable &v)
Operator decrement for variable v only.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
void __masterChangeNotification(Idx varPos, Idx newVal, Idx oldVal) const
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
const Key & atPos(Idx i) const
Returns the object at the pos i.
Definition: sequence_tpl.h:500
bool end() const
Returns true if the Instantiation reached the end.
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
void setFirstOut(const Instantiation &i)
Assign the first values in the Instantiation for the variables not in i.