aGrUM  0.14.2
DFSCode_inl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 namespace gum {
28  namespace prm {
29  namespace gspan {
30 
31  INLINE
32  DFSCode::DFSCode() { GUM_CONSTRUCTOR(DFSCode); }
33 
34  INLINE
35  DFSCode::DFSCode(const DFSCode& source) {
36  GUM_CONS_CPY(DFSCode);
37 
38  for (const auto code : source.codes)
39  codes.push_back(new EdgeCode(*code));
40  }
41 
42  INLINE
44  GUM_DESTRUCTOR(DFSCode);
45 
46  for (const auto item : codes)
47  delete item;
48  }
49 
50  INLINE
52  for (const auto item : codes)
53  delete item;
54 
55  for (const auto srcitem : source.codes)
56  codes.push_back(new EdgeCode(*srcitem));
57 
58  return *this;
59  }
60 
61  INLINE
62  bool DFSCode::operator==(const DFSCode& from) const {
63  if (codes.size() == from.codes.size()) {
64  for (size_t idx = 0; idx < codes.size(); ++idx) {
65  if ((*codes[idx]) != (*codes[idx])) { return false; }
66  }
67 
68  return true;
69  } else {
70  return false;
71  }
72  }
73 
74  INLINE
75  bool DFSCode::operator!=(const DFSCode& from) const {
76  if (codes.size() == from.codes.size()) {
77  for (size_t idx = 0; idx < codes.size(); ++idx) {
78  if ((*codes[idx]) != (*codes[idx])) { return true; }
79  }
80 
81  return false;
82  } else {
83  return true;
84  }
85  }
86 
87  INLINE
88  bool DFSCode::operator<(const DFSCode& from) const {
89  DFSCode::const_iterator iter = codes.begin();
90  DFSCode::const_iterator jter = from.codes.begin();
91 
92  for (; (iter != codes.end()) && (jter != from.codes.end());
93  ++iter, ++jter) {
94  if ((**iter) != (**jter)) {
95  EdgeCode& alpha = **iter;
96  EdgeCode& beta = **jter;
97 
98  if (alpha.isBackward()) {
99  if (beta.isForward()) {
100  return true;
101  } else if (alpha.j < beta.j) {
102  // beta is a backward edge
103  return true;
104  } else if ((alpha.j == beta.j) && (alpha.l_ij < beta.l_ij)) {
105  return true;
106  }
107 
108  return false;
109  } else {
110  // alpha is a forward edge
111  if (beta.isBackward()) {
112  return false;
113  } else if (beta.i < alpha.i) {
114  // Beta is a forward edge
115  return true;
116  } else if (beta.i == alpha.i) {
117  if (alpha.l_i < beta.l_i) {
118  return true;
119  } else if (alpha.l_i == beta.l_i) {
120  if (alpha.l_ij < beta.l_ij) {
121  return true;
122  } else if (alpha.l_ij == beta.l_ij) {
123  return alpha.l_j < beta.l_j;
124  }
125  }
126  }
127 
128  return false;
129  }
130 
131  return (**iter) < (**jter);
132  }
133  }
134 
135  return false;
136  }
137 
138  INLINE
139  bool DFSCode::operator<=(const DFSCode& from) const {
140  DFSCode::const_iterator iter = codes.begin();
141  DFSCode::const_iterator jter = from.codes.begin();
142 
143  for (; (iter != codes.end()) && (jter != from.codes.end());
144  ++iter, ++jter) {
145  if ((**iter) != (**jter)) { return (**iter) < (**jter); }
146  }
147 
148  return codes.size() <= from.codes.size();
149  }
150 
151  } /* namespace gspan */
152  } /* namespace prm */
153 } /* namespace gum */
bool operator<(const DFSCode &code) const
Lesser than operator.
Definition: DFSCode_inl.h:88
NodeId i
The DFS subscript of the first node in the code.
Definition: edgeCode.h:74
bool operator==(const DFSCode &code) const
Equality operator.
Definition: DFSCode_inl.h:62
bool operator<=(const DFSCode &code) const
Lesser or equal than operator.
Definition: DFSCode_inl.h:139
NodeId j
The DFS subscript of the second node in the code.
Definition: edgeCode.h:77
Reprensent a Depth First Search coding of a graph.
Definition: DFSCode.h:50
Size l_ij
The label of the edge in the code.
Definition: edgeCode.h:83
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
DFSCode & operator=(const DFSCode &source)
Copy operator.
Definition: DFSCode_inl.h:51
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:87
represent a DFS code used by gspan.
Definition: edgeCode.h:49
bool isBackward() const
Returns true if this EdgeCode is a backward edge.
Definition: edgeCode_inl.h:56
bool operator!=(const DFSCode &code) const
Difference operator.
Definition: DFSCode_inl.h:75
Size l_j
The label of the second node in the code.
Definition: edgeCode.h:86
bool isForward() const
Returns true if this EdgeCode is a forward edge.
Definition: edgeCode_inl.h:53
DFSCode()
Default constructor.
Definition: DFSCode_inl.h:32
~DFSCode()
Destructor.
Definition: DFSCode_inl.h:43
std::vector< EdgeCode *>::const_iterator const_iterator
Code alias.
Definition: DFSCode.h:128
Size l_i
The label of the first node in the code.
Definition: edgeCode.h:80