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