aGrUM  0.14.2
setInst_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  ***************************************************************************/
20 #ifndef DOXYGEN_SHOULD_SKIP_THIS
21 
23 
24 // to ease IDE PARSER
25 # include <agrum/multidim/setInst.h>
26 
27 namespace gum {
28 
29  // indicates whether a given variable belongs to the SetInst
30 
31  INLINE bool SetInst::contains(const DiscreteVariable& v) const {
32  return __vars.exists(&v);
33  }
34 
35  // indicates whether a given variable belongs to the SetInst
36 
37  INLINE bool SetInst::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 
43  INLINE void SetInst::__chgVal(Idx varPos, Idx newVal) {
44  // Size oldVal = __vals[varPos];
45  __vals[varPos] = Idx(1) << newVal;
46 
47  // if ( __master )
48  // __master->changeNotification( *this, __vars[varPos], oldVal, newVal
49  // );
50  }
51 
52  // modifies the value of a given variable of the sequence (external function)
53 
54  INLINE SetInst& SetInst::chgVal(const DiscreteVariable& v, Idx newVal) {
55  try {
56  // check that the variable does belong to the SetInst and that the new
57  // value is possible.
58  Idx varPos = __vars.pos(&v); // throws NotFound if v doesn't belong to this
59 
60  if (newVal >= v.domainSize()) GUM_ERROR(OutOfBounds, "");
61 
62  // if we were in overflow, indicate that we are not anymore
63  __overflow = false;
64 
65  __chgVal(varPos, newVal);
66 
67  return *this;
68  } catch (NotFound&) {
69  std::string name = "SetInst does not contain this DiscreteVariable: ";
70  GUM_ERROR(NotFound, name + v.name());
71  }
72  }
73 
74  INLINE SetInst& SetInst::chgVal(const DiscreteVariable* v, Idx newVal) {
75  try {
76  // check that the variable does belong to the SetInst and that the 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 = "SetInst 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 
96  INLINE SetInst& SetInst::chgVal(Idx varPos, Idx newVal) {
97  // check that the variable does belong to the SetInst and that the new
98  // value is possible.
99  if (__vals.size() <= varPos) GUM_ERROR(NotFound, "");
100 
101  if (newVal >= __vars[varPos]->domainSize()) GUM_ERROR(OutOfBounds, "");
102 
103  // if we were in overflow, indicate that we are not anymore
104  __overflow = false;
105 
106  __chgVal(varPos, newVal);
107 
108  return *this;
109  }
110 
111  // modifies internally the value of a given variable of the sequence
112 
113  INLINE void SetInst::__chgVals(Idx varPos, const Size newVals) {
114  // Size oldVal = __vals[varPos];
115  __vals[varPos] = 0;
116  __vals[varPos] = newVals;
117 
118  // if ( __master )
119  // __master->changeNotification( *this, __vars[varPos], oldVal, newVals
120  // );
121  }
122 
123  // modifies the value of a given variable of the sequence (external function)
124 
125  INLINE SetInst& SetInst::chgVals(const DiscreteVariable& v, const Size newVals) {
126  try {
127  // check that the variable does belong to the SetInst and that the new
128  // value is possible.
129  Idx varPos = __vars.pos(&v); // throws NotFound if v doesn't belong to this
130 
131  if (newVals >= (Size)1 << v.domainSize()) GUM_ERROR(OutOfBounds, "");
132 
133  // if we were in overflow, indicate that we are not anymore
134  __overflow = false;
135 
136  __chgVals(varPos, newVals);
137 
138  return *this;
139  } catch (NotFound&) {
140  std::string name = "SetInst does not contain this DiscreteVariable: ";
141  GUM_ERROR(NotFound, name + v.name());
142  }
143  }
144 
145  INLINE SetInst& SetInst::chgVals(const DiscreteVariable* v, const Size newVals) {
146  try {
147  // check that the variable does belong to the SetInst and that the new
148  // value is possible.
149  Idx varPos = __vars.pos(v); // throws NotFound if v doesn't belong to this
150 
151  if (newVals >= (Size)1 << v->domainSize()) GUM_ERROR(OutOfBounds, "");
152 
153  // if we were in overflow, indicate that we are not anymore
154  __overflow = false;
155 
156  __chgVals(varPos, newVals);
157 
158  return *this;
159  } catch (NotFound&) {
160  std::string name = "SetInst does not contain this DiscreteVariable: ";
161  GUM_ERROR(NotFound, name + v->name());
162  }
163  }
164 
165  // modifies the value of a given variable of the sequence (external function)
166 
167  INLINE SetInst& SetInst::chgVals(Idx varPos, const Size newVal) {
168  // check that the variable does belong to the SetInst and that the new
169  // value is possible.
170  if (__vals.size() <= varPos) GUM_ERROR(NotFound, "");
171 
172  if (newVal >= (Size)1 << __vars[varPos]->domainSize())
173 
174  GUM_ERROR(OutOfBounds, "");
175 
176  // if we were in overflow, indicate that we are not anymore
177  __overflow = false;
178 
179  __chgVals(varPos, newVal);
180 
181  return *this;
182  }
183 
184  INLINE SetInst& SetInst::addVal(Idx varPos, Idx newVal) {
185  if (__vals.size() <= varPos) GUM_ERROR(NotFound, "");
186 
187  if (newVal >= __vars[varPos]->domainSize()) GUM_ERROR(OutOfBounds, "");
188 
189  __chgVals(varPos, (Idx(1) << newVal) | __vals[varPos]);
190  return *this;
191  }
192 
193  INLINE SetInst& SetInst::addVal(const DiscreteVariable* v, Idx newVal) {
194  try {
195  // check that the variable does belong to the SetInst and that the new
196  // value is possible.
197  Idx varPos = __vars.pos(v); // throws NotFound if v doesn't belong to this
198 
199  if (newVal >= v->domainSize()) GUM_ERROR(OutOfBounds, "");
200 
201  // if we were in overflow, indicate that we are not anymore
202  __overflow = false;
203 
204  addVal(varPos, newVal);
205 
206  return *this;
207  } catch (NotFound&) {
208  std::string name = "SetInst does not contain this DiscreteVariable: ";
209  GUM_ERROR(NotFound, name + v->name());
210  }
211  }
212 
213  INLINE SetInst& SetInst::addVal(const DiscreteVariable& v, Idx newVal) {
214  try {
215  // check that the variable does belong to the SetInst and that the new
216  // value is possible.
217  Idx varPos = __vars.pos(&v); // throws NotFound if v doesn't belong to this
218 
219  if (newVal >= v.domainSize()) GUM_ERROR(OutOfBounds, "");
220 
221  // if we were in overflow, indicate that we are not anymore
222  __overflow = false;
223 
224  addVal(varPos, newVal);
225 
226  return *this;
227  } catch (NotFound&) {
228  std::string name = "SetInst does not contain this DiscreteVariable: ";
229  GUM_ERROR(NotFound, name + v.name());
230  }
231  }
232 
233  INLINE SetInst& SetInst::addVals(Idx varPos, const Size newVal) {
234  if (__vals.size() <= varPos) GUM_ERROR(NotFound, "");
235 
236  if (newVal >= (Size(1) << __vars[varPos]->domainSize()))
237  GUM_ERROR(OutOfBounds, "");
238 
239  __chgVals(varPos, newVal | __vals[varPos]);
240  return *this;
241  }
242 
243  INLINE SetInst& SetInst::addVals(const DiscreteVariable* v, const Size newVal) {
244  try {
245  // check that the variable does belong to the SetInst and that the new
246  // value is possible.
247  Idx varPos = __vars.pos(v); // throws NotFound if v doesn't belong to this
248 
249  if (newVal >= (Size(1) << __vars[varPos]->domainSize()))
250 
251  GUM_ERROR(OutOfBounds, "");
252 
253  // if we were in overflow, indicate that we are not anymore
254 
255  addVals(varPos, newVal);
256 
257  return *this;
258  } catch (NotFound&) {
259  std::string name = "SetInst does not contain this DiscreteVariable: ";
260  GUM_ERROR(NotFound, name + v->name());
261  }
262  }
263 
264  INLINE SetInst& SetInst::addVals(const DiscreteVariable& v, const Size newVal) {
265  try {
266  // check that the variable does belong to the SetInst and that the new
267  // value is possible.
268  Idx varPos = __vars.pos(&v); // throws NotFound if v doesn't belong to this
269 
270  if (newVal >= (Size(1) << __vars[varPos]->domainSize()))
271 
272  GUM_ERROR(OutOfBounds, "");
273 
274  // if we were in overflow, indicate that we are not anymore
275  __overflow = false;
276 
277  addVals(varPos, newVal);
278 
279  return *this;
280  } catch (NotFound&) {
281  std::string name = "SetInst does not contain this DiscreteVariable: ";
282  GUM_ERROR(NotFound, name + v.name());
283  }
284  }
285 
286  INLINE SetInst& SetInst::remVal(Idx varPos, Idx newVal) {
287  if (__vals.size() <= varPos) GUM_ERROR(NotFound, "");
288 
289  if (newVal >= __vars[varPos]->domainSize()) GUM_ERROR(OutOfBounds, "");
290 
291  __chgVals(varPos, ~(1 << newVal) & __vals[varPos]);
292  return *this;
293  }
294 
295  INLINE SetInst& SetInst::remVal(const DiscreteVariable* v, Idx newVal) {
296  try {
297  // check that the variable does belong to the SetInst and that the new
298  // value is possible.
299  Idx varPos = __vars.pos(v); // throws NotFound if v doesn't belong to this
300 
301  if (newVal >= v->domainSize()) GUM_ERROR(OutOfBounds, "");
302 
303  // if we were in overflow, indicate that we are not anymore
304 
305  remVal(varPos, newVal);
306 
307  return *this;
308  } catch (NotFound&) {
309  std::string name = "SetInst does not contain this DiscreteVariable: ";
310  GUM_ERROR(NotFound, name + v->name());
311  }
312  }
313 
314  INLINE SetInst& SetInst::remVal(const DiscreteVariable& v, Idx newVal) {
315  try {
316  // check that the variable does belong to the SetInst and that the new
317  // value is possible.
318  Idx varPos = __vars.pos(&v); // throws NotFound if v doesn't belong to this
319 
320  if (newVal >= v.domainSize()) GUM_ERROR(OutOfBounds, "");
321 
322  // if we were in overflow, indicate that we are not anymore
323  __overflow = false;
324 
325  remVal(varPos, newVal);
326 
327  return *this;
328  } catch (NotFound&) {
329  std::string name = "SetInst does not contain this DiscreteVariable: ";
330  GUM_ERROR(NotFound, name + v.name());
331  }
332  }
333 
334  INLINE SetInst& SetInst::remVals(Idx varPos, const Size newVal) {
335  if (__vals.size() <= varPos) GUM_ERROR(NotFound, "");
336 
337  if (newVal >= (Size(1) << __vars[varPos]->domainSize()))
338  GUM_ERROR(OutOfBounds, "");
339 
340  __chgVals(varPos, ~newVal & __vals[varPos]);
341  return *this;
342  }
343 
344  INLINE SetInst& SetInst::remVals(const DiscreteVariable* v, const Size newVal) {
345  try {
346  // check that the variable does belong to the SetInst and that the new
347  // value is possible.
348  Idx varPos = __vars.pos(v); // throws NotFound if v doesn't belong to this
349 
350  if (newVal >= (Size(1) << __vars[varPos]->domainSize()))
351 
352  GUM_ERROR(OutOfBounds, "");
353 
354  // if we were in overflow, indicate that we are not anymore
355 
356  remVals(varPos, newVal);
357 
358  return *this;
359  } catch (NotFound&) {
360  std::string name = "SetInst does not contain this DiscreteVariable: ";
361  GUM_ERROR(NotFound, name + v->name());
362  }
363  }
364 
365  INLINE SetInst& SetInst::remVals(const DiscreteVariable& v, const Size newVal) {
366  try {
367  // check that the variable does belong to the SetInst and that the new
368  // value is possible.
369  Idx varPos = __vars.pos(&v); // throws NotFound if v doesn't belong to this
370 
371  if (newVal >= (Size(1) << __vars[varPos]->domainSize()))
372 
373  GUM_ERROR(OutOfBounds, "");
374 
375  // if we were in overflow, indicate that we are not anymore
376  __overflow = false;
377 
378  remVals(varPos, newVal);
379 
380  return *this;
381  } catch (NotFound&) {
382  std::string name = "SetInst does not contain this DiscreteVariable: ";
383  GUM_ERROR(NotFound, name + v.name());
384  }
385  }
386 
387  INLINE SetInst& SetInst::chgDifVal(Idx varPos, const Size newVal) {
388  if (__vals.size() <= varPos) GUM_ERROR(NotFound, "");
389 
390  if (newVal >= __vars[varPos]->domainSize()) GUM_ERROR(OutOfBounds, "");
391 
392  __chgVals(varPos, newVal ^ __vals[varPos]);
393  return *this;
394  }
395 
396  INLINE SetInst& SetInst::interVals(Idx varPos, const Size newVal) {
397  if (__vals.size() <= varPos) GUM_ERROR(NotFound, "");
398 
399  if (newVal >= (Size(1) << __vars[varPos]->domainSize()))
400  GUM_ERROR(OutOfBounds, "");
401 
402  __chgVals(varPos, newVal & __vals[varPos]);
403  return *this;
404  }
405 
406  INLINE SetInst& SetInst::interVals(const DiscreteVariable* v,
407  const Size newVal) {
408  try {
409  // check that the variable does belong to the SetInst and that the new
410  // value is possible.
411  Idx varPos = __vars.pos(v); // throws NotFound if v doesn't belong to this
412 
413  if (newVal >= (Size(1) << __vars[varPos]->domainSize()))
414 
415  GUM_ERROR(OutOfBounds, "");
416 
417  // if we were in overflow, indicate that we are not anymore
418 
419  interVals(varPos, newVal);
420 
421  return *this;
422  } catch (NotFound&) {
423  std::string name = "SetInst does not contain this DiscreteVariable: ";
424  GUM_ERROR(NotFound, name + v->name());
425  }
426  }
427 
428  INLINE SetInst& SetInst::interVals(const DiscreteVariable& v,
429  const Size newVal) {
430  try {
431  // check that the variable does belong to the SetInst and that the new
432  // value is possible.
433  Idx varPos = __vars.pos(&v); // throws NotFound if v doesn't belong to this
434 
435  if (newVal >= (Size(1) << __vars[varPos]->domainSize()))
436 
437  GUM_ERROR(OutOfBounds, "");
438 
439  // if we were in overflow, indicate that we are not anymore
440  __overflow = false;
441 
442  interVals(varPos, newVal);
443 
444  return *this;
445  } catch (NotFound&) {
446  std::string name = "SetInst does not contain this DiscreteVariable: ";
447  GUM_ERROR(NotFound, name + v.name());
448  }
449  }
450 
451  INLINE SetInst& SetInst::interVal(Idx varPos, Idx newVal) {
452  if (__vals.size() <= varPos) GUM_ERROR(NotFound, "");
453 
454  if (newVal >= __vars[varPos]->domainSize()) GUM_ERROR(OutOfBounds, "");
455 
456  __chgVals(varPos, (Size(1) << newVal) & __vals[varPos]);
457  return *this;
458  }
459 
460  INLINE SetInst& SetInst::interVal(const DiscreteVariable* v, Idx newVal) {
461  try {
462  // check that the variable does belong to the SetInst and that the new
463  // value is possible.
464  Idx varPos = __vars.pos(v); // throws NotFound if v doesn't belong to this
465 
466  if (newVal >= v->domainSize()) GUM_ERROR(OutOfBounds, "");
467 
468  // if we were in overflow, indicate that we are not anymore
469 
470  interVal(varPos, newVal);
471 
472  return *this;
473  } catch (NotFound&) {
474  std::string name = "SetInst does not contain this DiscreteVariable: ";
475  GUM_ERROR(NotFound, name + v->name());
476  }
477  }
478 
479  INLINE SetInst& SetInst::interVal(const DiscreteVariable& v, Idx newVal) {
480  try {
481  // check that the variable does belong to the SetInst and that the new
482  // value is possible.
483  Idx varPos = __vars.pos(&v); // throws NotFound if v doesn't belong to this
484 
485  if (newVal >= v.domainSize()) GUM_ERROR(OutOfBounds, "");
486 
487  // if we were in overflow, indicate that we are not anymore
488  __overflow = false;
489 
490  interVal(varPos, newVal);
491 
492  return *this;
493  } catch (NotFound&) {
494  std::string name = "SetInst does not contain this DiscreteVariable: ";
495  GUM_ERROR(NotFound, name + v.name());
496  }
497  }
498 
499  // adds a new var to the sequence of vars
500 
501  INLINE void SetInst::add(const DiscreteVariable& v) {
502  // if __master : not allowed
503  // if ( __master ) GUM_ERROR( OperationNotAllowed, "in slave SetInst" );
504 
505  // check if the variable already belongs to the tuple of variables
506  // of the SetInst
507  if (__vars.exists(&v))
508  GUM_ERROR(DuplicateElement,
509  "Variable '" << v.name() << "' already exists in this SetInst");
510 
511  // actually add the new dimension
512  __add(v);
513  }
514 
515  // removes a variable from the sequence of vars
516 
517  INLINE void SetInst::erase(const DiscreteVariable& v) {
518  // if __master : not allowed
519  // if ( __master ) GUM_ERROR( OperationNotAllowed, "in slave SetInst" );
520 
521  // check that the variable does actually belong to the SetInst
522  if (!__vars.exists(&v))
523  GUM_ERROR(NotFound, "Var does not exist in this SetInst");
524 
525  // actually delete the dimension
526  __erase(v);
527  }
528 
529  // removes everything
530  INLINE void SetInst::clear() {
531  // if ( __master ) GUM_ERROR( OperationNotAllowed, "in slave SetInst" );
532 
533  __vars.clear();
534  __vals.clear();
535  }
536 
540  INLINE Size SetInst::domainSize() const {
541  // @todo enhance the cplxity with a member domainSize ?
542  Size s = 1;
543 
544  for (const auto var : __vars)
545  s *= var->domainSize();
546 
547  return s;
548  }
549 
550  // returns the index of a var
551 
552  INLINE Idx SetInst::pos(const DiscreteVariable& k) const {
553  return __vars.pos(&k);
554  }
555 
556  // Default constructor
557 
558  INLINE SetInst::SetInst() : /*__master( 0 ),*/ __overflow(false) {
559  GUM_CONSTRUCTOR(SetInst);
560  }
561 
562  // destructor
563 
564  INLINE SetInst::~SetInst() {
565  GUM_DESTRUCTOR(SetInst);
566  // unregister the SetInst from its __master
567 
568  // if ( __master ) __master->unregisterSlave( *this );
569  }
570 
571  // returns the number of vars in the sequence
572 
573  INLINE Idx SetInst::nbrDim() const { return __vars.size(); }
574 
575  // returns the current value of a given variable
576 
577  INLINE Size SetInst::vals(Idx i) const {
578  if (i >= __vals.size()) GUM_ERROR(NotFound, "");
579 
580  return __vals[i];
581  }
582 
583  // returns the current value of a given variable
584  // need to create functions TODO
585 
586  INLINE Size SetInst::vals(const DiscreteVariable& var) const {
587  return __vals[__vars.pos(&var)];
588  }
589 
590  // returns the current value of a given variable
591 
592  INLINE Size SetInst::vals(const DiscreteVariable* var) const {
593  return __vals[__vars.pos(var)];
594  }
595 
596  INLINE Idx SetInst::val(const DiscreteVariable* var) const {
597  Idx n = 0;
598  Size value = __vals[__vars.pos(var)];
599 
600  if (__vals[__vars.pos(var)] % 2 == 0) {
601  while (value & 1) {
602  n++;
603  value >>= 1;
604  }
605 
606  return n;
607  } else
608  GUM_ERROR(NotFound, "There is more than one value ");
609  }
610 
611  INLINE Idx SetInst::nbrOccurences(const DiscreteVariable& var) const {
612  Idx n = 0;
613  Size val = __vals[__vars.pos(&var)];
614 
615  while (val) {
616  n += (val & 1);
617  val >>= 1;
618  }
619 
620  return n;
621  }
622 
623  INLINE Idx SetInst::val(const DiscreteVariable& var) const {
624  Idx n = 0;
625  Size value = __vals[__vars.pos(&var)];
626 
627  if (nbrOccurences(var) == 1) {
628  while (value > 1) {
629  n++;
630  value >>= 1;
631  }
632 
633  return n;
634  } else
635  GUM_ERROR(NotFound, "There is more than one value ");
636  }
637 
638  // returns the variable at position i in the tuple
639 
640  INLINE const DiscreteVariable& SetInst::variable(Idx i) const {
641  return *(__vars.atPos(i));
642  }
643 
644  // indicates whether the current value of the tuple is correct or not
645 
646  INLINE bool SetInst::inOverflow() const { return __overflow; }
647 
648  // end() just is a synonym for inOverflow()
649 
650  INLINE bool SetInst::end() const { return inOverflow(); }
651 
652  // rend() just is a synonym for inOverflow()
653 
654  INLINE bool SetInst::rend() const { return inOverflow(); }
655 
656  // indicates that the current value is correct even if it should be in
657  // overflow
658 
659  INLINE void SetInst::unsetOverflow() { __overflow = false; }
660 
661  // alias for unsetOverflow
662 
663  INLINE void SetInst::unsetEnd() { __overflow = false; }
664 
665  // reorder vars in *this
666  INLINE void SetInst::reorder(const SetInst& i) {
667  reorder(i.variablesSequence());
668  }
669 
670  // change values with those in i
671 
672  INLINE SetInst& SetInst::chgValIn(const SetInst& i) {
673  __overflow = false;
674  Idx s = i.nbrDim();
675 
676  for (Size p = 0; p < s; ++p)
677  if (contains(i.variable(p)))
678  //__vals[pos( i.variable( p ) )] = i.val( p );
679  __chgVals(pos(i.variable(p)), i.vals(i.variable(p)));
680 
681  return *this;
682  }
683 
684  // returns the sequence of DiscreteVariable
685 
686  INLINE const Sequence< const DiscreteVariable* >&
688  return __vars;
689  }
690 
691  // replace 2 vars in the SetInst
692 
693  INLINE void SetInst::__swap(Idx i, Idx j) {
694  if (i == j) return;
695 
696  __vars.swap(i, j);
697 
698  Size v;
699 
700  v = __vals[i];
701 
702  __vals[i] = __vals[j];
703 
704  __vals[j] = v;
705  }
706 
707  // reordering
708 
709  INLINE void
710  SetInst::reorder(const Sequence< const DiscreteVariable* >& original) {
711  Idx max = original.size();
712  Idx position = 0;
713 
714  for (Idx i = 0; i < max; ++i) {
715  const DiscreteVariable* pv = original.atPos(i);
716 
717  if (contains(pv)) {
718  GUM_ASSERT(pos(*pv) >= position); // this var should not be
719  // already placed.
720  __swap(position, pos(*pv));
721  position++;
722  }
723  }
724  }
725 
726  // adds a new var to the sequence of vars
727 
728  INLINE void SetInst::__add(const DiscreteVariable& v) {
729  __vars.insert(&v);
730  __vals.push_back(1);
731  __overflow = false;
732  }
733 
734  // removes a variable from the sequence of vars
735 
736  INLINE void SetInst::__erase(const DiscreteVariable& v) {
737  // get the position of the variable
738  Idx pos = __vars.pos(&v);
739  __vars.erase(&v);
740  __vals.erase(__vals.begin() + pos);
741  }
742 
743  // is this empty ?
744  INLINE bool SetInst::empty() const { return __vals.empty(); }
745 
746  // Replace x by y.
747  INLINE void SetInst::_replace(const DiscreteVariable* x,
748  const DiscreteVariable* y) {
749  __vars.setAtPos(__vars.pos(x), y);
750  }
751 } /* namespace gum */
752 
753 #endif // DOXYGEN_SHOULD_SKIP_THIS
const DiscreteVariable & variable(Idx i) const
Returns the variable at position i in the tuple.
void __chgVal(Idx varPos, Idx newVal)
Change the value of a variable.
Idx nbrDim() const
Returns the number of variables in the SetInst.
void clear()
Erase all variables from an SetInst.
void __erase(const DiscreteVariable &v)
Removes a variable from the sequence of vars.
Size domainSize() const
Returns the product of the variable&#39;s domain size in the SetInst.
virtual bool empty() const
Returns true if the SetInst is empty.
SetInst & chgVal(const DiscreteVariable &v, Idx newVal)
Assign newVal to variable v in the SetInst.
void add(const DiscreteVariable &v)
Adds a new variable in the SetInst.
SetInst & remVal(const DiscreteVariable &v, Idx newVal)
Remove newVal from the variable v in the SetInst.
bool end() const
Returns true if the SetInst reached the end.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
bool rend() const
Returns true if the SetInst reached the rend.
bool contains(const DiscreteVariable &v) const
Indicates whether a given variable belongs to the SetInst.
const Sequence< const DiscreteVariable *> & variablesSequence() const
Returns the sequence of DiscreteVariable of this SetInst.
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y)
void __swap(Idx i, Idx j)
Swap 2 vars in the SetInst.
void __add(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
SetInst & interVal(const DiscreteVariable &v, Idx newVal)
Does an intersection (binary and) between the old value and new value.
void unsetOverflow()
Removes the flag overflow.
std::vector< Size > __vals
The current SetInst: the value of the tuple.
Definition: setInst.h:846
bool __overflow
The overflow flag.
Definition: setInst.h:849
SetInst & remVals(const DiscreteVariable &v, const Size newVal)
Remove newVal from the variable v in the SetInst.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
Definition: setInst.h:843
void erase(const DiscreteVariable &v)
Removes a variable from the SetInst.
Idx pos(const DiscreteVariable &v) const
Returns the position of the variable v.
SetInst & chgVals(const DiscreteVariable &v, const Size newVal)
Assign newVal to variable v in the SetInst.
Idx nbrOccurences(const DiscreteVariable &var) const
Returns the current value of the variable at position i.
Size vals(Idx i) const
Returns the current value of the variable at position i.
SetInst & chgDifVal(Idx varPos, const Size newVal)
Does the difference (binary or) between the old value and new value.
void unsetEnd()
Alias for unsetOverflow().
SetInst & addVal(const DiscreteVariable &v, Idx newVal)
Add newVal to variable v in the SetInst.
SetInst()
Default constructor: creates an empty tuple.
Size Idx
Type for indexes.
Definition: types.h:50
bool inOverflow() const
Indicates whether the current value of the tuple is correct or not.
Idx val(Idx i) const
Returns the current value of a variable at a given position.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
SetInst & interVals(const DiscreteVariable &v, const Size newVal)
Does an intersection (binary and) between the old value and new value.
SetInst & chgValIn(const SetInst &i)
Change all the values to match does in i.
SetInst & addVals(const DiscreteVariable &v, const Size newVal)
Add newVal to variable v in the SetInst.
Headers for the abstract base class for all multi dimensionnal containers.
void __chgVals(Idx varPos, const Size newVal)
Change the value of a variable.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
Headers of SetInst.
~SetInst()
Class destructor.
void reorder(const Sequence< const DiscreteVariable * > &v)
Reorder the variables given v.