aGrUM  0.18.1
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  Size s = 1;
182 
183  for (const auto var: vars__)
184  s *= var->domainSize();
185 
186  return s;
187  }
188 
189  // returns the index of a var
190  INLINE Idx Instantiation::pos(const DiscreteVariable& k) const {
191  return vars__.pos(&k);
192  }
193 
194  // returns the number of vars in the sequence
195  INLINE Idx Instantiation::nbrDim() const { return vars__.size(); }
196 
197  // returns the current value of a given variable
198  INLINE Idx Instantiation::val(Idx i) const {
199  if (i >= vals__.size()) {
200  GUM_ERROR(NotFound, i << " is out of bound index for the instantiation.");
201  }
202 
203  return vals__[i];
204  }
205 
206  // returns the current value of a given variable
207  INLINE Idx Instantiation::val(const DiscreteVariable& var) const {
208  return vals__[vars__.pos(&var)];
209  }
210  // returns the current value of a given variable
211  INLINE Idx Instantiation::val(const std::string& name) const {
212  return val(variable(name));
213  }
214 
215 
216  // returns the current value of a given variable
217  INLINE Idx Instantiation::valFromPtr(const DiscreteVariable* pvar) const {
218  return vals__[vars__.pos(pvar)];
219  }
220 
221  // returns the variable at position i in the tuple
223  return *(vars__.atPos(i));
224  }
225  // returns the variable with name in the tuple
226  INLINE const DiscreteVariable&
227  Instantiation::variable(const std::string& name) const {
228  for (const auto& v: vars__) {
229  if (v->name() == name) return *v;
230  }
231 
232  GUM_ERROR(NotFound, "'" << name << "' can not be found in the instantiation.")
233  }
234 
235  // indicates whether the current value of the tuple is correct or not
236  INLINE bool Instantiation::inOverflow() const { return overflow__; }
237 
238  // end() just is a synonym for inOverflow()
239  INLINE bool Instantiation::end() const { return inOverflow(); }
240 
241  // rend() just is a synonym for inOverflow()
242  INLINE bool Instantiation::rend() const { return inOverflow(); }
243 
244  // indicates that the current value is correct even if it should be in
245  // overflow
246  INLINE void Instantiation::unsetOverflow() { overflow__ = false; }
247 
248  // alias for unsetOverflow
249  INLINE void Instantiation::unsetEnd() { overflow__ = false; }
250 
251  // operator ++
252  INLINE void Instantiation::inc() {
253  Size p = nbrDim();
254  if (p == 0) { overflow__ = true; }
255 
256  if (overflow__) return;
257  p -= 1;
258  Idx cpt = 0;
259  // if we are in overflow, do nothing
260 
261  // perform the increment
262  while (true) {
263  Idx v = vals__[cpt];
264 
265  if (v + 1 == vars__[cpt]->domainSize()) {
266  vals__[cpt] = 0;
267 
268  if (cpt == p) {
269  overflow__ = true;
271  return;
272  } else
273  ++cpt;
274  } else {
275  ++vals__[cpt];
276  break;
277  }
278  }
279 
281  }
282 
283  // operator --
284  INLINE void Instantiation::dec() {
285  Size p = nbrDim();
286  if (p == 0) { overflow__ = true; }
287 
288  if (overflow__) return;
289  p -= 1;
290  Idx cpt = 0;
291  // if we are in overflow, do nothing
292 
293  // perform the increment
294  while (true) {
295  Idx v = vals__[cpt];
296 
297  if (v == 0) {
298  vals__[cpt] = vars__[cpt]->domainSize() - 1;
299 
300  if (cpt == p) {
301  overflow__ = true;
302 
304 
305  return;
306  } else
307  ++cpt;
308  } else {
309  --vals__[cpt];
310  break;
311  }
312  }
313 
315  }
316 
317  // operator ++
319  inc();
320  return *this;
321  }
322 
323  // operator --
325  dec();
326  return *this;
327  }
328 
329  // operator +=
331  for (Idx i = 0; i < depl; i++)
332  inc();
333 
334  return *this;
335  }
336 
337  // operator -=
339  for (Idx i = 0; i < depl; i++)
340  dec();
341 
342  return *this;
343  }
344 
345  // assign the (0,0,...) first value to the tuple of the Instantiation.
346  INLINE void Instantiation::setFirst() {
347  overflow__ = false;
348  Size s = nbrDim();
349 
350  for (Idx p = 0; p < s; ++p)
351  vals__[p] = 0;
352 
354  }
355 
356  // put the (D1-1,D2-1,...) last value in the Instantiation
357  INLINE void Instantiation::setLast() {
358  overflow__ = false;
359  Size s = nbrDim();
360 
361  for (Idx p = 0; p < s; ++p)
362  vals__[p] = vars__[p]->domainSize() - 1;
363 
365  }
366 
367  // operator ++ limited only to the variables in i
368  INLINE void Instantiation::incIn(const Instantiation& i) {
369  // if i is empty, overflow and do nothing
370  if (i.nbrDim() == 0) {
371  overflow__ = true;
372  return;
373  }
374 
375  // if we are in overflow, do nothing
376  if (overflow__) return;
377 
378  Size p = i.nbrDim() - 1;
379 
380  Idx i_cpt = 0;
381 
382  while (true) {
383  // verify that vars__[cpt] belongs to i before incrementing its value
384  const DiscreteVariable& v = i.variable(i_cpt);
385 
386  if (!contains(v)) {
387  if (i_cpt == p) {
388  overflow__ = true;
389  return;
390  } else
391  ++i_cpt;
392  } else {
393  Idx cpt = pos(v);
394  Idx iv = vals__[cpt];
395 
396  if (iv + 1 == vars__[cpt]->domainSize()) {
397  chgVal__(cpt, 0);
398 
399  if (i_cpt == p) {
400  overflow__ = true;
401  return;
402  } else
403  ++i_cpt;
404  } else {
405  chgVal__(cpt, iv + 1);
406  return;
407  }
408  }
409  }
410  }
411 
412  // operator -- limited only to the variables in i
413  INLINE void Instantiation::decIn(const Instantiation& i) {
414  Size p = i.nbrDim() - 1;
415  Idx i_cpt = 0;
416  // if we are in overflow, do nothing
417 
418  if (overflow__) return;
419 
420  while (true) {
421  // verify that vars__[cpt] belongs to i before incrementing its value
422  const DiscreteVariable& v = i.variable(i_cpt);
423 
424  if (!contains(v)) {
425  if (i_cpt == p) {
426  overflow__ = true;
427  return;
428  } else
429  ++i_cpt;
430  } else {
431  Idx cpt = pos(v);
432  Idx iv = vals__[cpt];
433 
434  if (iv == 0) {
435  chgVal__(cpt, vars__[cpt]->domainSize() - 1);
436 
437  if (i_cpt == p) {
438  overflow__ = true;
439  return;
440  } else
441  ++i_cpt;
442  } else {
443  chgVal__(cpt, iv - 1);
444  return;
445  }
446  }
447  }
448  }
449 
450  // reorder vars in *this
451  INLINE void Instantiation::reorder(const Instantiation& i) {
453  }
454 
455  // put the (0,0,...) first value in the Instantiation for the variables in i
456  INLINE void Instantiation::setFirstIn(const Instantiation& i) {
457  overflow__ = false;
458  Idx s = nbrDim();
459 
460  for (Size p = 0; p < s; ++p)
461  if (i.contains(vars__[p])) chgVal__(p, 0);
462  }
463 
464  // change values with those in i
466  overflow__ = false;
467  Idx s = i.nbrDim();
468 
469  for (Size p = 0; p < s; ++p)
470  if (contains(i.variable(p))) chgVal__(pos(i.variable(p)), i.val(p));
471 
472  return *this;
473  }
474 
475  // put the (D1-1,D2-1,...) lastvalue in the Instantiation for variables in i
476  INLINE void Instantiation::setLastIn(const Instantiation& i) {
477  overflow__ = false;
478  Idx s = nbrDim();
479 
480  for (Size p = 0; p < s; ++p)
481  if (i.contains(vars__[p])) chgVal__(p, vars__[p]->domainSize() - 1);
482  }
483 
484  // operator ++ for the variables not in i
485  INLINE void Instantiation::incOut(const Instantiation& i) {
486  Size p = nbrDim() - 1;
487  Idx cpt = 0;
488  // if we are in overflow, do nothing
489 
490  if (overflow__) return;
491 
492  while (true) {
493  if (i.contains(vars__[cpt])) {
494  if (cpt == p) {
495  overflow__ = true;
496  return;
497  } else
498  ++cpt;
499  } else {
500  Idx v = vals__[cpt];
501 
502  if (v + 1 == vars__[cpt]->domainSize()) {
503  chgVal__(cpt, 0);
504 
505  if (cpt == p) {
506  overflow__ = true;
507  return;
508  } else
509  ++cpt;
510  } else {
511  chgVal__(cpt, v + 1);
512  return;
513  }
514  }
515  }
516  }
517 
518  // operator -- for the variables not in i
519  INLINE void Instantiation::decOut(const Instantiation& i) {
520  Size p = nbrDim() - 1;
521  Idx cpt = 0;
522  // if we are in overflow, do nothing
523 
524  if (overflow__) return;
525 
526  while (true) {
527  if (i.contains(vars__[cpt])) {
528  if (cpt == p) {
529  overflow__ = true;
530  return;
531  } else
532  ++cpt;
533  } else {
534  Idx v = vals__[cpt];
535 
536  if (v == 0) {
537  chgVal__(cpt, vars__[cpt]->domainSize() - 1);
538 
539  if (cpt == p) {
540  overflow__ = true;
541  return;
542  } else
543  ++cpt;
544  } else {
545  chgVal__(cpt, v - 1);
546  return;
547  }
548  }
549  }
550  }
551 
552  // put the (0,0,...) first val in the Instantiation for the variables not in
553  // i
555  overflow__ = false;
556  Idx s = nbrDim();
557 
558  for (Size p = 0; p < s; ++p)
559  if (!i.contains(vars__[p])) chgVal__(p, 0);
560  }
561 
562  // put the (D1-1,D2-1,...) lastvalue in the Instantiation for vars not in i
563  INLINE void Instantiation::setLastOut(const Instantiation& i) {
564  overflow__ = false;
565  Idx s = nbrDim();
566 
567  for (Size p = 0; p < s; ++p)
568  if (!i.contains(vars__[p])) chgVal__(p, vars__[p]->domainSize() - 1);
569  }
570 
571  // operator ++ for vars which are not v.
573  Size p = nbrDim() - 1;
574  Idx cpt = 0;
575  // if we are in overflow, do nothing
576 
577  if (overflow__) return;
578 
579  while (true) {
580  if (vars__[cpt] == &v) {
581  if (cpt == p) {
582  overflow__ = true;
583  return;
584  } else
585  ++cpt;
586  } else {
587  Idx iv = vals__[cpt];
588 
589  if (iv + 1 == vars__[cpt]->domainSize()) {
590  chgVal__(cpt, 0);
591 
592  if (cpt == p) {
593  overflow__ = true;
594  return;
595  } else
596  ++cpt;
597  } else {
598  chgVal__(cpt, iv + 1);
599  return;
600  }
601  }
602  }
603  }
604 
605  // operator -- for vars which are not v.
607  Size p = nbrDim() - 1;
608  Idx cpt = 0;
609  // if we are in overflow, do nothing
610 
611  if (overflow__) return;
612 
613  while (true) {
614  if (vars__[cpt] == &v) {
615  if (cpt == p) {
616  overflow__ = true;
617  return;
618  } else
619  ++cpt;
620  } else {
621  Idx iv = vals__[cpt];
622 
623  if (iv == 0) {
624  chgVal__(cpt, vars__[cpt]->domainSize() - 1);
625 
626  if (cpt == p) {
627  overflow__ = true;
628  return;
629  } else
630  ++cpt;
631  } else {
632  chgVal__(cpt, iv - 1);
633  return;
634  }
635  }
636  }
637  }
638 
639  // assign the (0,0,...) first value to variables which are not v.
641  overflow__ = false;
642  Idx s = nbrDim();
643 
644  for (Size p = 0; p < s; ++p) {
645  if (vars__[p] == &v) {
646  Idx oldval = vals__[p];
647  setFirst();
648  chgVal__(p, oldval);
649  return;
650  }
651  }
652 
653  setFirst();
654  }
655 
656  // put the (D1-1,D2-1,...) lastvalue in the Instantiation for vars != v
658  overflow__ = false;
659  Idx s = nbrDim();
660 
661  for (Size p = 0; p < s; ++p) {
662  if (vars__[p] == &v) {
663  Idx oldval = vals__[p];
664  setLast();
665  chgVal__(p, oldval);
666  return;
667  }
668  }
669 
670  setLast();
671  }
672 
673  // operator ++ for variable v only
674  INLINE void Instantiation::incVar(const DiscreteVariable& v) {
675  // get the position of the variable
676  Idx cpt = vars__.pos(&v);
677  // if we are in overflow, do nothing
678 
679  if (overflow__) return;
680 
681  Idx p = vals__[cpt];
682 
683  if (p + 1 == v.domainSize()) {
684  chgVal__(cpt, 0);
685  overflow__ = true;
686  } else {
687  chgVal__(cpt, p + 1);
688  }
689  }
690 
691  // operator -- for variable v only
692  INLINE void Instantiation::decVar(const DiscreteVariable& v) {
693  // get the position of the variable
694  Idx cpt = vars__.pos(&v);
695  // if we are in overflow, do nothing
696 
697  if (overflow__) return;
698 
699  Idx p = vals__[cpt];
700 
701  if (p == 0) {
702  chgVal__(cpt, v.domainSize() - 1);
703  overflow__ = true;
704  } else {
705  chgVal__(cpt, p - 1);
706  }
707  }
708 
709  // assign the first value in the Instantiation for var v.
711  overflow__ = false;
712  chgVal__(vars__.pos(&v), 0);
713  }
714 
715  // assign the last value to var v.
717  overflow__ = false;
718  chgVal__(vars__.pos(&v), v.domainSize() - 1);
719  }
720 
721  // indicates whether the Instantiation has a master MultiDimAdressable
722  INLINE bool Instantiation::isSlave() const { return (master__ != nullptr); }
723 
724  // indicates wether the MultiDimAdressable* m is the master
725  INLINE bool Instantiation::isMaster(const MultiDimAdressable* m) const {
726  return (master__ == m);
727  }
728 
729  // indicates wether the MultiDimAdressable* m is the master
730  INLINE bool Instantiation::isMaster(const MultiDimAdressable& m) const {
731  return isMaster(&m);
732  }
733 
734  // returns the sequence of DiscreteVariable
737  return vars__;
738  }
739 
740 
741  // replace 2 vars in the Instantiation
742  INLINE void Instantiation::swap__(Idx i, Idx j) {
743  if (i == j) return;
744 
745  vars__.swap(i, j);
746 
747  Idx v;
748  v = vals__[i];
749  vals__[i] = vals__[j];
750  vals__[j] = v;
751  }
752 
753  // reordering
754  INLINE
755  void
757  if (master__ != nullptr) {
759  "Reordering impossible in slave instantiation");
760  }
761 
762  reorder__(original);
763  }
764 
765  INLINE
767  const Sequence< const DiscreteVariable* >& original) {
768  Idx max = original.size();
769  Idx position = 0;
770  for (Idx i = 0; i < max; ++i) {
771  const DiscreteVariable* pv = original.atPos(i);
772 
773  if (contains(pv)) {
774  auto p = pos(*pv);
775  GUM_ASSERT(p >= position); // this var should not be
776  // already placed.
777  swap__(position, p);
778  position++;
779  }
780  }
781  }
782 
783 
784  // add new dim by master
786  const DiscreteVariable& v) {
787  if (m != master__) {
788  GUM_ERROR(OperationNotAllowed, "only master can do this");
789  }
790 
791  add__(v);
792  }
793 
794 
795  // adds a new var to the sequence of vars
796  INLINE void Instantiation::add__(const DiscreteVariable& v) {
797  vars__.insert(&v);
798  vals__.push_back(0);
799  overflow__ = false;
800  }
801 
802  // removes a variable from the sequence of vars
803  INLINE void Instantiation::erase__(const DiscreteVariable& v) {
804  // get the position of the variable
805  Idx pos = vars__.pos(&v);
806  vars__.erase(&v);
807  vals__.erase(vals__.begin() + pos);
808  }
809 
810  // is this empty ?
811  INLINE bool Instantiation::empty() const { return vals__.empty(); }
812 
813  // Replace x by y.
815  const DiscreteVariable* y) {
816  vars__.setAtPos(vars__.pos(x), y);
817  }
818 
822  Size h = Size(0);
823  for (const DiscreteVariable* k:
824  key.variablesSequence()) // k are unique only by address (not by name)
826 
827  return h;
828  }
829 
832  INLINE Size
834  return castToSize(key) & this->hash_mask_;
835  }
836 
837  INLINE bool Instantiation::operator==(const Instantiation& other) const {
838  if (inOverflow() && other.inOverflow()) return true;
839  if (other.nbrDim() != nbrDim()) return false;
840  for (const auto& k: variablesSequence()) {
841  if (!other.contains(k)) return false;
842  if (val(*k) != other.val(*k)) return false;
843  }
844  return true;
845  }
846 } /* namespace gum */
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.
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 masterFirstNotification__() const
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y) final
Replace x by y.
Size size() const noexcept
Returns the size of the sequence.
Definition: sequence_tpl.h:38
void add__(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
void setLast()
Assign the last values in the Instantiation.
void masterLastNotification__() const
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.
std::vector< Idx > vals__
The current instantiation: the value of the tuple.
void masterIncNotification__() const
void unsetOverflow()
Removes the flag overflow.
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.
Sequence< const DiscreteVariable *> vars__
The tuple of variables to be instantiated.
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 erase__(const DiscreteVariable &v)
Removes a variable from the sequence of vars.
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() & Christophe GONZALES() info_at_agrum_dot_org.
Definition: agrum.h:25
void incVar(const DiscreteVariable &v)
Operator increment for variable v only.
void masterChangeNotification__(Idx varPos, Idx newVal, Idx oldVal) const
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 masterDecNotification__() const
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 setFirstVar(const DiscreteVariable &v)
Assign the first value in the Instantiation for var v.
Instantiation & operator-=(Size depl)
Calls depl times Instantiation::dec().
virtual bool empty() const final
Returns true if the instantiation is empty.
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.
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.
Size Idx
Type for indexes.
Definition: types.h:53
void chgVal__(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
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
bool overflow__
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
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 swap__(Idx i, Idx j)
Swap two variables in the Instantiation.
void decVar(const DiscreteVariable &v)
Operator decrement for variable v only.
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
#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.
void setFirstOut(const Instantiation &i)
Assign the first values in the Instantiation for the variables not in i.