49#ifndef DOXYGEN_SHOULD_SKIP_THIS
55 const Sequence< const DiscreteVariable* >& v = master->variablesSequence();
60 for (
const auto var: v)
70 GUM_CONSTRUCTOR(SetInst);
74 SetInst::SetInst(
const MultiDimAdressable& d) : _overflow_(false) {
76 GUM_CONSTRUCTOR(SetInst);
77 _init_(
const_cast< MultiDimAdressable*
>(&d));
82 SetInst::SetInst(MultiDimAdressable* d) : _overflow_(false) {
84 GUM_CONSTRUCTOR(SetInst);
93 SetInst::SetInst(
const MultiDimAdressable* const_d) : _overflow_(false) {
95 GUM_CONSTRUCTOR(SetInst);
97 if (const_d) _init_(
const_cast< MultiDimAdressable*
>(const_d));
102 SetInst::SetInst(
const SetInst& aI) :
105 GUM_CONS_CPY(SetInst);
109 _overflow_ = aI._overflow_;
114 SetInst::SetInst(SetInst&& aI) noexcept :
115 _vars_(std::move(aI._vars_)), _vals_(std::move(aI._vals_)), _overflow_(aI._overflow_) {
116 GUM_CONS_MOV(SetInst);
119 SetInst::SetInst(
const Instantiation& aI) :
122 GUM_CONS_CPY(SetInst);
123 const Sequence< const DiscreteVariable* >& v = aI.variablesSequence();
124 _vars_.resize(v.size());
128 for (
const auto var: v) {
130 _vals_[_vars_.pos(var)] = (Size(1) << (aI.val(*var)));
135 SetInst& SetInst::operator=(
const SetInst& aI) {
139 _overflow_ = aI._overflow_;
146 SetInst& SetInst::operator=(SetInst&& aI)
noexcept {
147 _vars_ = std::move(aI._vars_);
148 _vals_ = std::move(aI._vals_);
149 _overflow_ = aI._overflow_;
156 std::string SetInst::toString()
const {
160 if (_overflow_) { result +=
"<invalid>"; }
164 Sequence< const DiscreteVariable* >::iterator_safe iter = _vars_.begin();
166 if (iter != _vars_.end()) {
167 Size si = variable(iter.pos()).domainSize();
168 Size valb = vals(iter.pos());
172 bits = std::string(1, (valb & 1) ?
'1' :
'0') + bits;
176 result += variable(iter.pos()).name() +
":" + bits;
179 while (iter != _vars_.end()) {
180 si = variable(iter.pos()).domainSize();
181 valb = vals(iter.pos());
185 bits = std::string(1, (valb & 1) ?
'1' :
'0') + bits;
189 result +=
"|" + variable(iter.pos()).name() +
":" + bits;
200 std::ostream&
operator<<(std::ostream& aStream,
const SetInst& i) {
201 aStream << i.toString();
222 }
catch (gum::NotFound&) {
223 GUM_ERROR(gum::NotFound,
"missing variable in bijection or SetInst")
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
Set of pairs of elements with fast search for both elements.
Base class for discrete random variable.
Abstract base class for all multi dimensionnal addressable.
Class for assigning/browsing values to tuples of discrete variables.
SetInst()
Default constructor: creates an empty tuple.
void erase(const DiscreteVariable &v)
Removes a variable from the SetInst.
Sequence< const DiscreteVariable * > _vars_
The tuple of variables to be instantiated.
static void assign_values(Bijection< const DiscreteVariable *, const DiscreteVariable * > &bij, const SetInst &i, SetInst &j)
Assign the values of i in j, using bij as a bijection between i and j variables.
const Sequence< const DiscreteVariable * > & variablesSequence() const
Returns the sequence of DiscreteVariable of this SetInst.
void _add_(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
Idx val(Idx i) const
Returns the current value of a variable at a given position.
void _init_(MultiDimAdressable *master)
Intialize 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.
#define GUM_ERROR(type, msg)
Headers for the abstract base class for all multi dimensionnal containers.
gum is the global namespace for all aGrUM entities
std::istream & operator>>(std::istream &in, TiXmlNode &base)
std::ostream & operator<<(std::ostream &out, const TiXmlNode &base)