aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
PAG.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 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-2026 *
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
47#ifndef GUM_PAG_H
48#define GUM_PAG_H
49
50#include <agrum/agrum.h>
51
53
54namespace gum {
55
56 namespace dot {
57 class DotOptions;
58 } // namespace dot
59
69 enum class EdgeMark : uint8_t { Circle = 0, Tail = 1, Arrowhead = 2 };
70
71 /* =========================================================================
72 */
73 /* === PARTIAL ANCESTRAL GRAPH (PAG) ===
74 */
75 /* =========================================================================
76 */
94 class GUM_SHARED_PUBLIC PAG: public UndiGraph {
95 public:
96 // ########################################################################
98 // ########################################################################
100
101 PAG();
102 PAG(const PAG&);
103 PAG(PAG&&) noexcept;
104 ~PAG() override;
105
106 PAG& operator=(const PAG&);
107 PAG& operator=(PAG&&) noexcept;
108
110
111 // ########################################################################
113 // ########################################################################
115
117 void addEdge(NodeId x, NodeId y) override;
118
120 void addEdge(NodeId x, NodeId y, EdgeMark markAtX, EdgeMark markAtY);
121
123 void eraseEdge(const Edge& e) override;
124
126 void clearEdges() override;
127
129 void eraseNode(NodeId id) override;
130
132 void clear() override;
133
135
136 // ########################################################################
138 // ########################################################################
140
142 EdgeMark markAt(NodeId src, NodeId dst) const;
143
145 void setMarkAt(NodeId src, NodeId dst, EdgeMark m);
146
148
149 // ########################################################################
151 // ########################################################################
153
155 bool isArrowhead(NodeId src, NodeId dst) const;
156
158 bool isTail(NodeId src, NodeId dst) const;
159
161 bool isCircle(NodeId src, NodeId dst) const;
162
164 bool isDefinitelyDirected(NodeId x, NodeId y) const;
165
167 bool isBidirected(NodeId x, NodeId y) const;
168
170 bool isDefCollider(NodeId x, NodeId z, NodeId y) const;
171
173
174 // ########################################################################
176 // ########################################################################
178
181
183
184 // ########################################################################
186 // ########################################################################
188
192 MixedGraph toMixedGraph() const;
193
194 std::string toString() const override;
195 std::string toDot() const override;
196 std::string toDot(const dot::DotOptions& options) const override;
197
199
200 private:
203 };
204
205 GUM_SHARED_PUBLIC std::ostream& operator<<(std::ostream&, const PAG&);
206
207} /* namespace gum */
208
209#endif /* GUM_PAG_H */
The base class for all undirected edges.
Base class for mixed graphs.
Definition mixedGraph.h:150
Partial Ancestral Graph: undirected topology with endpoint marks.
Definition PAG.h:94
bool isCircle(NodeId src, NodeId dst) const
true if mark at dst (from src) is Circle
Definition PAG.cpp:149
bool isBidirected(NodeId x, NodeId y) const
true if edge x-y is bidirected x↔y (Arrowhead on both endpoints)
Definition PAG.cpp:156
bool isDefCollider(NodeId x, NodeId z, NodeId y) const
true if z is a definite collider on path x-z-y (Arrowhead at z from both sides)
Definition PAG.cpp:160
PAG & operator=(const PAG &)
Definition PAG.cpp:72
void clear() override
remove all nodes, edges, and marks
Definition PAG.cpp:126
void reorientAllWith(EdgeMark m)
set all endpoint marks to m (used between FCI phases to reset to Circle)
Definition PAG.cpp:169
PAG()
Definition PAG.cpp:58
ArcProperty< EdgeMark > marks_
marks_[Arc(x,y)] = mark at y-endpoint of edge x-y
Definition PAG.h:202
void addEdge(NodeId x, NodeId y) override
add edge with Circle-Circle marks
Definition PAG.cpp:92
void setMarkAt(NodeId src, NodeId dst, EdgeMark m)
set mark at dst-endpoint when traversing from src
Definition PAG.cpp:137
bool isTail(NodeId src, NodeId dst) const
true if mark at dst (from src) is Tail
Definition PAG.cpp:147
void eraseEdge(const Edge &e) override
remove edge and its two mark entries
Definition PAG.cpp:102
EdgeMark markAt(NodeId src, NodeId dst) const
mark at dst-endpoint when traversing from src
Definition PAG.cpp:135
std::string toDot() const override
approximate conversion for learnDAG/learnPDAG: Tail-Arrowhead → arc; Arrowhead-Arrowhead → two arcs; ...
Definition PAG.cpp:231
void clearEdges() override
clear all edges (and their marks)
Definition PAG.cpp:109
bool isArrowhead(NodeId src, NodeId dst) const
true if mark at dst (from src) is Arrowhead
Definition PAG.cpp:143
MixedGraph toMixedGraph() const
approximate conversion for learnDAG/learnPDAG: Tail-Arrowhead → arc; Arrowhead-Arrowhead → two arcs; ...
Definition PAG.cpp:180
bool isDefinitelyDirected(NodeId x, NodeId y) const
true if edge x-y is definitely directed x→y (Tail@x, Arrowhead@y)
Definition PAG.cpp:151
void eraseNode(NodeId id) override
remove node and clean up marks for all its adjacent edges
Definition PAG.cpp:114
std::string toString() const override
approximate conversion for learnDAG/learnPDAG: Tail-Arrowhead → arc; Arrowhead-Arrowhead → two arcs; ...
Definition PAG.cpp:216
UndiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition undiGraph.cpp:74
The options given to a toDot(const DotOptions&).
Definition dotOptions.h:110
Size NodeId
Type for node ids.
HashTable< Arc, VAL > ArcProperty
Property on graph elements.
Base classes for mixed directed/undirected graphs.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
EdgeMark
Endpoint marks used in PAG edges.
Definition PAG.h:69
@ Arrowhead
Definition PAG.h:69