aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
instantiation_inl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40#pragma once
41
42
49
51
52namespace gum {
53 // indicates whether a given variable belongs to the Instantiation
54 INLINE bool Instantiation::contains(const DiscreteVariable& v) const { return _vars_.exists(&v); }
55
56 INLINE bool Instantiation::contains(const std::string& name) const {
57 for (const auto& v: _vars_) {
58 if (v->name() == name) return true;
59 }
60 return false;
61 }
62
63 // indicates whether a given variable belongs to the Instantiation
64 INLINE bool Instantiation::contains(const DiscreteVariable* v) const { return _vars_.exists(v); }
65
66 // modifies internally the value of a given variable of the sequence
67 INLINE void Instantiation::_chgVal_(Idx varPos, Idx newVal) {
68 Idx oldVal = _vals_[varPos];
69 _vals_[varPos] = newVal;
70
71 _masterChangeNotification_(varPos, newVal, oldVal);
72 }
73
74 // modifies the value of a given variable of the sequence (external function)
76 try {
77 // check that the variable does belong to the instantiation and that the
78 // new
79 // value is possible.
80 Idx varPos = _vars_.pos(&v); // throws NotFound if v doesn't belong to this
81
82 if (newVal >= v.domainSize()) { GUM_ERROR(OutOfBounds, "") }
83
84 // if we were in overflow, indicate that we are not anymore
85 _overflow_ = false;
86
87 _chgVal_(varPos, newVal);
88
89 return *this;
90 } catch (NotFound const&) {
91 std::string name = "instantiation does not contain this DiscreteVariable: ";
92 GUM_ERROR(NotFound, name + v.name())
93 }
94 }
95
96 // modifies the value of a given variable of the sequence (external function)
97 INLINE Instantiation& Instantiation::chgVal(Idx varPos, Idx newVal) {
98 // check that the variable does belong to the instantiation and that the new
99 // value is possible.
100 if (_vals_.size() <= varPos) { GUM_ERROR(NotFound, "") }
101
102 if (newVal >= _vars_[varPos]->domainSize()) { GUM_ERROR(OutOfBounds, "") }
103
104 // if we were in overflow, indicate that we are not anymore
105 _overflow_ = false;
106
107 _chgVal_(varPos, newVal);
108
109 return *this;
110 }
111
112 INLINE Instantiation& Instantiation::chgVal(const std::string& var, Idx newVal) {
113 return chgVal(variable(var), newVal);
114 }
115
116 INLINE Instantiation& Instantiation::chgVal(const std::string& var, const std::string& newVal) {
117 const auto& vv = variable(var);
118 Idx pos = vv.index(newVal);
119 return chgVal(vv, pos);
120 }
121
122 // adds a new var to the sequence of vars
123 INLINE void Instantiation::add(const DiscreteVariable& v) {
124 // if _master_ : not allowed
125 if (_master_) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
126
127 // check if the variable already belongs to the tuple of variables
128 // of the Instantiation
129 if (_vars_.exists(&v)) {
130 GUM_ERROR(DuplicateElement, "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() << "> already exists in this instantiation");
137 }
138 }
139
140 // actually add the new dimension
141 _add_(v);
142 }
143
144 // removes a variable from the sequence of vars
146 // if _master_ : not allowed
147 if (_master_) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
148
149 // check that the variable does actually belong to the Instantiation
150 if (!_vars_.exists(&v)) { GUM_ERROR(NotFound, "Var does not exist in this instantiation") }
151
152 // actually delete the dimension
153 _erase_(v);
154 }
155
156 INLINE void Instantiation::erase(const std::string& name) { erase(variable(name)); }
157
158 // removes everything
159 INLINE void Instantiation::clear() {
160 if (_master_) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
161
162 _vars_.clear();
163 _vals_.clear();
164 }
165
166 // @brief returns the product of the size of the domains of the variables
167 // belonging to the matrix
169 Size s = 1;
170
171 for (const auto var: _vars_)
172 s *= var->domainSize();
173
174 return s;
175 }
176
177 // returns the index of a var
178 INLINE Idx Instantiation::pos(const DiscreteVariable& k) const { return _vars_.pos(&k); }
179
180 // returns the number of vars in the sequence
181 INLINE Idx Instantiation::nbrDim() const { return _vars_.size(); }
182
183 // returns the current value of a given variable
184 INLINE Idx Instantiation::val(Idx i) const {
185 if (i >= _vals_.size()) {
186 GUM_ERROR(NotFound, i << " is out of bound index for the instantiation.")
187 }
188
189 return _vals_[i];
190 }
191
192 // returns the current value of a given variable
193 INLINE Idx Instantiation::val(const DiscreteVariable& var) const {
194 return _vals_[_vars_.pos(&var)];
195 }
196
197 // returns the current value of a given variable
198 INLINE Idx Instantiation::val(const std::string& name) const { return val(variable(name)); }
199
200 // returns the current value of a given variable
202 return _vals_[_vars_.pos(pvar)];
203 }
204
205 // returns the variable at position i in the tuple
206 INLINE const DiscreteVariable& Instantiation::variable(Idx i) const { return *(_vars_.atPos(i)); }
207
208 // returns the variable with name in the tuple
209 INLINE const DiscreteVariable& Instantiation::variable(const std::string& name) const {
210 for (const auto& v: _vars_) {
211 if (v->name() == name) return *v;
212 }
213
214 GUM_ERROR(NotFound, "'" << name << "' can not be found in the instantiation.")
215 }
216
217 // indicates whether the current value of the tuple is correct or not
218 INLINE bool Instantiation::inOverflow() const { return _overflow_; }
219
220 // end() just is a synonym for inOverflow()
221 INLINE bool Instantiation::end() const { return inOverflow(); }
222
223 // rend() just is a synonym for inOverflow()
224 INLINE bool Instantiation::rend() const { return inOverflow(); }
225
226 // indicates that the current value is correct even if it should be in
227 // overflow
228 INLINE void Instantiation::unsetOverflow() { _overflow_ = false; }
229
230 // alias for unsetOverflow
231 INLINE void Instantiation::unsetEnd() { _overflow_ = false; }
232
233 // operator ++
234 INLINE void Instantiation::inc() {
235 Size p = nbrDim();
236 if (p == 0) { _overflow_ = true; }
237
238 if (_overflow_) return;
239 p -= 1;
240 Idx cpt = 0;
241 // if we are in overflow, do nothing
242
243 // perform the increment
244 while (true) {
245 Idx v = _vals_[cpt];
246
247 if (v + 1 == _vars_[cpt]->domainSize()) {
248 _vals_[cpt] = 0;
249
250 if (cpt == p) {
251 _overflow_ = true;
253 return;
254 } else ++cpt;
255 } else {
256 ++_vals_[cpt];
257 break;
258 }
259 }
260
262 }
263
264 // operator --
265 INLINE void Instantiation::dec() {
266 Size p = nbrDim();
267 if (p == 0) { _overflow_ = true; }
268
269 if (_overflow_) return;
270 p -= 1;
271 Idx cpt = 0;
272 // if we are in overflow, do nothing
273
274 // perform the increment
275 while (true) {
276 Idx v = _vals_[cpt];
277
278 if (v == 0) {
279 _vals_[cpt] = _vars_[cpt]->domainSize() - 1;
280
281 if (cpt == p) {
282 _overflow_ = true;
283
285
286 return;
287 } else ++cpt;
288 } else {
289 --_vals_[cpt];
290 break;
291 }
292 }
293
295 }
296
297 // operator ++
299 inc();
300 return *this;
301 }
302
303 // operator --
305 dec();
306 return *this;
307 }
308
309 // operator +=
311 for (Idx i = 0; i < depl; i++)
312 inc();
313
314 return *this;
315 }
316
317 // operator -=
319 for (Idx i = 0; i < depl; i++)
320 dec();
321
322 return *this;
323 }
324
325 // assign the (0,0,...) first value to the tuple of the Instantiation.
327 _overflow_ = false;
328 Size s = nbrDim();
329
330 for (Idx p = 0; p < s; ++p)
331 _vals_[p] = 0;
332
334 }
335
336 // put the (D1-1,D2-1,...) last value in the Instantiation
338 _overflow_ = false;
339 Size s = nbrDim();
340
341 for (Idx p = 0; p < s; ++p)
342 _vals_[p] = _vars_[p]->domainSize() - 1;
343
345 }
346
347 // operator ++ limited only to the variables in i
348 INLINE void Instantiation::incIn(const Instantiation& i) {
349 // if i is empty, overflow and do nothing
350 if (i.nbrDim() == 0) {
351 _overflow_ = true;
352 return;
353 }
354
355 // if we are in overflow, do nothing
356 if (_overflow_) return;
357
358 Size p = i.nbrDim() - 1;
359
360 Idx i_cpt = 0;
361
362 while (true) {
363 // verify that _vars_[cpt] belongs to i before incrementing its value
364 const DiscreteVariable& v = i.variable(i_cpt);
365
366 if (!contains(v)) {
367 if (i_cpt == p) {
368 _overflow_ = true;
369 return;
370 } else ++i_cpt;
371 } else {
372 Idx cpt = pos(v);
373 Idx iv = _vals_[cpt];
374
375 if (iv + 1 == _vars_[cpt]->domainSize()) {
376 _chgVal_(cpt, 0);
377
378 if (i_cpt == p) {
379 _overflow_ = true;
380 return;
381 } else ++i_cpt;
382 } else {
383 _chgVal_(cpt, iv + 1);
384 return;
385 }
386 }
387 }
388 }
389
390 // operator -- limited only to the variables in i
391 INLINE void Instantiation::decIn(const Instantiation& i) {
392 Size p = i.nbrDim() - 1;
393 Idx i_cpt = 0;
394 // if we are in overflow, do nothing
395
396 if (_overflow_) return;
397
398 while (true) {
399 // verify that _vars_[cpt] belongs to i before incrementing its value
400 const DiscreteVariable& v = i.variable(i_cpt);
401
402 if (!contains(v)) {
403 if (i_cpt == p) {
404 _overflow_ = true;
405 return;
406 } else ++i_cpt;
407 } else {
408 Idx cpt = pos(v);
409 Idx iv = _vals_[cpt];
410
411 if (iv == 0) {
412 _chgVal_(cpt, _vars_[cpt]->domainSize() - 1);
413
414 if (i_cpt == p) {
415 _overflow_ = true;
416 return;
417 } else ++i_cpt;
418 } else {
419 _chgVal_(cpt, iv - 1);
420 return;
421 }
422 }
423 }
424 }
425
426 // reorder vars in *this
428
429 // put the (0,0,...) first value in the Instantiation for the variables in i
431 _overflow_ = false;
432 Idx s = nbrDim();
433
434 for (Size p = 0; p < s; ++p)
435 if (i.contains(_vars_[p])) _chgVal_(p, 0);
436 }
437
438 // change values with those in i
440 _overflow_ = false;
441 Idx s = i.nbrDim();
442
443 for (Size p = 0; p < s; ++p)
444 if (contains(i.variable(p))) _chgVal_(pos(i.variable(p)), i.val(p));
445
446 return *this;
447 }
448
449 // put the (D1-1,D2-1,...) lastvalue in the Instantiation for variables in i
451 _overflow_ = false;
452 Idx s = nbrDim();
453
454 for (Size p = 0; p < s; ++p)
455 if (i.contains(_vars_[p])) _chgVal_(p, _vars_[p]->domainSize() - 1);
456 }
457
458 // operator ++ for the variables not in i
459 INLINE void Instantiation::incOut(const Instantiation& i) {
460 Size p = nbrDim() - 1;
461 Idx cpt = 0;
462 // if we are in overflow, do nothing
463
464 if (_overflow_) return;
465
466 while (true) {
467 if (i.contains(_vars_[cpt])) {
468 if (cpt == p) {
469 _overflow_ = true;
470 return;
471 } else ++cpt;
472 } else {
473 Idx v = _vals_[cpt];
474
475 if (v + 1 == _vars_[cpt]->domainSize()) {
476 _chgVal_(cpt, 0);
477
478 if (cpt == p) {
479 _overflow_ = true;
480 return;
481 } else ++cpt;
482 } else {
483 _chgVal_(cpt, v + 1);
484 return;
485 }
486 }
487 }
488 }
489
490 // operator -- for the variables not in i
491 INLINE void Instantiation::decOut(const Instantiation& i) {
492 Size p = nbrDim() - 1;
493 Idx cpt = 0;
494 // if we are in overflow, do nothing
495
496 if (_overflow_) return;
497
498 while (true) {
499 if (i.contains(_vars_[cpt])) {
500 if (cpt == p) {
501 _overflow_ = true;
502 return;
503 } else ++cpt;
504 } else {
505 Idx v = _vals_[cpt];
506
507 if (v == 0) {
508 _chgVal_(cpt, _vars_[cpt]->domainSize() - 1);
509
510 if (cpt == p) {
511 _overflow_ = true;
512 return;
513 } else ++cpt;
514 } else {
515 _chgVal_(cpt, v - 1);
516 return;
517 }
518 }
519 }
520 }
521
522 // put the (0,0,...) first val in the Instantiation for the variables not in
523 // i
525 _overflow_ = false;
526 Idx s = nbrDim();
527
528 for (Size p = 0; p < s; ++p)
529 if (!i.contains(_vars_[p])) _chgVal_(p, 0);
530 }
531
532 // put the (D1-1,D2-1,...) lastvalue in the Instantiation for vars not in i
534 _overflow_ = false;
535 Idx s = nbrDim();
536
537 for (Size p = 0; p < s; ++p)
538 if (!i.contains(_vars_[p])) _chgVal_(p, _vars_[p]->domainSize() - 1);
539 }
540
541 // operator ++ for vars which are not v.
543 Size p = nbrDim() - 1;
544 Idx cpt = 0;
545 // if we are in overflow, do nothing
546
547 if (_overflow_) return;
548
549 while (true) {
550 if (_vars_[cpt] == &v) {
551 if (cpt == p) {
552 _overflow_ = true;
553 return;
554 } else ++cpt;
555 } else {
556 Idx iv = _vals_[cpt];
557
558 if (iv + 1 == _vars_[cpt]->domainSize()) {
559 _chgVal_(cpt, 0);
560
561 if (cpt == p) {
562 _overflow_ = true;
563 return;
564 } else ++cpt;
565 } else {
566 _chgVal_(cpt, iv + 1);
567 return;
568 }
569 }
570 }
571 }
572
573 // operator -- for vars which are not v.
575 Size p = nbrDim() - 1;
576 Idx cpt = 0;
577 // if we are in overflow, do nothing
578
579 if (_overflow_) return;
580
581 while (true) {
582 if (_vars_[cpt] == &v) {
583 if (cpt == p) {
584 _overflow_ = true;
585 return;
586 } else ++cpt;
587 } else {
588 Idx iv = _vals_[cpt];
589
590 if (iv == 0) {
591 _chgVal_(cpt, _vars_[cpt]->domainSize() - 1);
592
593 if (cpt == p) {
594 _overflow_ = true;
595 return;
596 } else ++cpt;
597 } else {
598 _chgVal_(cpt, iv - 1);
599 return;
600 }
601 }
602 }
603 }
604
605 // assign the (0,0,...) first value to variables which are not v.
607 _overflow_ = false;
608 Idx s = nbrDim();
609
610 for (Size p = 0; p < s; ++p) {
611 if (_vars_[p] == &v) {
612 Idx oldval = _vals_[p];
613 setFirst();
614 _chgVal_(p, oldval);
615 return;
616 }
617 }
618
619 setFirst();
620 }
621
622 // put the (D1-1,D2-1,...) lastvalue in the Instantiation for vars != v
624 _overflow_ = false;
625 Idx s = nbrDim();
626
627 for (Size p = 0; p < s; ++p) {
628 if (_vars_[p] == &v) {
629 Idx oldval = _vals_[p];
630 setLast();
631 _chgVal_(p, oldval);
632 return;
633 }
634 }
635
636 setLast();
637 }
638
639 // operator ++ for variable v only
641 // get the position of the variable
642 Idx cpt = _vars_.pos(&v);
643 // if we are in overflow, do nothing
644
645 if (_overflow_) return;
646
647 Idx p = _vals_[cpt];
648
649 if (p + 1 == v.domainSize()) {
650 _chgVal_(cpt, 0);
651 _overflow_ = true;
652 } else {
653 _chgVal_(cpt, p + 1);
654 }
655 }
656
657 // operator -- for variable v only
659 // get the position of the variable
660 Idx cpt = _vars_.pos(&v);
661 // if we are in overflow, do nothing
662
663 if (_overflow_) return;
664
665 Idx p = _vals_[cpt];
666
667 if (p == 0) {
668 _chgVal_(cpt, v.domainSize() - 1);
669 _overflow_ = true;
670 } else {
671 _chgVal_(cpt, p - 1);
672 }
673 }
674
675 // assign the first value in the Instantiation for var v.
677 _overflow_ = false;
678 _chgVal_(_vars_.pos(&v), 0);
679 }
680
681 // assign the last value to var v.
683 _overflow_ = false;
684 _chgVal_(_vars_.pos(&v), v.domainSize() - 1);
685 }
686
687 // indicates whether the Instantiation has a master MultiDimAdressable
688 INLINE bool Instantiation::isSlave() const { return (_master_ != nullptr); }
689
690 // indicates wether the MultiDimAdressable* m is the master
691 INLINE bool Instantiation::isMaster(const MultiDimAdressable* m) const { return (_master_ == m); }
692
693 // indicates wether the MultiDimAdressable* m is the master
694 INLINE bool Instantiation::isMaster(const MultiDimAdressable& m) const { return isMaster(&m); }
695
696 // returns the sequence of DiscreteVariable
700
701 // replace 2 vars in the Instantiation
702 INLINE void Instantiation::_swap_(Idx i, Idx j) {
703 if (i == j) return;
704
705 _vars_.swap(i, j);
706
707 Idx v;
708 v = _vals_[i];
709 _vals_[i] = _vals_[j];
710 _vals_[j] = v;
711 }
712
713 // reordering
714 INLINE
715
717 if (_master_ != nullptr) {
718 GUM_ERROR(OperationNotAllowed, "Reordering impossible in slave instantiation")
719 }
720
721 _reorder_(original);
722 }
723
724 INLINE
725
727 Idx max = original.size();
728 Idx position = 0;
729 for (Idx i = 0; i < max; ++i) {
730 const DiscreteVariable* pv = original.atPos(i);
731
732 if (contains(pv)) {
733 auto p = pos(*pv);
734 GUM_ASSERT(p >= position); // this var should not be
735 // already placed.
736 _swap_(position, p);
737 position++;
738 }
739 }
740 }
741
742 // add new dim by master
744 if (m != _master_) { GUM_ERROR(OperationNotAllowed, "only master can do this") }
745
746 _add_(v);
747 }
748
749 // adds a new var to the sequence of vars
751 _vars_.insert(&v);
752 _vals_.push_back(0);
753 _overflow_ = false;
754 }
755
756 // removes a variable from the sequence of vars
758 // get the position of the variable
759 Idx pos = _vars_.pos(&v);
760 _vars_.erase(&v);
761 _vals_.erase(_vals_.begin() + pos);
762 }
763
764 // is this empty ?
765 INLINE bool Instantiation::empty() const { return _vals_.empty(); }
766
767 // Replace x by y.
769 _vars_.setAtPos(_vars_.pos(x), y);
770 }
771
775 Size h = Size(0);
776 for (const DiscreteVariable* k:
777 key.variablesSequence()) // k are unique only by address (not by name)
779
780 return h;
781 }
782
786 return castToSize(key) & this->hash_mask_;
787 }
788
789 INLINE bool Instantiation::operator==(const Instantiation& other) const {
790 if (inOverflow() && other.inOverflow()) return true;
791 if (other.nbrDim() != nbrDim()) return false;
792 for (const auto& k: variablesSequence()) {
793 if (!other.contains(k)) return false;
794 if (val(*k) != other.val(*k)) return false;
795 }
796 return true;
797 }
798} /* namespace gum */
Base class for discrete random variable.
virtual Size domainSize() const =0
Exception : a similar element already exists.
static Size castToSize(const Instantiation &key)
Returns the value of a key as a Size.
virtual Size operator()(const Instantiation &key) const override final
Computes the hashed value of a key.
This class should be useless as only its specializations should be used.
Definition hashFunc.h:487
Class for assigning/browsing values to tuples of discrete variables.
const Sequence< const DiscreteVariable * > & variablesSequence() const final
Returns the sequence of DiscreteVariable of this instantiation.
void setLastOut(const Instantiation &i)
Assign the last values in the Instantiation for the variables not in i.
void incIn(const Instantiation &i)
Operator increment for the variables in i.
void decNotVar(const DiscreteVariable &v)
Operator decrement for vars which are not v.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
bool end() const
Returns true if the Instantiation reached the end.
void incOut(const Instantiation &i)
Operator increment for the variables not in i.
void decOut(const Instantiation &i)
Operator decrement for the variables not in i.
void clear()
Erase all variables from an Instantiation.
void _masterIncNotification_() const
Instantiation & operator--()
Alias of Instantiation::dec().
Sequence< const DiscreteVariable * > _vars_
The tuple of variables to be instantiated.
void incVar(const DiscreteVariable &v)
Operator increment for variable v only.
bool isMaster(const MultiDimAdressable *m) const
Indicates whether m is the master of this instantiation.
void _masterFirstNotification_() const
void setFirstNotVar(const DiscreteVariable &v)
Assign the first values to variables different of v.
void setFirstIn(const Instantiation &i)
Assign the first values in the Instantiation for the variables in i.
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
void decVar(const DiscreteVariable &v)
Operator decrement for variable v only.
void decIn(const Instantiation &i)
Operator decrement for the variables in i.
Instantiation & setVals(const Instantiation &i)
Assign the values from i in the Instantiation.
Instantiation & operator-=(Size depl)
Calls depl times Instantiation::dec().
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.
void setLastIn(const Instantiation &i)
Assign the last values in the Instantiation for the variables in i.
void incNotVar(const DiscreteVariable &v)
Operator increment for vars which are not v.
virtual bool empty() const final
Returns true if the instantiation is empty.
bool _overflow_
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
void _reorder_(const Sequence< const DiscreteVariable * > &v)
Reorder vars of this instantiation giving the order in v.
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
Size domainSize() const final
Returns the product of the variable's domain size in the Instantiation.
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
Instantiation()
Default constructor: creates an empty tuple.
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
void setFirstVar(const DiscreteVariable &v)
Assign the first value in the Instantiation for var v.
bool rend() const
Returns true if the Instantiation reached the rend.
void inc()
Operator increment.
MultiDimAdressable * _master_
The master, if any, contains precisely the set of variables to be instantiated.
void dec()
Operator decrement.
void erase(const DiscreteVariable &v) final
Removes a variable from the Instantiation.
bool isSlave() const
Indicates whether the Instantiation has a master.
void addWithMaster(const MultiDimAdressable *m, const DiscreteVariable &v)
Call Instantiation:: add(const DiscreteVariable&) by master.
void setLastNotVar(const DiscreteVariable &v)
Assign the last values to variables different of v.
void _erase_(const DiscreteVariable &v)
Removes a variable from the sequence of vars.
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::inc().
void _masterLastNotification_() const
void _swap_(Idx i, Idx j)
Swap two variables in the Instantiation.
bool inOverflow() const
Indicates whether the current value of the tuple is correct or not.
void _add_(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
void _masterDecNotification_() const
Idx val(Idx i) const
Returns the current value of the variable at position i.
void setFirst()
Assign the first values to the tuple of the Instantiation.
void _masterChangeNotification_(Idx varPos, Idx newVal, Idx oldVal) const
void setFirstOut(const Instantiation &i)
Assign the first values in the Instantiation for the variables not in i.
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
void unsetEnd()
Alias for unsetOverflow().
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Instantiation & operator++()
Alias of Instantiation::inc().
bool operator==(const Instantiation &other) const
operator==
void setLastVar(const DiscreteVariable &v)
Assign the last value in the Instantiation for var v.
void unsetOverflow()
Removes the flag overflow.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y) final
Replace x by y.
void setLast()
Assign the last values in the Instantiation.
Exception: at least one argument passed to a function is not what was expected.
Abstract base class for all multi dimensionnal addressable.
Exception : the element we looked for cannot be found.
Exception : operation not allowed.
Exception : out of bound.
Size size() const noexcept
Returns the size of the sequence.
const Key & atPos(Idx i) const
Returns the object at the pos i.
The generic class for storing (ordered) sequences of objects.
Definition sequence.h:972
const std::string & name() const
returns the name of the variable
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Headers for the abstract base class for all multi dimensionnal containers.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46