aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
idCondSet.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
47#ifndef GUM_LEARNING_ID_SET_H
48#define GUM_LEARNING_ID_SET_H
49
50#include <iostream>
51#include <sstream>
52#include <string>
53#include <utility>
54#include <vector>
55
56#include <agrum/agrum.h>
57
60
61#include <type_traits>
62
63namespace gum {
64
65 namespace learning {
66
67
68 class IdCondSet;
69
76 public:
79 using iterator_category = std::forward_iterator_tag;
81 using reference = NodeId&;
82 using const_reference = const NodeId&;
83 using pointer = NodeId*;
84 using const_pointer = const NodeId*;
85 using difference_type = std::ptrdiff_t;
87
88
89 // ##########################################################################
91 // ##########################################################################
93
95
97
99
101
104
107
110
112
113
114 // ##########################################################################
116 // ##########################################################################
118
121
124
130
132 bool operator!=(const IdCondSetIterator& from) const;
133
135 bool operator==(const IdCondSetIterator& from) const;
136
149
155 IdCondSetIterator& operator+=(const std::size_t i);
156
163 IdCondSetIterator operator+(const std::size_t i);
164
166
167
168 // ##########################################################################
170 // ##########################################################################
172
178 std::size_t pos() const;
179
181
182
183#ifndef DOXYGEN_SHOULD_SKIP_THIS
184
185 private:
187 const Sequence< NodeId >* _seq_{nullptr};
188
190 std::size_t _index_{std::size_t(0)};
191
192
194 void _gotoEnd_();
195
196 friend class IdCondSet;
197
198#endif /* DOXYGEN_SHOULD_SKIP_THIS */
199 };
200
214 class IdCondSet {
215 public:
220
221 // ##########################################################################
223 // ##########################################################################
225
228
230
236 IdCondSet(const std::vector< NodeId >& ids, const bool rhs_ids, const bool ordered_ids);
237
239
246 const std::vector< NodeId >& rhs_ids,
247 const bool ordered_rhs_ids = false);
248
250
262 NodeId var2,
263 const std::vector< NodeId >& rhs_ids,
264 const bool ordered_lhs_vars,
265 const bool ordered_rhs_ids = false);
266
268
279 NodeId var2,
280 NodeId var3,
281 const std::vector< NodeId >& rhs_ids,
282 const bool ordered_lhs_vars,
283 const bool ordered_rhs_ids = false);
284
286 IdCondSet(const IdCondSet& from);
287
290
292 virtual IdCondSet* clone() const;
293
295 virtual ~IdCondSet();
296
298
299
300 // ##########################################################################
302 // ##########################################################################
304
307
310
312 NodeId operator[](const std::size_t index) const;
313
315 bool operator==(const IdCondSet& from) const;
316
318 bool operator!=(const IdCondSet& from) const;
319
321
322
323 // ##########################################################################
325 // ##########################################################################
327
333
338 const iterator_safe& endSafe() const;
339
345
350 const iterator& end() const;
351
353
354
355 // ##########################################################################
357 // ##########################################################################
359
361 const Sequence< NodeId >& ids() const;
362
365
367 std::size_t nbLHSIds() const;
368
370 std::size_t nbRHSIds() const;
371
373 bool contains(const IdCondSet& set) const;
374
376 void clear();
377
379 std::size_t size() const;
380
382
383 std::size_t pos(const NodeId id) const;
384
386 bool exists(const NodeId id) const;
387
389
391 void erase(const NodeId id);
392
394 bool hasConditioningSet() const;
395
397 bool empty() const;
398
400 std::string toString() const;
401
403 std::pair< NodeSet, NodeSet > toNodeSets() const;
404
406
407
408#ifndef DOXYGEN_SHOULD_SKIP_THIS
409
410 private:
412 Sequence< NodeId > _ids_;
413
415 std::size_t _nb_lhs_ids_{std::size_t(0)};
416
418 IdCondSetIterator _end_safe_;
419
420#endif /* DOXYGEN_SHOULD_SKIP_THIS */
421 };
422
424 std::ostream& operator<<(std::ostream& stream, const IdCondSet& idset);
425
426 } /* namespace learning */
427
429 template <>
430 class HashFunc< learning::IdCondSet >: public HashFuncBase< learning::IdCondSet > {
431 public:
438
440 Size operator()(const learning::IdCondSet& key) const final;
441 };
442
443
444} /* namespace gum */
445
446// include the inlined functions if necessary
447#ifndef GUM_NO_INLINE
449#endif /* GUM_NO_INLINE */
450
451#endif /* GUM_LEARNING_ID_SET_H */
All hash functions should inherit from this class.
Definition hashFunc.h:169
Size operator()(const learning::IdCondSet &key) const final
computes the hashed value of a key
static Size castToSize(const learning::IdCondSet &key)
Returns the value of a key as a Size.
This class should be useless as only its specializations should be used.
Definition hashFunc.h:487
The iterators for IdSets.
Definition idCondSet.h:75
virtual ~IdCondSetIterator()
destructor
NodeId & reference
types for STL compliance
Definition idCondSet.h:81
std::forward_iterator_tag iterator_category
types for STL compliance
Definition idCondSet.h:79
const NodeId * const_pointer
types for STL compliance
Definition idCondSet.h:84
IdCondSetIterator()
default constructor
IdCondSetIterator(const IdCondSet &idset)
Constructor for a begin.
NodeId value_type
types for STL compliance
Definition idCondSet.h:80
IdCondSetIterator & operator++()
Makes the iterator point to the next element in the IdCondSet.
IdCondSetIterator(IdCondSetIterator &&from)
move constructor
NodeId operator*() const
Gives access to the content of the iterator.
std::size_t pos() const
Returns the position of the iterator in the IdCondSet.
bool operator!=(const IdCondSetIterator &from) const
Checks whether two iterators point toward different elements.
IdCondSetIterator(const IdCondSetIterator &from)
Copy constructor.
const NodeId & const_reference
types for STL compliance
Definition idCondSet.h:82
std::ptrdiff_t difference_type
types for STL compliance
Definition idCondSet.h:85
IdCondSetIterator & operator=(IdCondSetIterator &&from)
move operator
IdCondSetIterator & operator=(const IdCondSetIterator &from)
copy operator
bool operator==(const IdCondSetIterator &from) const
Checks whether two iterators point toward the same elements.
NodeId * pointer
types for STL compliance
Definition idCondSet.h:83
IdCondSetIterator & operator+=(const std::size_t i)
Makes the iterator point to i elements further in the IdCondSet.
IdCondSetIterator operator+(const std::size_t i)
Returns a new iterator pointing to i further elements in the IdCondSet.
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set.
Definition idCondSet.h:214
bool contains(const IdCondSet &set) const
indicates whether the IdCondSet contains the IdCondSet passed in argument
bool empty() const
indicates whether the IdCondSet contains some nodes or not
const Sequence< NodeId > & ids() const
returns the set of ids
IdCondSet conditionalIdCondSet() const
returns the idSet at the right hand side of the conditioning bar
IdCondSetIterator iterator_safe
Definition idCondSet.h:218
IdCondSetIterator const_iterator
Definition idCondSet.h:217
std::size_t nbRHSIds() const
returns the number of right hand side ids
std::size_t pos(const NodeId id) const
returns the position of a given node in the IdCondSet
void clear()
removes all the nodes from the IdCondSet
bool operator!=(const IdCondSet &from) const
returns true if the sets differ
virtual ~IdCondSet()
destructor
std::string toString() const
returns the content of the set as a string
const iterator_safe & endSafe() const
Returns the safe end iterator.
NodeId operator[](const std::size_t index) const
returns the node id stored at a given index
std::pair< NodeSet, NodeSet > toNodeSets() const
returns the pair of conditioned gum::NodeSet and conditioning gum::NodeSet
virtual IdCondSet * clone() const
virtual copy constructor
bool exists(const NodeId id) const
indicates whether a given id is contained in the IdCondSet
IdCondSetIterator const_iterator_safe
Definition idCondSet.h:219
IdCondSet(const IdCondSet &from)
copy constructor
void erase(const NodeId id)
erase a node in the idset
IdCondSet & operator=(IdCondSet &&from)
move operator
std::size_t size() const
returns the number of variables (both left and right hand side)
IdCondSet & operator=(const IdCondSet &from)
copy operator
IdCondSet(NodeId var1, const std::vector< NodeId > &rhs_ids, const bool ordered_rhs_ids=false)
default constructor with one variable on the left side
bool operator==(const IdCondSet &from) const
returns true if both sets are equal
IdCondSet(NodeId var1, NodeId var2, const std::vector< NodeId > &rhs_ids, const bool ordered_lhs_vars, const bool ordered_rhs_ids=false)
default constructor with two variables on the left side
iterator begin() const
Returns an unsafe begin iterator.
IdCondSet(NodeId var1, NodeId var2, NodeId var3, const std::vector< NodeId > &rhs_ids, const bool ordered_lhs_vars, const bool ordered_rhs_ids=false)
default constructor with three variables on the left side
iterator_safe beginSafe() const
Returns a safe begin iterator.
IdCondSet(IdCondSet &&from)
move constructor
IdCondSet(const std::vector< NodeId > &ids, const bool rhs_ids, const bool ordered_ids)
default constructor with no variable on the left side
const iterator & end() const
Returns the unsafe end iterator.
IdCondSet()
default constructor
IdCondSetIterator iterator
Definition idCondSet.h:216
std::size_t nbLHSIds() const
returns the number of left hand side ids
bool hasConditioningSet() const
indicates whether the idset contains a non-empty conditioning set
some utils for topology : NodeId, Edge, Arc and consorts ...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
Template implementation of idSets.
include the inlined functions if necessary
Definition CSVParser.h:54
std::ostream & operator<<(std::ostream &stream, const IdCondSet &idset)
the display operator
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Header file of gum::Sequence, a class for storing (ordered) sequences of objects.