aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
pattern.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#ifndef GUM_PATTERN_H
50#define GUM_PATTERN_H
51
52#include <agrum/agrum.h>
53
56
57namespace gum {
58 namespace prm {
59 namespace gspan {
60
61 class NeighborIterator;
62
90 class Pattern: private DiGraph {
91 public:
92 // =========================================================================
94 // ==========================================================================
96
98 Pattern();
99
101 Pattern(const Pattern& source);
102
104 ~Pattern();
105
107 // =========================================================================
109 // ==========================================================================
111
117
119 LabelData& label(NodeId node);
120
122 const LabelData& label(NodeId node) const;
123
126
128 const LabelData& label(NodeId i, NodeId j) const;
129
131 LabelData& label(const Arc& arc);
132
134 const LabelData& label(const Arc& arc) const;
135
136 // Returns the last added LabelData.
138
139 // Returns the last added LabelData.
140 const LabelData& lastAdded() const;
141
155 void addArc(NodeId i, NodeId j, LabelData& l);
156
158 bool exists(NodeId id) const;
159
161 bool exists(NodeId tail, NodeId head) const;
162
164 Size size() const;
165
167 Size sizeArcs() const;
168
171 void rightmostPath(std::list< NodeId >& r_path) const;
172
174 std::string toDot(size_t name) const;
175
177 // =========================================================================
179 // ==========================================================================
181 const NodeGraphPart& nodes() const;
182
183 const ArcSet& arcs() const;
184
186 // =========================================================================
188 // ==========================================================================
190
192 DFSCode& code();
193
195 const DFSCode& code() const;
196
198 EdgeCode& edgeCode(NodeId tail, NodeId head);
199
201 EdgeCode& edgeCode(const Arc& arc);
202
204 const EdgeCode& edgeCode(NodeId tail, NodeId head) const;
205
207 const EdgeCode& edgeCode(const Arc& arc) const;
208
210 void pop_back();
211
214 void remove(NodeId node);
215
216 bool isMinimal();
217
219
220 private:
223
227
231
233 LabelData* _last_ = nullptr;
234
246
253 bool _rec_(Pattern& p, Bijection< NodeId, NodeId >& node_map, NodeId u, NodeId v);
254
257
258 // to avoid clang++ warnings
259 using DiGraph::addNode;
260 using DiGraph::addArc;
261 using DiGraph::toDot;
262 using DiGraph::parents;
263 using DiGraph::children;
264 };
265 } /* namespace gspan */
266 } /* namespace prm */
267} /* namespace gum */
268#ifndef GUM_NO_INLINE
270#endif // GUM_NO_INLINE
271
272#endif /* GUM_PATTERN_H */
Headers of a DFSCode.
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
The base class for all directed edges.
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1594
virtual std::string toDot() const
to friendly display the content of the graph in the DOT syntax
Definition diGraph.cpp:88
DiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
Definition diGraph.cpp:69
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition diGraph_inl.h:55
virtual NodeId addNode()
insert a new node and return its id
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
Reprensent a Depth First Search coding of a graph.
Definition DFSCode.h:72
bool _expandCodeIsMinimal_(NodeId u, NodeId v)
Returns true if the expand code by adding and edge betwenne u and v is minimal with respect to code.
Definition pattern.cpp:114
void rightmostPath(std::list< NodeId > &r_path) const
Fill r_path with the rightmost path of this Pattern. The list is supposed empty.
const ArcSet & arcs() const
NodeProperty< LabelData * > _node_map_
Mapping between nodes in this Pattern and their respective LabelData.
Definition pattern.h:226
bool isMinimal()
Returns the DFSCode of this Pattern.
Definition pattern.cpp:71
LabelData * _last_
The last LabelData added to this pattern.
Definition pattern.h:233
NodeId addNodeWithLabel(LabelData &l)
Insert a node with the given LabelData.
Definition pattern_inl.h:66
Size size() const
Returns the number of nodes in this Pattern.
virtual std::string toDot() const
to friendly display the content of the graph in the DOT syntax
Definition diGraph.cpp:88
void pop_back()
Remove the last EdgeCode of this pattern.
DFSCode & code()
Returns the DFSCode of this Pattern.
ArcProperty< std::pair< LabelData *, EdgeCode * > > _arc_map_
Mapping between edges in this Pattern and their respective LabelData.
Definition pattern.h:230
Size sizeArcs() const
Returns the number of arcs in this Pattern.
DFSCode _code_
The DFSCode of this Pattern.
Definition pattern.h:222
Pattern()
Default constructor.
Definition pattern_inl.h:54
void remove(NodeId node)
Remove a node if it has no neighbors, raise an OperationNotAllowed otherwise.
void addArc(NodeId i, NodeId j, LabelData &l)
Add an arc to this Pattern.
bool exists(NodeId id) const
Returns true if id is a node in this Pattern.
const NodeGraphPart & nodes() const
LabelData & lastAdded()
Insert a node with the given LabelData.
Definition pattern_inl.h:89
bool _rec_(Pattern &p, Bijection< NodeId, NodeId > &node_map, NodeId u, NodeId v)
Recurisve method used by expandCodeIsMinimal.
Definition pattern.cpp:143
LabelData & label(NodeId node)
Returns the LabelData assigned to node.
Definition pattern_inl.h:75
bool _not_rec_(Pattern &p, Bijection< NodeId, NodeId > &node_map, NodeId u, NodeId v)
A non recursive bugged version of rec.
Definition pattern.cpp:200
EdgeCode & edgeCode(NodeId tail, NodeId head)
Returns the EdgeCode of an edge of this Pattern.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
HashTable< Arc, VAL > ArcProperty
Property on graph elements.
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Headers of InterfaceGraph.
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Inline implementation of the Pattern class.
represent a DFS code used by gspan.
Definition edgeCode.h:72
Inner class to handle data about labels in this interface graph.