82 _pdag_.addNodeWithId(node);
85 mg.
addArc(arc.tail(), arc.head());
91 for (
const auto x:
_dagmodel_->topologicalOrder())
95 for (
const auto& arc: v) {
97 mg.
addEdge(arc.tail(), arc.head());
101 for (
const auto& arc: mg.
arcs()) {
102 _pdag_.addArc(arc.tail(), arc.head());
104 for (
const auto& edge: mg.
edges()) {
105 _pdag_.addEdge(edge.first(), edge.second());
122 for (
const auto& c: mg.
parents(a)) {
123 if (!mg.
existsArc(c, b)) {
return true; }
127 for (
const auto& c: mg.
parents(b)) {
128 if (c == a) {
continue; }
137 bool oneFound =
false;
138 for (
const auto& c: mg.
parents(b)) {
139 if (c == a) {
continue; }
153 std::stringstream output;
154 std::stringstream nodeStream;
155 std::stringstream edgeStream;
157 output <<
"digraph \"no_name\" {\n";
158 nodeStream <<
"node [shape = ellipse];\n";
159 std::string tab =
" ";
161 for (
const auto node:
_pdag_.nodes()) {
162 nodeStream << std::format(
"{}{}[label=\"{}\"];",
167 for (
const auto nei:
_pdag_.neighbours(node))
168 if (!treatedNodes.
exists(nei))
169 edgeStream << std::format(
"{}{} -> {} [dir=none];\n", tab, node, nei);
171 for (
const auto chi:
_pdag_.children(node))
172 edgeStream << std::format(
"{}{} -> {} [color=red];\n", tab, node, chi);
174 treatedNodes.
insert(node);
177 output << nodeStream.str() <<
'\n' << edgeStream.str() <<
'\n' <<
"}\n";
184 for (
const auto& n:
nodes())
186 for (
const auto& edge:
edges())
187 skel.
addEdge(edge.first(), edge.second());
188 for (
const auto& arc:
arcs())
189 skel.
addEdge(arc.tail(), arc.head());
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
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 nodes which consists in the node and its parents returns the set of children of a ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
Virtual base class for PGMs using a DAG.
void addArc(const NodeId tail, const NodeId head) override
insert a new arc into the directed graph
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
const ArcSet & arcs() const
wrapping MixedGraph::arcs()
const DAGmodel * _dagmodel_
UndiGraph skeleton() const
const NodeGraphPart & nodes() const
wrapping MixedGraph::nodes()
void _buildEssentialGraph_()
EssentialGraph & operator=(const EssentialGraph &g)
bool _strongly_protected_(NodeId a, NodeId b) const
std::string toDot() const
const EdgeSet & edges() const
wrapping MixedGraph::edges()
Generic doubly linked lists.
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
bool exists(const Val &val) const
Checks whether there exists a given element in the list.
Base class for mixed graphs.
void setName(NodeId id, const std::string &name)
sets the name of node id
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
Base class for partially directed acyclic graphs.
Base class for undirected graphs.
void addEdge(NodeId first, NodeId second) override
insert a new edge into the undirected graph
Class building the essential Graph from a DAGmodel.
Inline implementation of the class building the essential Graph from a DAGmodel.
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities