aGrUM 3.0.0
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
65 enum class EdgeMark : uint8_t { Circle = 0, Tail = 1, Arrowhead = 2 };
66
67 /* =========================================================================
68 */
69 /* === PARTIAL ANCESTRAL GRAPH (PAG) ===
70 */
71 /* =========================================================================
72 */
90 class PAG: public UndiGraph {
91 public:
92 // ########################################################################
94 // ########################################################################
96
97 PAG();
98 PAG(const PAG&);
99 PAG(PAG&&) noexcept;
100 ~PAG() override;
101
102 PAG& operator=(const PAG&);
103 PAG& operator=(PAG&&) noexcept;
104
106
107 // ########################################################################
109 // ########################################################################
111
113 void addEdge(NodeId x, NodeId y) override;
114
116 void addEdge(NodeId x, NodeId y, EdgeMark markAtX, EdgeMark markAtY);
117
119 void eraseEdge(const Edge& e) override;
120
122 void clearEdges() override;
123
125 void eraseNode(NodeId id) override;
126
128 void clear() override;
129
131
132 // ########################################################################
134 // ########################################################################
136
138 EdgeMark markAt(NodeId src, NodeId dst) const;
139
141 void setMarkAt(NodeId src, NodeId dst, EdgeMark m);
142
144
145 // ########################################################################
147 // ########################################################################
149
151 bool isArrowhead(NodeId src, NodeId dst) const;
152
154 bool isTail(NodeId src, NodeId dst) const;
155
157 bool isCircle(NodeId src, NodeId dst) const;
158
160 bool isDefinitelyDirected(NodeId x, NodeId y) const;
161
163 bool isBidirected(NodeId x, NodeId y) const;
164
166 bool isDefCollider(NodeId x, NodeId z, NodeId y) const;
167
169
170 // ########################################################################
172 // ########################################################################
174
177
179
180 // ########################################################################
182 // ########################################################################
184
188 MixedGraph toMixedGraph() const;
189
190 std::string toString() const override;
191 std::string toDot() const override;
192
194
195 private:
198 };
199
200 std::ostream& operator<<(std::ostream&, const PAG&);
201
202} /* namespace gum */
203
204#endif /* GUM_PAG_H */
The base class for all undirected edges.
Base class for mixed graphs.
Definition mixedGraph.h:146
Partial Ancestral Graph: undirected topology with endpoint marks.
Definition PAG.h:90
bool isCircle(NodeId src, NodeId dst) const
true if mark at dst (from src) is Circle
Definition PAG.cpp:148
bool isBidirected(NodeId x, NodeId y) const
true if edge x-y is bidirected x↔y (Arrowhead on both endpoints)
Definition PAG.cpp:155
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:159
PAG & operator=(const PAG &)
Definition PAG.cpp:71
void clear() override
remove all nodes, edges, and marks
Definition PAG.cpp:125
void reorientAllWith(EdgeMark m)
set all endpoint marks to m (used between FCI phases to reset to Circle)
Definition PAG.cpp:168
PAG()
Definition PAG.cpp:57
ArcProperty< EdgeMark > marks_
marks_[Arc(x,y)] = mark at y-endpoint of edge x-y
Definition PAG.h:197
void addEdge(NodeId x, NodeId y) override
add edge with Circle-Circle marks
Definition PAG.cpp:91
void setMarkAt(NodeId src, NodeId dst, EdgeMark m)
set mark at dst-endpoint when traversing from src
Definition PAG.cpp:136
bool isTail(NodeId src, NodeId dst) const
true if mark at dst (from src) is Tail
Definition PAG.cpp:146
void eraseEdge(const Edge &e) override
remove edge and its two mark entries
Definition PAG.cpp:101
EdgeMark markAt(NodeId src, NodeId dst) const
mark at dst-endpoint when traversing from src
Definition PAG.cpp:134
std::string toDot() const override
approximate conversion for learnDAG/learnPDAG: Tail-Arrowhead → arc; Arrowhead-Arrowhead → two arcs; ...
Definition PAG.cpp:230
void clearEdges() override
clear all edges (and their marks)
Definition PAG.cpp:108
bool isArrowhead(NodeId src, NodeId dst) const
true if mark at dst (from src) is Arrowhead
Definition PAG.cpp:142
~PAG() override
Definition PAG.cpp:69
MixedGraph toMixedGraph() const
approximate conversion for learnDAG/learnPDAG: Tail-Arrowhead → arc; Arrowhead-Arrowhead → two arcs; ...
Definition PAG.cpp:179
bool isDefinitelyDirected(NodeId x, NodeId y) const
true if edge x-y is definitely directed x→y (Tail@x, Arrowhead@y)
Definition PAG.cpp:150
void eraseNode(NodeId id) override
remove node and clean up marks for all its adjacent edges
Definition PAG.cpp:113
std::string toString() const override
approximate conversion for learnDAG/learnPDAG: Tail-Arrowhead → arc; Arrowhead-Arrowhead → two arcs; ...
Definition PAG.cpp:215
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:73
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:65
@ Arrowhead
Definition PAG.h:65