57 DAG::DAG(
Size nodes_size,
bool nodes_resize_policy,
Size arcs_size,
bool arcs_resize_policy) :
59 DiGraph(nodes_size, nodes_resize_policy, arcs_size, arcs_resize_policy) {
72 for (
const auto& arc:
arcs())
73 moralgraph.
addEdge(arc.first(), arc.second());
76 for (
const auto node:
nodes()) {
77 const auto& par =
parents(node);
79 for (
auto it1 = par.begin(); it1 != par.end(); ++it1) {
82 for (++it2; it2 != par.end(); ++it2) {
96 while (!tmp.
empty()) {
97 auto current = *(tmp.
begin());
101 for (
auto next:
parents(current))
106 for (
auto current: res)
107 for (
auto father:
parents(current)) {
110 for (
auto other_father:
parents(current))
111 if (other_father != father) res.
addEdge(father, other_father);
123 return !g.hasUndirectedPath(X, Y);
127 if (!(X * Y).
empty())
136 auto cc = g.nodes2ConnectedComponent();
139 for (
const auto node: X)
140 if (g.existsNode(node))
142 for (
const auto node: Y)
143 if (g.existsNode(node))
146 return (Xcc * Ycc).empty();
154 NodeSet& alreadyVisitedDn)
const {
155 if (alreadyVisitedUp.
contains(node))
return;
156 alreadyVisitedUp << node;
173 NodeSet& alreadyVisitedDn)
const {
174 if (alreadyVisitedDn.
contains(node))
return;
175 alreadyVisitedDn << node;
193 alreadyVisitedDn << target;
194 alreadyVisitedUp << target;
196 for (
auto fath:
parents(target))
205 for (
auto node: targets) {
Base classes for 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
bool dSeparation(NodeId X, NodeId Y, const NodeSet &Z) const
check if node X and node Y are independent given nodes Z (in the sense of d-separation)
void _minimalCondSetVisitUp_(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
void _minimalCondSetVisitDn_(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
UndiGraph moralGraph() const
build a UndiGraph by moralizing the dag
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const
DAG(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
UndiGraph moralizedAncestralGraph(const NodeSet &nodes) const
build a UndiGraph by moralizing the Ancestral Graph of a set of Nodes
DiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
Exception: at least one argument passed to a function is not what was expected.
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 exists(const NodeId id) const
alias for existsNode
bool empty() const
alias for emptyNodes
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
iterator begin() const
The usual unsafe begin iterator to parse the set.
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.
bool empty() const noexcept
Indicates whether the set is the empty set.
void erase(const Key &k)
Erases an element from 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