aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
interfaceGraph.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#ifndef GUM_INTERFACE_GRAPH_H
49#define GUM_INTERFACE_GRAPH_H
50
51#include <list>
52#include <sstream>
53#include <string>
54
55#include <agrum/PRM/PRM.h>
56
57namespace gum {
58 namespace prm {
59 template < typename GUM_SCALAR >
60 class GSpan;
61
62 namespace gspan {
63
68 struct LabelData {
70 LabelData();
72 LabelData(const LabelData& from);
74 ~LabelData();
78 std::string l;
82 bool operator==(const LabelData& from) const;
84 bool operator!=(const LabelData& from) const;
85 };
86
93 std::ostream& operator<<(std::ostream& out, const LabelData& data);
94
99 template < typename GUM_SCALAR >
100 class NodeData {
101 public:
103 NodeData();
105 NodeData(const NodeData< GUM_SCALAR >& from);
107 ~NodeData();
113 bool operator==(const NodeData< GUM_SCALAR >& from) const;
115 bool operator!=(const NodeData< GUM_SCALAR >& from) const;
116 };
117
124 template < typename GUM_SCALAR >
125 std::ostream& operator<<(std::ostream& out, const NodeData< GUM_SCALAR >& data);
126
131 template < typename GUM_SCALAR >
155
162 template < typename GUM_SCALAR >
163 std::ostream& operator<<(std::ostream& out, const EdgeData< GUM_SCALAR >& data);
164
181 template < typename GUM_SCALAR >
183 friend class gum::prm::GSpan< GUM_SCALAR >;
184
185 public:
187 explicit InterfaceGraph(const PRMSystem< GUM_SCALAR >& sys);
188
190 InterfaceGraph(const InterfaceGraph& source);
191
194
197
199 UndiGraph& graph();
200
202 const UndiGraph& graph() const;
203
207
211
213 Size size(const LabelData* l) const;
214
217
219 const Set< NodeData< GUM_SCALAR >* >& nodes(const LabelData* l) const;
220
223
225 const Set< EdgeData< GUM_SCALAR >* >& edges(const LabelData* l) const;
226
228 LabelData* label(Idx id);
229
231 NodeId id(const PRMInstance< GUM_SCALAR >& i) const;
232
234 NodeId id(const PRMInstance< GUM_SCALAR >* i) const;
235
239
243
247
250 const NodeData< GUM_SCALAR >& node(NodeId id) const;
251
255
258 const EdgeData< GUM_SCALAR >& edge(NodeId u, NodeId v) const;
259
260 private:
264
267
270
273
276
279
284
289
292
295
299
303 };
304
305
306#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
307# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
308# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
309 extern template class NodeData< double >;
310# endif
311# endif
312#endif
313#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
314# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
315# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
316 extern template class EdgeData< double >;
317# endif
318# endif
319#endif
320#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
321# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
322# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
323 extern template class InterfaceGraph< double >;
324# endif
325# endif
326#endif
327
328
329 } /* namespace gspan */
330 } /* namespace prm */
331} /* namespace gum */
332
334
335#endif /* GUM_INTERFACE_GRAPH_H */
Headers of PRM.
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1594
The class for generic Hash Tables.
Definition hashTable.h:637
Representation of a set.
Definition set.h:131
Base class for undirected graphs.
Definition undiGraph.h:128
This class discovers pattern in a PRM<GUM_SCALAR>'s PRMSystem<GUM_SCALAR> to speed up structured infe...
Definition gspan.h:86
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
Definition PRMInstance.h:79
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition PRMSystem.h:70
Inner class to handle data about edges in graph.
bool operator==(const EdgeData< GUM_SCALAR > &from) const
Equality operator.
PRMInstance< GUM_SCALAR > * v
The other instance represented by thus edge.
PRMInstance< GUM_SCALAR > * u
One of the two instance represented by this edge.
LabelData * l_u
The label data of u.
LabelData * l
The labal data of this edge.
bool operator!=(const EdgeData< GUM_SCALAR > &from) const
Difference operator.
LabelData * l_v
The label data of v.
This class represent the interface graph of a given gum::prm::PRMSystem<GUM_SCALAR>.
const PRMSystem< GUM_SCALAR > * _sys_
The gum::prm::PRMSystem<GUM_SCALAR> represented by this interface graph.
NodeProperty< NodeData< GUM_SCALAR > * > _nodes_
Data associated with a node in graph.
Size size(const LabelData *l) const
Returns the number of node or edges labelled by l.
Bijection< Idx, LabelData * > & labels()
Returns the bijection between LabelData and their string representation.
UndiGraph _graph_
The interface graph.
InterfaceGraph & operator=(const InterfaceGraph &source)
Copy operator.
Idx _counter_
A counter used of assigning ids to labels.
InterfaceGraph(const PRMSystem< GUM_SCALAR > &sys)
Default constructor.
NodeId id(const PRMInstance< GUM_SCALAR > &i) const
Returns the id of i in this interface graph.
HashTable< LabelData *, Set< NodeData< GUM_SCALAR > * > * > _nodeMap_
Mapping between a LabelData and the set of NodeData<GUM_SCALAR> with that label.
EdgeData< GUM_SCALAR > & edge(NodeId u, NodeId v)
Returns data about an edge.
Set< NodeData< GUM_SCALAR > * > & nodes(const LabelData *l)
Returns the set of nodes labelled by l.
EdgeProperty< EdgeData< GUM_SCALAR > * > _edges_
Data associated with edges in graph.
bool _erase_flag_
For shallow copies.
HashTable< LabelData *, Set< EdgeData< GUM_SCALAR > * > * > _edgeMap_
Mapping between a LabelData and the set of EdgeData<GUM_SCALAR> with that label.
void _label_(NodeData< GUM_SCALAR > *node, HashTable< std::string, LabelData * > &label_map)
Compute the label of node and add it to labels if it does not exists yet. Update node with the correc...
UndiGraph & graph()
Returns the graph of this interface graph.
NodeData< GUM_SCALAR > & node(const PRMInstance< GUM_SCALAR > *i)
Returns data about a node.
LabelData * label(Idx id)
Returns a label given its id.
Bijection< Idx, LabelData * > * _labels_
Bijection between labels and their ids.
Set< EdgeData< GUM_SCALAR > * > & edges(const LabelData *l)
Returns the set of nodes labelled by l.
HashTable< PRMInstance< GUM_SCALAR > *, NodeId > _idMap_
Mapping between PRMInstance<GUM_SCALAR> dans their id in graph.
Inner class to handle data about nodes in graph.
PRMInstance< GUM_SCALAR > * n
The instance represented by this node.
bool operator==(const NodeData< GUM_SCALAR > &from) const
Equality operator.
bool operator!=(const NodeData< GUM_SCALAR > &from) const
Difference operator.
LabelData * l
The label of this node.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.
HashTable< Edge, VAL > EdgeProperty
Property on graph elements.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Inline implementation of gum::InterfaceGraph.
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
Inner class to handle data about labels in this interface graph.
bool operator==(const LabelData &from) const
Equality operator.
Idx id
An unique identifier for this label.
bool operator!=(const LabelData &from) const
Difference operator.
Size tree_width
The size in terms of tree width of the given label.
std::string l
The string version of this label.