43#ifndef DOXYGEN_SHOULD_SKIP_THIS
79 if (newVal >= v.domainSize())
GUM_ERROR(OutOfBounds,
"")
87 } catch (NotFound const&) {
88 std::string name =
"SetInst does not contain this DiscreteVariable: ";
99 if (newVal >= v->domainSize())
GUM_ERROR(OutOfBounds,
"")
107 } catch (NotFound const&) {
108 std::string name =
"SetInst does not contain this DiscreteVariable: ";
150 if (newVals >= (
Size)1 << v.domainSize())
GUM_ERROR(OutOfBounds,
"")
158 } catch (NotFound const&) {
159 std::string name =
"SetInst does not contain this DiscreteVariable: ";
170 if (newVals >= (
Size)1 << v->domainSize())
GUM_ERROR(OutOfBounds,
"")
178 } catch (NotFound const&) {
179 std::string name =
"SetInst does not contain this DiscreteVariable: ";
216 if (newVal >= v->domainSize())
GUM_ERROR(OutOfBounds,
"")
224 } catch (NotFound const&) {
225 std::string name =
"SetInst does not contain this DiscreteVariable: ";
236 if (newVal >= v.domainSize())
GUM_ERROR(OutOfBounds,
"")
244 } catch (NotFound const&) {
245 std::string name =
"SetInst does not contain this DiscreteVariable: ";
272 } catch (NotFound const&) {
273 std::string name =
"SetInst does not contain this DiscreteVariable: ";
292 } catch (NotFound const&) {
293 std::string name =
"SetInst does not contain this DiscreteVariable: ";
313 if (newVal >= v->domainSize())
GUM_ERROR(OutOfBounds,
"")
320 } catch (NotFound const&) {
321 std::string name =
"SetInst does not contain this DiscreteVariable: ";
332 if (newVal >= v.domainSize())
GUM_ERROR(OutOfBounds,
"")
340 } catch (NotFound const&) {
341 std::string name =
"SetInst does not contain this DiscreteVariable: ";
368 } catch (NotFound const&) {
369 std::string name =
"SetInst does not contain this DiscreteVariable: ";
388 } catch (NotFound const&) {
389 std::string name =
"SetInst does not contain this DiscreteVariable: ";
425 } catch (NotFound const&) {
426 std::string name =
"SetInst does not contain this DiscreteVariable: ";
445 } catch (NotFound const&) {
446 std::string name =
"SetInst does not contain this DiscreteVariable: ";
466 if (newVal >= v->domainSize())
GUM_ERROR(OutOfBounds,
"")
473 } catch (NotFound const&) {
474 std::string name =
"SetInst does not contain this DiscreteVariable: ";
485 if (newVal >= v.domainSize())
GUM_ERROR(OutOfBounds,
"")
493 } catch (NotFound const&) {
494 std::string name =
"SetInst does not contain this DiscreteVariable: ";
508 GUM_ERROR(DuplicateElement,
"Variable '" << v.name() <<
"' already exists in this SetInst")
521 if (!
_vars_.exists(&v))
GUM_ERROR(NotFound,
"Var does not exist in this SetInst")
541 for (
const auto var:
_vars_)
542 s *= var->domainSize();
557 INLINE SetInst::~SetInst() {
558 GUM_DESTRUCTOR(SetInst);
566 INLINE Idx SetInst::nbrDim()
const {
return _vars_.size(); }
570 INLINE Size SetInst::vals(Idx i)
const {
576 INLINE Size SetInst::vals(const DiscreteVariable& var)
const {
return _vals_[_vars_.pos(&var)]; }
578 INLINE Size SetInst::vals(
const DiscreteVariable* var)
const {
return _vals_[_vars_.pos(var)]; }
580 INLINE Idx SetInst::val(
const DiscreteVariable* var)
const {
582 Size value = _vals_[_vars_.pos(var)];
584 if (_vals_[_vars_.pos(var)] % 2 == 0) {
594 INLINE Idx SetInst::nbrOccurences(
const DiscreteVariable& var)
const {
596 Size val = _vals_[_vars_.pos(&var)];
606 INLINE Idx SetInst::val(
const DiscreteVariable& var)
const {
608 Size value = _vals_[_vars_.pos(&var)];
610 if (nbrOccurences(var) == 1) {
622 INLINE
const DiscreteVariable& SetInst::variable(Idx i)
const {
return *(_vars_.atPos(i)); }
626 INLINE
bool SetInst::inOverflow()
const {
return _overflow_; }
630 INLINE
bool SetInst::end()
const {
return inOverflow(); }
634 INLINE
bool SetInst::rend()
const {
return inOverflow(); }
639 INLINE
void SetInst::unsetOverflow() { _overflow_ =
false; }
643 INLINE
void SetInst::unsetEnd() { _overflow_ =
false; }
646 INLINE
void SetInst::reorder(
const SetInst& i) { reorder(i.variablesSequence()); }
650 INLINE SetInst& SetInst::chgValIn(
const SetInst& i) {
654 for (Size p = 0; p < s; ++p)
655 if (contains(i.variable(p)))
657 _chgVals_(pos(i.variable(p)), i.vals(i.variable(p)));
664 INLINE
const Sequence< const DiscreteVariable* >& SetInst::variablesSequence()
const {
670 INLINE
void SetInst::_swap_(Idx i, Idx j) {
679 _vals_[i] = _vals_[j];
686 INLINE
void SetInst::reorder(
const Sequence< const DiscreteVariable* >& original) {
687 Idx max = original.size();
690 for (Idx i = 0; i < max; ++i) {
691 const DiscreteVariable* pv = original.atPos(i);
694 GUM_ASSERT(pos(*pv) >= position);
696 _swap_(position, pos(*pv));
704 INLINE
void SetInst::_add_(
const DiscreteVariable& v) {
712 INLINE
void SetInst::_erase_(
const DiscreteVariable& v) {
714 Idx pos = _vars_.pos(&v);
716 _vals_.erase(_vals_.begin() + pos);
720 INLINE
bool SetInst::empty()
const {
return _vals_.empty(); }
723 INLINE
void SetInst::replace_(
const DiscreteVariable* x,
const DiscreteVariable* y) {
724 _vars_.setAtPos(_vars_.pos(x), y);
Base class for discrete random variable.
Exception : the element we looked for cannot be found.
Class for assigning/browsing values to tuples of discrete variables.
SetInst()
Default constructor: creates an empty tuple.
void _chgVal_(Idx varPos, Idx newVal)
Change the value of a variable.
Idx pos(const DiscreteVariable &v) const
Returns the position of the variable v.
void erase(const DiscreteVariable &v)
Removes a variable from the SetInst.
Sequence< const DiscreteVariable * > _vars_
The tuple of variables to be instantiated.
void _chgVals_(Idx varPos, const Size newVal)
Change the value of a variable.
SetInst & interVals(const DiscreteVariable &v, const Size newVal)
Does an intersection (binary and) between the old value and new value.
bool contains(const DiscreteVariable &v) const
Indicates whether a given variable belongs to the SetInst.
void _erase_(const DiscreteVariable &v)
Removes a variable from the sequence of vars.
SetInst & chgDifVal(Idx varPos, const Size newVal)
Does the difference (binary or) between the old value and new value.
SetInst & addVal(const DiscreteVariable &v, Idx newVal)
Add newVal to variable v in the SetInst.
void _add_(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
bool _overflow_
The overflow flag.
SetInst & remVals(const DiscreteVariable &v, const Size newVal)
Remove newVal from the variable v in the SetInst.
Size domainSize() const
Returns the product of the variable's domain size in the SetInst.
SetInst & interVal(const DiscreteVariable &v, Idx newVal)
Does an intersection (binary and) between the old value and new value.
SetInst & remVal(const DiscreteVariable &v, Idx newVal)
Remove newVal from the variable v in the SetInst.
void add(const DiscreteVariable &v)
Adds a new variable in the SetInst.
std::vector< Size > _vals_
The current SetInst: the value of the tuple.
SetInst & chgVal(const DiscreteVariable &v, Idx newVal)
Assign newVal to variable v in the SetInst.
void clear()
Erase all variables from an SetInst.
SetInst & chgVals(const DiscreteVariable &v, const Size newVal)
Assign newVal to variable v in the SetInst.
SetInst & addVals(const DiscreteVariable &v, const Size newVal)
Add newVal to variable v in the SetInst.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Headers for the abstract base class for all multi dimensionnal containers.
gum is the global namespace for all aGrUM entities