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