aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DFSCode.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
48
49#include <ostream>
50#include <vector>
51
53
54#ifndef GUM_DFS_CODE_H
55# define GUM_DFS_CODE_H
56
57namespace gum {
58 namespace prm {
59 namespace gspan {
60
72 class DFSCode {
73 public:
84 static bool validNeighbors(EdgeCode* e1, EdgeCode* e2);
85
90 DFSCode();
91
97 DFSCode(const DFSCode& source);
98
104 ~DFSCode();
105
109 std::vector< EdgeCode* > codes;
110
116 DFSCode& operator=(const DFSCode& source);
117
123 bool operator==(const DFSCode& code) const;
124
130 bool operator!=(const DFSCode& code) const;
131
137 bool operator<(const DFSCode& code) const;
138
144 bool operator<=(const DFSCode& code) const;
145
147 using iterator = std::vector< EdgeCode* >::iterator;
148
150 using const_iterator = std::vector< EdgeCode* >::const_iterator;
151 };
152
159 std::ostream& operator<<(std::ostream& out, const DFSCode& code);
160
162 if (e1->isBackward()) {
163 if (e2->isForward()) {
164 return (e2->i <= e1->i) && (e2->j = (e1->i + 1));
165 } else {
166 return (e2->i == e1->i) && (e1->j < e2->j);
167 }
168 } else {
169 // e1 is a forward edge
170 if (e2->isForward()) {
171 return (e2->i <= e1->j) && (e2->j == (e1->j + 1));
172 } else {
173 return (e2->i == e1->j) && (e2->j < e1->i);
174 }
175 }
176 }
177
178 } /* namespace gspan */
179 } /* namespace prm */
180} /* namespace gum */
181
182# ifndef GUM_NO_INLINE
184# endif // GUM_NO_INLINE
185
186#endif /* GUM_DFS_CODE_H */
Inline implementation of the DFSCode class.
Reprensent a Depth First Search coding of a graph.
Definition DFSCode.h:72
DFSCode & operator=(const DFSCode &source)
Copy operator.
Definition DFSCode_inl.h:76
std::vector< EdgeCode * > codes
The vector containing the EdgeCode composing this DFSCode.
Definition DFSCode.h:109
std::vector< EdgeCode * >::const_iterator const_iterator
Code alias.
Definition DFSCode.h:150
static bool validNeighbors(EdgeCode *e1, EdgeCode *e2)
Returns true of e2 is a valid neighbor for e1 (i.e.
Definition DFSCode.h:161
bool operator==(const DFSCode &code) const
Equality operator.
Definition DFSCode_inl.h:87
bool operator<=(const DFSCode &code) const
Lesser or equal than operator.
bool operator<(const DFSCode &code) const
Lesser than operator.
std::vector< EdgeCode * >::iterator iterator
Code alias.
Definition DFSCode.h:147
DFSCode()
Default constructor.
Definition DFSCode_inl.h:54
bool operator!=(const DFSCode &code) const
Difference operator.
Headers of the EdgeCode class.
std::ostream & operator<<(std::ostream &out, const DFSCode &code)
Print code in out.
Definition DFSCode.cpp:59
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
represent a DFS code used by gspan.
Definition edgeCode.h:72
NodeId i
The DFS subscript of the first node in the code.
Definition edgeCode.h:97
bool isForward() const
Returns true if this EdgeCode is a forward edge.
NodeId j
The DFS subscript of the second node in the code.
Definition edgeCode.h:100
bool isBackward() const
Returns true if this EdgeCode is a backward edge.