aGrUM  0.16.0
setInst.h
Go to the documentation of this file.
1 
31 #ifndef GUM_SETINST_H
32 #define GUM_SETINST_H
33 
34 #include <ostream>
35 
36 #include <agrum/agrum.h>
37 
38 #include <agrum/core/bijection.h>
41 
42 namespace gum {
43 
44  class MultiDimAdressable;
45 
46  class Instantiation;
47  // ==========================================================================
48  // === GUM_SetInst ===
49  // ==========================================================================
82  class SetInst {
83  public:
84  // =========================================================================
86  // =========================================================================
88 
92  SetInst();
93 
98  SetInst(const SetInst& aI);
99 
104  SetInst(const Instantiation& aI);
105 
111  SetInst& operator=(const SetInst& aI);
112 
120 
127  SetInst(const MultiDimAdressable& aMD);
128 
136 
143  SetInst(const MultiDimAdressable* aMD);
144 
148  ~SetInst();
149 
151  // =========================================================================
153  // =========================================================================
155 
160  Idx nbrDim() const;
161 
175  void add(const DiscreteVariable& v);
176 
184  void erase(const DiscreteVariable& v);
185 
190  void clear();
191 
197  Size domainSize() const;
198 
203  Idx pos(const DiscreteVariable& v) const;
204 
213  Size vals(Idx i) const;
214 
223  Size vals(const DiscreteVariable& var) const;
224 
233  Size vals(const DiscreteVariable* var) const;
234 
243  Idx nbrOccurences(const DiscreteVariable& var) const;
244 
245 
254  Idx val(Idx i) const;
255 
264  Idx val(const DiscreteVariable& var) const;
265 
274  Idx val(const DiscreteVariable* var) const;
275 
284  const DiscreteVariable& variable(Idx i) const;
285 
299  SetInst& chgVal(const DiscreteVariable& v, Idx newVal);
300 
314  SetInst& chgVal(const DiscreteVariable* v, Idx newVal);
315 
331  SetInst& chgVal(Idx varPos, Idx newVal);
332 
346  SetInst& chgVals(const DiscreteVariable& v, const Size newVal);
347 
361  SetInst& addVal(const DiscreteVariable& v, Idx newVal);
362 
376  SetInst& addVals(const DiscreteVariable& v, const Size newVal);
377 
391  SetInst& remVal(const DiscreteVariable& v, Idx newVal);
392 
406  SetInst& remVals(const DiscreteVariable& v, const Size newVal);
407 
422  SetInst& interVals(const DiscreteVariable& v, const Size newVal);
423 
438  SetInst& interVal(const DiscreteVariable& v, Idx newVal);
439 
453  SetInst& chgVals(const DiscreteVariable* v, const Size newVal);
454 
468  SetInst& addVal(const DiscreteVariable* v, Idx newVal);
469 
483  SetInst& addVals(const DiscreteVariable* v, const Size newVal);
484 
498  SetInst& remVal(const DiscreteVariable* v, Idx newVal);
499 
513  SetInst& remVals(const DiscreteVariable* v, const Size newVal);
514 
529  SetInst& interVals(const DiscreteVariable* v, const Size newVal);
530 
545  SetInst& interVal(const DiscreteVariable* v, Idx newVal);
546 
562  SetInst& chgVals(Idx varPos, const Size newVal);
563 
578  SetInst& addVal(Idx varPos, Idx newVal);
579 
594  SetInst& addVals(Idx varPos, const Size newVal);
595 
610  SetInst& remVal(Idx varPos, Idx newVal);
611 
626  SetInst& remVals(Idx varPos, const Size newVal);
627 
643  SetInst& interVals(Idx varPos, const Size newVal);
644 
660  SetInst& interVal(Idx varPos, Idx newVal);
661 
677  SetInst& chgDifVal(Idx varPos, const Size newVal);
678 
684  SetInst& chgValIn(const SetInst& i);
685 
692  bool contains(const DiscreteVariable& v) const;
693 
700  bool contains(const DiscreteVariable* v) const;
701 
707 
712  virtual bool empty() const;
713 
718  std::string toString() const;
719 
725 
730  void reorder(const SetInst& i);
731 
733  // =========================================================================
735  // =========================================================================
737 
748  bool inOverflow() const;
749 
779  void unsetOverflow();
780 
785  void unsetEnd();
786 
797  bool end() const;
798 
810  bool rend() const;
811 
814 
815 
817 
818  // ############################################################################
820  // ############################################################################
822 
834  static void assign_values(
836  const SetInst& i,
837  SetInst& j);
838 
840 
841  protected:
842  virtual void _replace(const DiscreteVariable* x, const DiscreteVariable* y);
843 
844  private:
847 
849  std::vector< Size > __vals;
850 
853 
859  void __swap(Idx i, Idx j);
860 
866  void __chgVal(Idx varPos, Idx newVal);
867 
873  void __chgVals(Idx varPos, const Size newVal);
874 
896  void __add(const DiscreteVariable& v);
897 
913  void __erase(const DiscreteVariable& v);
914 
919  void __init(MultiDimAdressable* master);
920  };
921 
923  std::ostream& operator<<(std::ostream&, const SetInst&);
924 
933 
942 
943 } /* namespace gum */
944 
945 #ifndef GUM_NO_INLINE
947 #endif /* GUM_NO_INLINE */
948 
949 #endif /* GUM_SetInst_H */
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.
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.
SetInst & chgVal(const DiscreteVariable &v, Idx newVal)
Assign newVal to variable v in the SetInst.
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1022
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.
Base class for discrete random variable.
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.
std::string toString() const
Give a string version of SetInst.
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.
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map&#39;s DAG in output using the Graphviz-dot format.
Definition: BayesNet_tpl.h:605
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y)
Class for assigning/browsing values to tuples of discrete variables.
Definition: setInst.h:82
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.
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1805
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
Abstract base class for all multi dimensionnal addressable.
SetInst & remVals(const DiscreteVariable &v, const Size newVal)
Remove newVal from the variable v in the SetInst.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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
void __init(MultiDimAdressable *master)
Intialize the SetInst.
SetInst & interVals(const DiscreteVariable &v, const Size newVal)
Does an intersection (binary and) between the old value and new value.
MultiDimInterface & operator>>(MultiDimInterface &c, const DiscreteVariable &v)
Removes a var from the variables of the MutliDimAdressing.
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.
SetInst & operator=(const SetInst &aI)
Copy operator.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
~SetInst()
Class destructor.
void reorder(const Sequence< const DiscreteVariable * > &v)
Reorder the variables given v.