aGrUM  0.14.2
setInst.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Ariele-Paolo MAESANO *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
28 #ifndef GUM_SETINST_H
29 #define GUM_SETINST_H
30 
31 #include <ostream>
32 
33 #include <agrum/agrum.h>
34 
35 #include <agrum/core/bijection.h>
38 
39 namespace gum {
40 
41  class MultiDimAdressable;
42 
43  class Instantiation;
44  // ==========================================================================
45  // === GUM_SetInst ===
46  // ==========================================================================
79  class SetInst {
80  public:
81  // =========================================================================
83  // =========================================================================
85 
89  SetInst();
90 
95  SetInst(const SetInst& aI);
96 
101  SetInst(const Instantiation& aI);
102 
108  SetInst& operator=(const SetInst& aI);
109 
117 
124  SetInst(const MultiDimAdressable& aMD);
125 
133 
140  SetInst(const MultiDimAdressable* aMD);
141 
145  ~SetInst();
146 
148  // =========================================================================
150  // =========================================================================
152 
157  Idx nbrDim() const;
158 
172  void add(const DiscreteVariable& v);
173 
181  void erase(const DiscreteVariable& v);
182 
187  void clear();
188 
194  Size domainSize() const;
195 
200  Idx pos(const DiscreteVariable& v) const;
201 
210  Size vals(Idx i) const;
211 
220  Size vals(const DiscreteVariable& var) const;
221 
230  Size vals(const DiscreteVariable* var) const;
231 
240  Idx nbrOccurences(const DiscreteVariable& var) const;
241 
242 
251  Idx val(Idx i) const;
252 
261  Idx val(const DiscreteVariable& var) const;
262 
271  Idx val(const DiscreteVariable* var) const;
272 
281  const DiscreteVariable& variable(Idx i) const;
282 
296  SetInst& chgVal(const DiscreteVariable& v, Idx newVal);
297 
311  SetInst& chgVal(const DiscreteVariable* v, Idx newVal);
312 
328  SetInst& chgVal(Idx varPos, Idx newVal);
329 
343  SetInst& chgVals(const DiscreteVariable& v, const Size newVal);
344 
358  SetInst& addVal(const DiscreteVariable& v, Idx newVal);
359 
373  SetInst& addVals(const DiscreteVariable& v, const Size newVal);
374 
388  SetInst& remVal(const DiscreteVariable& v, Idx newVal);
389 
403  SetInst& remVals(const DiscreteVariable& v, const Size newVal);
404 
419  SetInst& interVals(const DiscreteVariable& v, const Size newVal);
420 
435  SetInst& interVal(const DiscreteVariable& v, Idx newVal);
436 
450  SetInst& chgVals(const DiscreteVariable* v, const Size newVal);
451 
465  SetInst& addVal(const DiscreteVariable* v, Idx newVal);
466 
480  SetInst& addVals(const DiscreteVariable* v, const Size newVal);
481 
495  SetInst& remVal(const DiscreteVariable* v, Idx newVal);
496 
510  SetInst& remVals(const DiscreteVariable* v, const Size newVal);
511 
526  SetInst& interVals(const DiscreteVariable* v, const Size newVal);
527 
542  SetInst& interVal(const DiscreteVariable* v, Idx newVal);
543 
559  SetInst& chgVals(Idx varPos, const Size newVal);
560 
575  SetInst& addVal(Idx varPos, Idx newVal);
576 
591  SetInst& addVals(Idx varPos, const Size newVal);
592 
607  SetInst& remVal(Idx varPos, Idx newVal);
608 
623  SetInst& remVals(Idx varPos, const Size newVal);
624 
640  SetInst& interVals(Idx varPos, const Size newVal);
641 
657  SetInst& interVal(Idx varPos, Idx newVal);
658 
674  SetInst& chgDifVal(Idx varPos, const Size newVal);
675 
681  SetInst& chgValIn(const SetInst& i);
682 
689  bool contains(const DiscreteVariable& v) const;
690 
697  bool contains(const DiscreteVariable* v) const;
698 
704 
709  virtual bool empty() const;
710 
715  std::string toString() const;
716 
722 
727  void reorder(const SetInst& i);
728 
730  // =========================================================================
732  // =========================================================================
734 
745  bool inOverflow() const;
746 
776  void unsetOverflow();
777 
782  void unsetEnd();
783 
794  bool end() const;
795 
807  bool rend() const;
808 
811 
812 
814 
815  // ############################################################################
817  // ############################################################################
819 
831  static void assign_values(
833  const SetInst& i,
834  SetInst& j);
835 
837 
838  protected:
839  virtual void _replace(const DiscreteVariable* x, const DiscreteVariable* y);
840 
841  private:
844 
846  std::vector< Size > __vals;
847 
850 
856  void __swap(Idx i, Idx j);
857 
863  void __chgVal(Idx varPos, Idx newVal);
864 
870  void __chgVals(Idx varPos, const Size newVal);
871 
893  void __add(const DiscreteVariable& v);
894 
910  void __erase(const DiscreteVariable& v);
911 
916  void __init(MultiDimAdressable* master);
917  };
918 
920  std::ostream& operator<<(std::ostream&, const SetInst&);
921 
930 
939 
940 } /* namespace gum */
941 
942 #ifndef GUM_NO_INLINE
944 #endif /* GUM_NO_INLINE */
945 
946 #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:1019
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.
gum is the global namespace for all aGrUM entities
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:583
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y)
Class for assigning/browsing values to tuples of discrete variables.
Definition: setInst.h:79
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:1803
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:846
bool __overflow
The overflow flag.
Definition: setInst.h:849
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:80
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
Definition: setInst.h:843
void erase(const DiscreteVariable &v)
Removes a variable from the SetInst.
Headers of MultiDimInterface.
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:50
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:45
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.
Set of pairs of elements with fast search for both elements.
Headers for the abstract base class for all multi dimensionnal containers.
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.