51#ifndef DOXYGEN_SHOULD_SKIP_THIS
57 const Sequence< const DiscreteVariable* >& v = master->variablesSequence();
62 for (
const auto var: v)
72 GUM_CONSTRUCTOR(SetInst);
76 SetInst::SetInst(
const MultiDimAdressable& d) : _overflow_(false) {
78 GUM_CONSTRUCTOR(SetInst);
79 _init_(
const_cast< MultiDimAdressable*
>(&d));
84 SetInst::SetInst(MultiDimAdressable* d) : _overflow_(false) {
86 GUM_CONSTRUCTOR(SetInst);
95 SetInst::SetInst(
const MultiDimAdressable* const_d) : _overflow_(false) {
97 GUM_CONSTRUCTOR(SetInst);
99 if (const_d) _init_(
const_cast< MultiDimAdressable*
>(const_d));
104 SetInst::SetInst(
const SetInst& aI) :
107 GUM_CONS_CPY(SetInst);
111 _overflow_ = aI._overflow_;
116 SetInst::SetInst(
const Instantiation& aI) :
119 GUM_CONS_CPY(SetInst);
120 const Sequence< const DiscreteVariable* >& v = aI.variablesSequence();
121 _vars_.resize(v.size());
125 for (
const auto var: v) {
127 _vals_[_vars_.pos(var)] = (Size(1) << (aI.val(*var)));
132 SetInst& SetInst::operator=(
const SetInst& aI) {
136 _overflow_ = aI._overflow_;
142 std::string SetInst::toString()
const {
143 std::stringstream sstr;
146 if (_overflow_) { sstr <<
"<invalid>"; }
150 Sequence< const DiscreteVariable* >::iterator_safe iter = _vars_.begin();
152 if (iter != _vars_.end()) {
153 std::stringstream sstr2;
155 Size si = variable(iter.pos()).domainSize();
156 Size valb = vals(iter.pos());
159 std::stringstream sstr4;
160 sstr4 << ((valb & 1) ?
"1" :
"0") << sstr2.str();
164 sstr2 << sstr4.str();
167 sstr << variable(iter.pos()).name() <<
":" << sstr2.str();
170 while (iter != _vars_.end()) {
171 std::stringstream sstr3;
173 si = variable(iter.pos()).domainSize();
175 valb = vals(iter.pos());
178 std::stringstream sstr4;
180 sstr4 << ((valb & 1) ?
"1" :
"0") << sstr3.str();
183 sstr3 << sstr4.str();
186 sstr <<
"|" << variable(iter.pos()).name() <<
":" << sstr3.str();
197 std::ostream&
operator<<(std::ostream& aStream,
const SetInst& i) {
198 aStream << i.toString();
219 }
catch (gum::NotFound&) {
220 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)