45#ifndef DOXYGEN_SHOULD_SKIP_THIS
76 auto pPos =
_vars_.tryPos(&v);
78 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v.name())
82 if (newVal >= v.domainSize())
GUM_ERROR(OutOfBounds,
"")
93 auto pPos =
_vars_.tryPos(v);
95 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v->name())
99 if (newVal >= v->domainSize())
GUM_ERROR(OutOfBounds,
"")
141 auto pPos =
_vars_.tryPos(&v);
143 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v.name())
147 if (newVals >= (
Size)1 << v.domainSize())
GUM_ERROR(OutOfBounds,
"")
158 auto pPos =
_vars_.tryPos(v);
160 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v->name())
164 if (newVals >= (
Size)1 << v->domainSize())
GUM_ERROR(OutOfBounds,
"")
201 auto pPos =
_vars_.tryPos(v);
203 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v->name())
207 if (newVal >= v->domainSize())
GUM_ERROR(OutOfBounds,
"")
218 auto pPos =
_vars_.tryPos(&v);
220 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v.name())
224 if (newVal >= v.domainSize())
GUM_ERROR(OutOfBounds,
"")
244 auto pPos =
_vars_.tryPos(v);
246 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v->name())
258 auto pPos =
_vars_.tryPos(&v);
260 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v.name())
284 auto pPos =
_vars_.tryPos(v);
286 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v->name())
290 if (newVal >= v->domainSize())
GUM_ERROR(OutOfBounds,
"")
298 auto pPos =
_vars_.tryPos(&v);
300 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v.name())
304 if (newVal >= v.domainSize())
GUM_ERROR(OutOfBounds,
"")
324 auto pPos =
_vars_.tryPos(v);
326 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v->name())
338 auto pPos =
_vars_.tryPos(&v);
340 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v.name())
373 auto pPos =
_vars_.tryPos(v);
375 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v->name())
387 auto pPos =
_vars_.tryPos(&v);
389 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v.name())
413 auto pPos =
_vars_.tryPos(v);
415 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v->name())
419 if (newVal >= v->domainSize())
GUM_ERROR(OutOfBounds,
"")
427 auto pPos =
_vars_.tryPos(&v);
429 GUM_ERROR(NotFound,
"SetInst does not contain this DiscreteVariable: " + v.name())
433 if (newVal >= v.domainSize())
GUM_ERROR(OutOfBounds,
"")
452 GUM_ERROR(DuplicateElement,
"Variable '" << v.name() <<
"' already exists in this SetInst")
465 if (!
_vars_.exists(&v))
GUM_ERROR(NotFound,
"Var does not exist in this SetInst")
485 for (
const auto var:
_vars_)
486 s *= var->domainSize();
501 INLINE SetInst::~SetInst() {
502 GUM_DESTRUCTOR(SetInst);
510 INLINE Idx SetInst::nbrDim()
const {
return _vars_.size(); }
514 INLINE Size SetInst::vals(Idx i)
const {
520 INLINE Size SetInst::vals(const DiscreteVariable& var)
const {
return _vals_[_vars_.pos(&var)]; }
522 INLINE Size SetInst::vals(
const DiscreteVariable* var)
const {
return _vals_[_vars_.pos(var)]; }
524 INLINE Idx SetInst::nbrOccurences(
const DiscreteVariable& var)
const {
526 Size val = _vals_[_vars_.pos(&var)];
536 INLINE Idx SetInst::val(
const DiscreteVariable& var)
const {
538 Size value = _vals_[_vars_.pos(&var)];
540 if (nbrOccurences(var) == 1) {
550 INLINE Idx SetInst::val(
const DiscreteVariable* var)
const {
551 if (var !=
nullptr) {
return val(*var); }
557 INLINE
const DiscreteVariable& SetInst::variable(Idx i)
const {
return *(_vars_.atPos(i)); }
561 INLINE
bool SetInst::inOverflow()
const {
return _overflow_; }
565 INLINE
bool SetInst::end()
const {
return inOverflow(); }
569 INLINE
bool SetInst::rend()
const {
return inOverflow(); }
574 INLINE
void SetInst::unsetOverflow() { _overflow_ =
false; }
578 INLINE
void SetInst::unsetEnd() { _overflow_ =
false; }
581 INLINE
void SetInst::reorder(
const SetInst& i) { reorder(i.variablesSequence()); }
585 INLINE SetInst& SetInst::chgValIn(
const SetInst& i) {
589 for (Size p = 0; p < s; ++p)
592 _chgVals_(pos(i.variable(p)), i.vals(i.variable(p)));
599 INLINE
const Sequence< const DiscreteVariable* >& SetInst::variablesSequence()
const {
605 INLINE
void SetInst::_swap_(Idx i, Idx j) {
614 _vals_[i] = _vals_[j];
621 INLINE
void SetInst::reorder(
const Sequence< const DiscreteVariable* >& original) {
622 Idx max = original.size();
625 for (Idx i = 0; i < max; ++i) {
626 const DiscreteVariable* pv = original.atPos(i);
629 GUM_ASSERT(pos(*pv) >= position);
631 _swap_(position, pos(*pv));
639 INLINE
void SetInst::_add_(
const DiscreteVariable& v) {
647 INLINE
void SetInst::_erase_(
const DiscreteVariable& v) {
649 Idx pos = _vars_.pos(&v);
651 _vals_.erase(_vals_.begin() + pos);
655 INLINE
bool SetInst::empty()
const {
return _vals_.empty(); }
658 INLINE
void SetInst::replace_(
const DiscreteVariable* x,
const DiscreteVariable* y) {
659 _vars_.setAtPos(_vars_.pos(x), y);
Exception base for argument error.
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.
bool contains(std::string_view s, std::string_view needle)
true if needle in s
Headers for the abstract base class for all multi dimensionnal containers.
gum is the global namespace for all aGrUM entities