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());
119 for (
const auto& c: mg.
parents(a)) {
120 if (!mg.
existsArc(c, b)) {
return true; }
124 for (
const auto& c: mg.
parents(b)) {
125 if (c == a) {
continue; }
134 bool oneFound =
false;
135 for (
const auto& c: mg.
parents(b)) {
136 if (c == a) {
continue; }
150 std::stringstream output;
151 std::stringstream nodeStream;
152 std::stringstream edgeStream;
154 output <<
"digraph \""
155 <<
"no_name\" {" << std::endl;
156 nodeStream <<
"node [shape = ellipse];" << std::endl;
157 std::string tab =
" ";
159 for (
const auto node:
_pdag_.nodes()) {
160 nodeStream << tab << node <<
"[label=\"" <<
_dagmodel_->variable(node).name() <<
"\"];";
162 for (
const auto nei:
_pdag_.neighbours(node))
163 if (!treatedNodes.
exists(nei))
164 edgeStream << tab << node <<
" -> " << nei <<
" [dir=none];" << std::endl;
166 for (
const auto chi:
_pdag_.children(node))
167 edgeStream << tab << node <<
" -> " << chi <<
" [color=red];" << std::endl;
169 treatedNodes.
insert(node);
172 output << nodeStream.str() << std::endl << edgeStream.str() << std::endl <<
"}" << std::endl;
179 for (
const auto& n:
nodes())
181 for (
const auto& edge:
edges())
182 skel.
addEdge(edge.first(), edge.second());
183 for (
const auto& arc:
arcs())
184 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 children of a set of nodes
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.
virtual void addArc(const NodeId tail, const NodeId head)
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.
bool exists(const Val &val) const
Checks whether there exists a given element in the list.
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Base class for mixed graphs.
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