aGrUM 2.3.2
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-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
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
181
183
184 // ############################################################################
186 // ############################################################################
188
191
194
197
199
200 // ############################################################################
202 // ############################################################################
204
206 Edge& operator=(const Edge& src);
207
209
211 bool operator==(const Edge& src) const = default;
212
214
215 private:
219 };
220
221 /* =========================================================================*/
222 /* =========================================================================*/
223 /* == GENERIC DIRECTED EDGES ==*/
224 /* =========================================================================*/
225 /* =========================================================================*/
258 /* ===========================================================================
259 */
260
261 class Arc {
262 public:
263 // ############################################################################
265 // ############################################################################
267
269
271
273 Arc(const Arc& src);
274
277
279
280 // ############################################################################
282 // ############################################################################
284
287
290
293
296
299
301
302 // ############################################################################
304 // ############################################################################
306
308 Arc& operator=(const Arc& src);
309
311
313 bool operator==(const Arc& src) const = default;
314
316
317 private:
321
324
327
329 void operator-();
330 };
331
333 // we need to provide hash functions for some Edge and Arc
334
335#ifndef DOXYGEN_SHOULD_SKIP_THIS
336
337 template <>
338 class HashFunc< Edge >: public HashFuncBase< Edge > {
339 public:
345 static Size castToSize(const Edge& key);
346
352 Size operator()(const Edge& key) const final;
353 };
354
355 template <>
356 class HashFunc< Arc >: public HashFuncBase< Arc > {
357 public:
363 static Size castToSize(const Arc& key);
364
370 Size operator()(const Arc& key) const final;
371 };
372
373#endif // DOXYGEN_SHOULD_SKIP_THIS
374
382
386
387 inline const NodeSet emptyNodeSet;
389
394 template < class VAL >
396 template < class VAL >
398 template < class VAL >
400
402
404 std::ostream& operator<<(std::ostream& stream, const Edge& edge);
405
407 std::ostream& operator<<(std::ostream& stream, const Arc& arc);
408
409} /* namespace gum */
410
411#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
412extern template class gum::HashFunc< gum::NodeSet >;
413#endif
414
415#ifndef GUM_NO_INLINE
417#endif /* GUM_NO_INLINE */
418
419#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
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
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.
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=(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:169
This class should be useless as only its specializations should be used.
Definition hashFunc.h:487
SetIterator< Arc > const_iterator
Definition set.h:143
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
Definition AVLTree.h:913
Sets of elements (i.e.
#define GUM_NODISCARD
Definition types.h:61