aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
setInst.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
49
50#ifndef GUM_SETINST_H
51#define GUM_SETINST_H
52
53#include <ostream>
54
55#include <agrum/agrum.h>
56
59
60namespace gum {
61
63
64 class Instantiation;
65
66 // ==========================================================================
67 // === GUM_SetInst ===
68 // ==========================================================================
101 class SetInst {
102 public:
103 // =========================================================================
105 // =========================================================================
107
112
117 SetInst(const SetInst& aI);
118
124
131
139
147
155
163
168
170 // =========================================================================
172 // =========================================================================
174
179 Idx nbrDim() const;
180
194 void add(const DiscreteVariable& v);
195
203 void erase(const DiscreteVariable& v);
204
209 void clear();
210
217
222 Idx pos(const DiscreteVariable& v) const;
223
232 Size vals(Idx i) const;
233
242 Size vals(const DiscreteVariable& var) const;
243
252 Size vals(const DiscreteVariable* var) const;
253
263
264
273 Idx val(Idx i) const;
274
283 Idx val(const DiscreteVariable& var) const;
284
293 Idx val(const DiscreteVariable* var) const;
294
304
318 SetInst& chgVal(const DiscreteVariable& v, Idx newVal);
319
333 SetInst& chgVal(const DiscreteVariable* v, Idx newVal);
334
350 SetInst& chgVal(Idx varPos, Idx newVal);
351
365 SetInst& chgVals(const DiscreteVariable& v, const Size newVal);
366
380 SetInst& addVal(const DiscreteVariable& v, Idx newVal);
381
395 SetInst& addVals(const DiscreteVariable& v, const Size newVal);
396
410 SetInst& remVal(const DiscreteVariable& v, Idx newVal);
411
425 SetInst& remVals(const DiscreteVariable& v, const Size newVal);
426
441 SetInst& interVals(const DiscreteVariable& v, const Size newVal);
442
458
472 SetInst& chgVals(const DiscreteVariable* v, const Size newVal);
473
487 SetInst& addVal(const DiscreteVariable* v, Idx newVal);
488
502 SetInst& addVals(const DiscreteVariable* v, const Size newVal);
503
517 SetInst& remVal(const DiscreteVariable* v, Idx newVal);
518
532 SetInst& remVals(const DiscreteVariable* v, const Size newVal);
533
548 SetInst& interVals(const DiscreteVariable* v, const Size newVal);
549
565
581 SetInst& chgVals(Idx varPos, const Size newVal);
582
597 SetInst& addVal(Idx varPos, Idx newVal);
598
613 SetInst& addVals(Idx varPos, const Size newVal);
614
629 SetInst& remVal(Idx varPos, Idx newVal);
630
645 SetInst& remVals(Idx varPos, const Size newVal);
646
662 SetInst& interVals(Idx varPos, const Size newVal);
663
679 SetInst& interVal(Idx varPos, Idx newVal);
680
696 SetInst& chgDifVal(Idx varPos, const Size newVal);
697
704
711 bool contains(const DiscreteVariable& v) const;
712
719 bool contains(const DiscreteVariable* v) const;
720
726
731 virtual bool empty() const;
732
737 std::string toString() const;
738
744
749 void reorder(const SetInst& i);
750
752 // =========================================================================
754 // =========================================================================
756
767 bool inOverflow() const;
768
799
804 void unsetEnd();
805
816 bool end() const;
817
828
829 bool rend() const;
830
833
834
836
837 // ############################################################################
839 // ############################################################################
841
854 const SetInst& i,
855 SetInst& j);
856
858
859 protected:
860 virtual void replace_(const DiscreteVariable* x, const DiscreteVariable* y);
861
862 private:
865
867 std::vector< Size > _vals_;
868
871
877 void _swap_(Idx i, Idx j);
878
884 void _chgVal_(Idx varPos, Idx newVal);
885
891 void _chgVals_(Idx varPos, const Size newVal);
892
914 void _add_(const DiscreteVariable& v);
915
931 void _erase_(const DiscreteVariable& v);
932
938 };
939
941 std::ostream& operator<<(std::ostream&, const SetInst&);
942
951
960
961} /* namespace gum */
962
963#ifndef GUM_NO_INLINE
965#endif /* GUM_NO_INLINE */
966
967#endif /* GUM_SetInst_H */
Set of pairs of elements with fast search for both elements.
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1594
Base class for discrete random variable.
Class for assigning/browsing values to tuples of discrete variables.
Abstract base class for all multi dimensionnal addressable.
The generic class for storing (ordered) sequences of objects.
Definition sequence.h:972
Class for assigning/browsing values to tuples of discrete variables.
Definition setInst.h:101
SetInst & interVal(Idx varPos, Idx newVal)
Does an intersection (binary and) between the old value and new value.
Idx val(const DiscreteVariable &var) const
Returns the current value of a given variable.
Size vals(Idx i) const
Returns the current value of the variable at position i.
SetInst & addVals(Idx varPos, const Size newVal)
Add newVal to variable varPos in the SetInst.
SetInst(MultiDimAdressable &aMD)
Constructor for a SetInst of all the variables of a MultiDimAdressable.
SetInst(const SetInst &aI)
Copy constructor.
void reorder(const SetInst &i)
Reorder the variables given i.
SetInst()
Default constructor: creates an empty tuple.
bool end() const
Returns true if the SetInst reached the end.
SetInst & remVal(const DiscreteVariable *v, Idx newVal)
Remove newVal from the variable v in the SetInst.
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.
SetInst & chgVal(Idx varPos, Idx newVal)
Assign newVal to variable at position varPos in the SetInst.
SetInst & interVal(const DiscreteVariable *v, Idx newVal)
Does an intersection (binary and) between the old value and new value.
void _swap_(Idx i, Idx j)
Swap 2 vars in the SetInst.
void erase(const DiscreteVariable &v)
Removes a variable from the SetInst.
Sequence< const DiscreteVariable * > _vars_
The tuple of variables to be instantiated.
Definition setInst.h:864
bool inOverflow() const
Indicates whether the current value of the tuple is correct or not.
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.
void unsetOverflow()
Removes the flag overflow.
void _chgVals_(Idx varPos, const Size newVal)
Change the value of a variable.
bool rend() const
Returns true if the SetInst reached the rend.
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(const MultiDimAdressable *aMD)
Constructor for a SetInst of all the variables of a MultiDimAdressable.
SetInst & chgDifVal(Idx varPos, const Size newVal)
Does the difference (binary or) between the old value and new value.
bool contains(const DiscreteVariable *v) const
Indicates whether a given variable belongs to the SetInst.
SetInst & addVal(const DiscreteVariable *v, Idx newVal)
Add newVal to variable v in the SetInst.
~SetInst()
Class destructor.
SetInst & chgValIn(const SetInst &i)
Change all the values to match does in i.
SetInst & interVals(const DiscreteVariable *v, const Size newVal)
Does an intersection (binary and) between the old value and new value.
void unsetEnd()
Alias for unsetOverflow().
const Sequence< const DiscreteVariable * > & variablesSequence() const
Returns the sequence of DiscreteVariable of this SetInst.
SetInst(const Instantiation &aI)
Copy constructor.
Size vals(const DiscreteVariable &var) const
Returns the current value of a given variable.
SetInst & addVals(const DiscreteVariable *v, const Size newVal)
Add newVal to variable v in the SetInst.
SetInst & addVal(const DiscreteVariable &v, Idx newVal)
Add newVal to variable v in the SetInst.
SetInst & remVals(Idx varPos, const Size newVal)
Remove newVal from the variable varPos in the SetInst.
void _add_(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
bool _overflow_
The overflow flag.
Definition setInst.h:870
Idx val(const DiscreteVariable *var) const
Returns the current value of a given variable.
SetInst & remVals(const DiscreteVariable &v, const Size newVal)
Remove newVal from the variable v in the SetInst.
Idx nbrDim() const
Returns the number of variables in the SetInst.
Idx val(Idx i) const
Returns the current value of a variable at a given position.
SetInst & operator=(const SetInst &aI)
Copy operator.
Size vals(const DiscreteVariable *var) const
Returns the current value of a given variable.
SetInst(const MultiDimAdressable &aMD)
Constructor for a SetInst of all the variables of a MultiDimAdressable.
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 & addVal(Idx varPos, Idx newVal)
Add newVal to variable v in the SetInst.
Idx nbrOccurences(const DiscreteVariable &var) const
Returns the current value of the variable at position i.
SetInst & remVal(const DiscreteVariable &v, Idx newVal)
Remove newVal from the variable v in the SetInst.
SetInst & chgVals(const DiscreteVariable *v, const Size newVal)
Assign newVal to variable v in the SetInst.
std::string toString() const
Give a string version of SetInst.
void _init_(MultiDimAdressable *master)
Intialize the SetInst.
const DiscreteVariable & variable(Idx i) const
Returns the variable at position i in the tuple.
void add(const DiscreteVariable &v)
Adds a new variable in the SetInst.
std::vector< Size > _vals_
The current SetInst: the value of the tuple.
Definition setInst.h:867
SetInst & chgVal(const DiscreteVariable &v, Idx newVal)
Assign newVal to variable v in the SetInst.
void reorder(const Sequence< const DiscreteVariable * > &v)
Reorder the variables given v.
void clear()
Erase all variables from an SetInst.
SetInst & remVals(const DiscreteVariable *v, const Size newVal)
Remove newVal from the variable v in the SetInst.
SetInst & chgVals(const DiscreteVariable &v, const Size newVal)
Assign newVal to variable v in the SetInst.
SetInst & interVals(Idx varPos, const Size newVal)
Does an intersection (binary and) between the old value and new value.
virtual bool empty() const
Returns true if the SetInst is empty.
SetInst & chgVals(Idx varPos, const Size newVal)
Assign newVal to variable at position varPos in the SetInst.
SetInst & remVal(Idx varPos, Idx newVal)
Remove newVal from the variable varPos in the SetInst.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y)
SetInst(MultiDimAdressable *aMD)
Constructor for a SetInst of all the variables of a MultiDimAdressable.
SetInst & chgVal(const DiscreteVariable *v, Idx 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.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
MultiDimInterface & operator>>(MultiDimInterface &c, const DiscreteVariable &v)
Removes a var from the variables of the MutliDimAdressing.
Headers for the abstract base class for all multi dimensionnal containers.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Definition AVLTree.h:913