aGrUM 3.1.1
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-2026 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-2026 *
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
123 SetInst(SetInst&& aI) noexcept;
124
130
137
139 SetInst& operator=(SetInst&& aI) noexcept;
140
148
156
164
172
177
179 // =========================================================================
181 // =========================================================================
183
188 Idx nbrDim() const;
189
203 void add(const DiscreteVariable& v);
204
212 void erase(const DiscreteVariable& v);
213
218 void clear();
219
226
231 Idx pos(const DiscreteVariable& v) const;
232
241 Size vals(Idx i) const;
242
251 Size vals(const DiscreteVariable& var) const;
252
261 Size vals(const DiscreteVariable* var) const;
262
272
273
282 Idx val(Idx i) const;
283
292 Idx val(const DiscreteVariable& var) const;
293
302 Idx val(const DiscreteVariable* var) const;
303
313
327 SetInst& chgVal(const DiscreteVariable& v, Idx newVal);
328
342 SetInst& chgVal(const DiscreteVariable* v, Idx newVal);
343
359 SetInst& chgVal(Idx varPos, Idx newVal);
360
374 SetInst& chgVals(const DiscreteVariable& v, const Size newVal);
375
389 SetInst& addVal(const DiscreteVariable& v, Idx newVal);
390
404 SetInst& addVals(const DiscreteVariable& v, const Size newVal);
405
419 SetInst& remVal(const DiscreteVariable& v, Idx newVal);
420
434 SetInst& remVals(const DiscreteVariable& v, const Size newVal);
435
450 SetInst& interVals(const DiscreteVariable& v, const Size newVal);
451
467
481 SetInst& chgVals(const DiscreteVariable* v, const Size newVal);
482
496 SetInst& addVal(const DiscreteVariable* v, Idx newVal);
497
511 SetInst& addVals(const DiscreteVariable* v, const Size newVal);
512
526 SetInst& remVal(const DiscreteVariable* v, Idx newVal);
527
541 SetInst& remVals(const DiscreteVariable* v, const Size newVal);
542
557 SetInst& interVals(const DiscreteVariable* v, const Size newVal);
558
574
590 SetInst& chgVals(Idx varPos, const Size newVal);
591
606 SetInst& addVal(Idx varPos, Idx newVal);
607
622 SetInst& addVals(Idx varPos, const Size newVal);
623
638 SetInst& remVal(Idx varPos, Idx newVal);
639
654 SetInst& remVals(Idx varPos, const Size newVal);
655
671 SetInst& interVals(Idx varPos, const Size newVal);
672
688 SetInst& interVal(Idx varPos, Idx newVal);
689
705 SetInst& chgDifVal(Idx varPos, const Size newVal);
706
713
720 bool contains(const DiscreteVariable& v) const;
721
728 bool contains(const DiscreteVariable* v) const;
729
735
740 virtual bool empty() const;
741
746 std::string toString() const;
747
753
758 void reorder(const SetInst& i);
759
761 // =========================================================================
763 // =========================================================================
765
776 bool inOverflow() const;
777
808
813 void unsetEnd();
814
825 bool end() const;
826
837
838 bool rend() const;
839
842
843
845
846 // ############################################################################
848 // ############################################################################
850
863 const SetInst& i,
864 SetInst& j);
865
867
868 protected:
869 virtual void replace_(const DiscreteVariable* x, const DiscreteVariable* y);
870
871 private:
874
876 std::vector< Size > _vals_;
877
880
886 void _swap_(Idx i, Idx j);
887
893 void _chgVal_(Idx varPos, Idx newVal);
894
900 void _chgVals_(Idx varPos, const Size newVal);
901
923 void _add_(const DiscreteVariable& v);
924
940 void _erase_(const DiscreteVariable& v);
941
947 };
948
950 std::ostream& operator<<(std::ostream&, const SetInst&);
951
960
969
970} /* namespace gum */
971
972#ifndef GUM_NO_INLINE
974#endif /* GUM_NO_INLINE */
975
976#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:1640
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:994
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.
SetInst(SetInst &&aI) noexcept
Move constructor.
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:873
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().
SetInst & operator=(SetInst &&aI) noexcept
move assignment operator
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:879
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:876
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