aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
graphElements.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
103#ifndef GUM_GRAPH_ELEMENTS_H
104#define GUM_GRAPH_ELEMENTS_H
105
106#include <iostream>
107
108#include <agrum/agrum.h>
109
110#include <agrum/base/core/set.h>
111
112namespace gum {
113
117 using NodeId = Size;
118
119 /* ===========================================================================
120 */
121 /* ===========================================================================
122 */
123 /* === GENERIC UNDIRECTED EDGES ===
124 */
125 /* ===========================================================================
126 */
127 /* ===========================================================================
128 */
161 /* ===========================================================================
162 */
163
164 class Edge {
165 public:
166 // ############################################################################
168 // ############################################################################
170
172
174 Edge(NodeId aN1, NodeId aN2);
175
177 Edge(const Edge& src);
178
180 Edge(Edge&& src) noexcept;
181
184
186
187 // ############################################################################
189 // ############################################################################
191
194
197
200
202
203 // ############################################################################
205 // ############################################################################
207
209 Edge& operator=(const Edge& src);
210
212 Edge& operator=(Edge&& src) noexcept;
213
215
217 bool operator==(const Edge& src) const = default;
218
220
221 private:
225 };
226
227 /* =========================================================================*/
228 /* =========================================================================*/
229 /* == GENERIC DIRECTED EDGES ==*/
230 /* =========================================================================*/
231 /* =========================================================================*/
264 /* ===========================================================================
265 */
266
267 class Arc {
268 public:
269 // ############################################################################
271 // ############################################################################
273
275
277
279 Arc(const Arc& src);
280
282 Arc(Arc&& src) noexcept;
283
286
288
289 // ############################################################################
291 // ############################################################################
293
296
299
302
305
308
310
311 // ############################################################################
313 // ############################################################################
315
317 Arc& operator=(const Arc& src);
318
320 Arc& operator=(Arc&& src) noexcept;
321
323
325 bool operator==(const Arc& src) const = default;
326
328
329 private:
333
336
339
341 void operator-();
342 };
343
345 // we need to provide hash functions for some Edge and Arc
346
347#ifndef DOXYGEN_SHOULD_SKIP_THIS
348
349 template <>
350 class HashFunc< Edge >: public HashFuncBase< Edge > {
351 public:
357 static Size castToSize(const Edge& key);
358
364 Size operator()(const Edge& key) const final;
365 };
366
367 template <>
368 class HashFunc< Arc >: public HashFuncBase< Arc > {
369 public:
375 static Size castToSize(const Arc& key);
376
382 Size operator()(const Arc& key) const final;
383 };
384
385#endif // DOXYGEN_SHOULD_SKIP_THIS
386
394
398
399 inline const NodeSet emptyNodeSet;
401
406 template < class VAL >
408 template < class VAL >
410 template < class VAL >
412
414
416 std::ostream& operator<<(std::ostream& stream, const Edge& edge);
417
419 std::ostream& operator<<(std::ostream& stream, const Arc& arc);
420
421} /* namespace gum */
422
423#if !defined(GUM_NO_EXTERN_TEMPLATE_CLASS) && !defined(SWIG)
424extern template class gum::HashFunc< gum::NodeSet >;
425#endif
426
427#ifndef GUM_NO_INLINE
429#endif /* GUM_NO_INLINE */
430
431#endif // GUM_GRAPH_ELEMENTS_H
The base class for all directed edges.
GUM_NODISCARD NodeId second() const
returns the node ID of the other extremal node ID
void _setTail_(NodeId id)
modifies the tail of the arc
GUM_NODISCARD NodeId head() const
returns the head of the arc
~Arc()
destructor
NodeId n1
the extremal nodes of the edge (their order is unimportant)
Arc(const Arc &src)
copy constructor
Arc & operator=(Arc &&src) noexcept
move operator
void _setHead_(NodeId id)
modifies the head of the arc
bool operator==(const Arc &src) const =default
checks whether two arcs are equal
GUM_NODISCARD NodeId other(NodeId id) const
returns an extremal node of an edge given the ID of the other one
GUM_NODISCARD NodeId first() const
returns one extremal node ID (whichever one it is is unspecified)
Arc & operator=(const Arc &src)
copy operator
Arc(Arc &&src) noexcept
move constructor
GUM_NODISCARD NodeId tail() const
returns the tail of the arc
Arc(NodeId tail, NodeId head)
basic constructor. Creates tail -> head.
void operator-()
reverses the direction of the arc
The base class for all undirected edges.
Edge(Edge &&src) noexcept
move constructor
NodeId n1
the extremal nodes of the edge (their order is unimportant)
GUM_NODISCARD NodeId first() const
returns one extremal node ID (whichever one it is is unspecified)
Edge & operator=(Edge &&src) noexcept
move operator
Edge & operator=(const Edge &src)
copy operator
~Edge()
destructor
GUM_NODISCARD NodeId other(NodeId id) const
returns an extremal node of an edge given the ID of the other one
Edge(NodeId aN1, NodeId aN2)
constructs a new edge (aN1,aN2)
Edge(const Edge &src)
copy constructor
bool operator==(const Edge &src) const =default
checks whether two undirected edges are equal
GUM_NODISCARD NodeId second() const
returns the node ID of the other extremal node ID
All hash functions should inherit from this class.
Definition hashFunc.h:174
This class should be useless as only its specializations should be used.
Definition hashFunc.h:492
SetIterator< Arc > const_iterator
Definition set.h:141
Inlined implementation of directed and undirected edges.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size NodeId
Type for node ids.
HashTable< Arc, VAL > ArcProperty
Property on graph elements.
ArcSet::const_iterator ArcSetIterator
Some typdefs and define for shortcuts ...
HashTable< Edge, VAL > EdgeProperty
Property on graph elements.
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
const NodeSet emptyNodeSet
Some typdefs and define for shortcuts ...
EdgeSet::const_iterator EdgeSetIterator
Some typdefs and define for shortcuts ...
NodeSet::const_iterator NodeSetIterator
Some typdefs and define for shortcuts ...
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
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
Sets of elements (i.e.
#define GUM_NODISCARD
Definition types.h:61