aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DFSCode_inl.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#pragma once
41
48
49namespace gum {
50 namespace prm {
51 namespace gspan {
52
53 INLINE
55 GUM_CONSTRUCTOR(DFSCode);
56 ;
57 }
58
59 INLINE
60 DFSCode::DFSCode(const DFSCode& source) {
61 GUM_CONS_CPY(DFSCode);
62
63 for (const auto code: source.codes)
64 codes.push_back(new EdgeCode(*code));
65 }
66
67 INLINE
69 GUM_DESTRUCTOR(DFSCode);
70
71 for (const auto item: codes)
72 delete item;
73 }
74
75 INLINE
77 for (const auto item: codes)
78 delete item;
79
80 for (const auto srcitem: source.codes)
81 codes.push_back(new EdgeCode(*srcitem));
82
83 return *this;
84 }
85
86 INLINE
87 bool DFSCode::operator==(const DFSCode& from) const {
88 if (codes.size() == from.codes.size()) {
89 for (size_t idx = 0; idx < codes.size(); ++idx) {
90 if ((*codes[idx]) != (*codes[idx])) { return false; }
91 }
92
93 return true;
94 } else {
95 return false;
96 }
97 }
98
99 INLINE
100 bool DFSCode::operator!=(const DFSCode& from) const {
101 if (codes.size() == from.codes.size()) {
102 for (size_t idx = 0; idx < codes.size(); ++idx) {
103 if ((*codes[idx]) != (*codes[idx])) { return true; }
104 }
105
106 return false;
107 } else {
108 return true;
109 }
110 }
111
112 INLINE
113 bool DFSCode::operator<(const DFSCode& from) const {
114 DFSCode::const_iterator iter = codes.begin();
115 DFSCode::const_iterator jter = from.codes.begin();
116
117 for (; (iter != codes.end()) && (jter != from.codes.end()); ++iter, ++jter) {
118 if ((**iter) != (**jter)) {
119 EdgeCode& alpha = **iter;
120 EdgeCode& beta = **jter;
121
122 if (alpha.isBackward()) {
123 if (beta.isForward()) {
124 return true;
125 } else if (alpha.j < beta.j) {
126 // beta is a backward edge
127 return true;
128 } else if ((alpha.j == beta.j) && (alpha.l_ij < beta.l_ij)) {
129 return true;
130 }
131
132 return false;
133 } else {
134 // alpha is a forward edge
135 if (beta.isBackward()) {
136 return false;
137 } else if (beta.i < alpha.i) {
138 // Beta is a forward edge
139 return true;
140 } else if (beta.i == alpha.i) {
141 if (alpha.l_i < beta.l_i) {
142 return true;
143 } else if (alpha.l_i == beta.l_i) {
144 if (alpha.l_ij < beta.l_ij) {
145 return true;
146 } else if (alpha.l_ij == beta.l_ij) {
147 return alpha.l_j < beta.l_j;
148 }
149 }
150 }
151
152 return false;
153 }
154
155 return (**iter) < (**jter);
156 }
157 }
158
159 return false;
160 }
161
162 INLINE
163 bool DFSCode::operator<=(const DFSCode& from) const {
164 DFSCode::const_iterator iter = codes.begin();
165 DFSCode::const_iterator jter = from.codes.begin();
166
167 for (; (iter != codes.end()) && (jter != from.codes.end()); ++iter, ++jter) {
168 if ((**iter) != (**jter)) { return (**iter) < (**jter); }
169 }
170
171 return codes.size() <= from.codes.size();
172 }
173
174 } /* namespace gspan */
175 } /* namespace prm */
176} /* namespace gum */
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
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.
DFSCode()
Default constructor.
Definition DFSCode_inl.h:54
bool operator!=(const DFSCode &code) const
Difference operator.
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
Size l_i
The label of the first node in the code.
Definition edgeCode.h:103
NodeId i
The DFS subscript of the first node in the code.
Definition edgeCode.h:97
Size l_ij
The label of the edge in the code.
Definition edgeCode.h:106
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.
Size l_j
The label of the second node in the code.
Definition edgeCode.h:109