49 inline void _marryParents_(
const NodeSet& parents, UndiGraph& g) {
50 for (
auto it1 = parents.begin(); it1 != parents.end(); ++it1) {
52 for (++it2; it2 != parents.end(); ++it2)
53 g.addEdge(*it1, *it2);
59 template < GUM_DiGraphable G >
62 for (
const auto node: g.nodes())
66 for (
const auto node: g.nodes()) {
67 for (
const auto p: g.parents(node))
69 for (
const auto n: g.neighbours(node))
74 for (
const auto node: g.nodes()) {
75 if (already.
contains(node))
continue;
79 NodeSet frontier = g.neighbours(node);
80 while (!frontier.
empty()) {
84 par += g.parents(nei);
85 frontier += g.neighbours(nei) - already;
88 _marryParents_(par, moral);
91 for (
const auto node: g.nodes()) {
92 const auto& par = g.parents(node);
93 for (
const auto p: par)
95 _marryParents_(par, moral);
101 template < GUM_DiGraphable G >
106 for (
const auto n: query)
109 while (!frontier.
empty()) {
111 frontier.
erase(current);
113 for (
const auto p: g.parents(current)) {
118 ancestral.
addArc(p, current);
120 for (
const auto n: g.neighbours(current)) {
134 while (!frontier.
empty()) {
136 frontier.
erase(current);
138 for (
const auto p: g.parents(current))
142 for (
const auto node: res.
nodes()) {
143 const auto& par = g.parents(node);
144 for (
const auto p: par)
146 _marryParents_(par, res);
void addArc(const NodeId tail, const NodeId head) override
insert a new arc into the directed graph
Base class for mixed graphs.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
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
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Key popFirst()
Removes and returns an arbitrary element from the set.
bool empty() const noexcept
Indicates whether the set is the empty set.
iterator begin() const
The usual unsafe begin iterator to parse the set.
void insert(const Key &k)
Inserts a new element into the 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
Concept for mixed graphs (both arcs and edges).
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Moralization algorithms for aGrUM directed and mixed graphs.
UndiGraph moralizedAncestralGraph(const G &g, const NodeSet &query)
Returns the moralized ancestral graph of query in g.
UndiGraph moralGraph(const G &g)
Returns the moral graph of g.