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