58 bool nodes_resize_policy,
60 bool arcs_resize_policy,
62 bool edges_resize_policy) :
68 edges_resize_policy) {
69 GUM_CONSTRUCTOR(
PDAG);
86 for (
const auto& arc:
edges())
87 mg.
addEdge(arc.first(), arc.second());
88 for (
const auto& arc:
arcs())
89 mg.
addEdge(arc.first(), arc.second());
93 for (
const auto node:
nodes()) {
94 if (already.
contains(node))
continue;
100 const auto nei = cc.popFirst();
101 if (already.
contains(nei))
continue;
108 for (
auto it1 = par.begin(); it1 != par.end(); ++it1) {
110 for (++it2; it2 != par.end(); ++it2) {
123 bool alreadyOriented) {
124 if (node == goal)
return alreadyOriented;
125 if (marked.
contains(node))
return false;
127 for (
const auto nod: gr.
children(node))
135 if (n1 == n2)
return false;
137 for (
const auto nod: this->
children(n1))
147 for (
const auto par: graph.
parents(nod)) {
152 ancestral.
addArc(par, nod);
165 for (
const auto n:
nodes) {
181 return !g.hasUndirectedPath(X, Y);
185 if (!(X * Y).
empty())
194 auto cc = g.nodes2ConnectedComponent();
198 for (
const auto node: X)
199 if (g.existsNode(node) && !Xcc.
exists(cc[node]))
201 for (
const auto node: Y)
202 if (g.existsNode(node) && !Ycc.
exists(cc[node]))
204 return (Xcc * Ycc).empty();
208 std::stringstream output;
210 output <<
"digraph \""
211 <<
"no_name\" {" << std::endl;
213 std::string tab =
" ";
214 output << tab <<
"rankdir = TD;" << std::endl;
215 output << tab <<
"node [style=filled,fillcolor=white,color=black];" << std::endl;
216 output << tab <<
"graph [style=filled,color=\"#F5F5F5\"];" << std::endl;
219 for (
const auto node:
nodes()) {
221 output << tab << node <<
";" << std::endl;
222 treatedNodes.
insert(node);
228 for (
const auto node:
nodes()) {
229 if (!treatedNodes.
exists(node)) {
230 output << tab <<
"subgraph cluster_" << cluster++ <<
"{{" << std::endl;
231 output << tab << tab <<
"rank=same;" << std::endl << tab << tab;
236 output << std::endl << tab <<
"}}" << std::endl << std::endl;
240 for (
const auto node:
nodes()) {
241 for (
const auto child:
children(node)) {
242 output << tab << node <<
"->" << child <<
";\n";
245 output << std::endl << tab <<
"edge [dir=none];" << std::endl;
247 for (
const auto node:
nodes()) {
249 if (other > node) output << tab << node <<
"->" << other <<
";\n";
Base classes for partially directed acyclic graphs.
Inline implementation of Base classes for directed acylic graphs.
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
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
const NodeSet & neighbours(NodeId id) const
returns the set of node neighbours to a given node
Exception: at least one argument passed to a function is not what was expected.
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).
NodeSet chainComponent(NodeId node) const
returns the set of nodes reachable by undirected path
MixedGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Class for node sets in graph.
void populateNodes(const NodeGraphPart &s)
populateNodes clears *this and fills it with the same nodes as "s"
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
bool empty() const
alias for emptyNodes
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
Base class for partially directed acyclic graphs.
void addEdge(NodeId first, NodeId second) final
insert a new edge into the partially directed graph
std::string toDot() const override
to friendly display mixed graph in DOT format
void addArc(NodeId tail, NodeId head) final
insert a new arc into the directed graph
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
PDAG(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
UndiGraph moralGraph() const
build a UndiGraph by moralizing the PDAG
bool hasMixedReallyOrientedPath(NodeId n1, NodeId n2) const
returns true if a mixed edge/directed arc path from node1 to node2 in the arc/edge set exists with at...
bool cSeparation(NodeId X, NodeId Y, const NodeSet &Z) const
check if node X and node Y are independent given nodes Z (in the sense of c-separation)
virtual ~PDAG()
destructor
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
void insert(const Key &k)
Inserts a new element into the set.
Base class for undirected graphs.
void addEdge(NodeId first, NodeId second) override
insert a new edge into the undirected graph
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
void rec_ancestral(const PDAG &graph, PDAG &ancestral, NodeId nod)
bool rec_hasMixedReallyOrientedPath(const PDAG &gr, NodeSet &marked, NodeId node, NodeId goal, bool alreadyOriented)