76 for (
auto node: graph) {
80 pdag.
addEdge(edge.first(), edge.second());
82 for (
const Arc& arc: graph.
arcs()) {
83 pdag.
addArc(arc.tail(), arc.head());
102 for (
auto node: graph.
nodes()) {
105 for (
const Arc& arc: graph.
arcs()) {
106 dag.
addArc(arc.tail(), arc.head());
128 bool withdrawFlag_L =
false;
129 for (
auto arc:
ArcSet(L)) {
132 bool withdrawFlag_arc =
false;
135 if (tail_head && !head_tail) {
138 withdrawFlag_arc =
true;
141 }
else if (!tail_head && head_tail) {
144 withdrawFlag_arc =
true;
147 }
else if (!tail_head && !head_tail) {
151 withdrawFlag_arc =
true;
155 if (withdrawFlag_arc) {
157 withdrawFlag_L =
true;
161 if (L.
empty()) {
break; }
166 if (!withdrawFlag_L) {
180 bool newOrientation =
true;
181 while (newOrientation) {
182 newOrientation =
false;
192 bool newOrientation =
true;
193 while (newOrientation) {
194 newOrientation =
false;
209 for (
auto& xi: neighbours) {
271 for (
const auto p: graph.
parents(xj)) {
287 const auto& edge = *(essentialGraph.
edges().begin());
288 NodeId root = edge.first();
294 while (!stack.
empty()) {
297 if (visited.
contains(next))
continue;
298 if (essentialGraph.
children(next).
size() > size_children_root) {
299 size_children_root = essentialGraph.
children(next).
size();
302 for (
const auto n: essentialGraph.
neighbours(next))
311 while (!stack.
empty()) {
316 if (visited.
contains(next))
continue;
317 const auto nei = essentialGraph.
neighbours(next);
318 for (
const auto n: nei) {
329 essentialGraph.
addArc(n, next);
351 while (!nodeFIFO.
empty()) {
352 current = nodeFIFO.
front();
356 for (
const auto new_one: graph.
parents(current)) {
361 if (new_one == n1) {
return true; }
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
The base class for all directed edges.
void addArc(NodeId tail, NodeId head) final
insert a new arc into the directed graph
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
virtual void eraseEdge(const Edge &edge)
removes an edge from the EdgeGraphPart
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
The base class for all undirected edges.
Generic doubly linked lists.
Val & front() const
Returns a reference to first element of a list, if any.
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
void popFront()
Removes the first element of a List, if any.
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
MixedGraph _propagates_(const MixedGraph &graph)
PDAG propagateToCPDAG(const MixedGraph &mg)
Propagates the orientation of a MixedGraph (no double-headed arcs) and return a PDAG.
gum::Arc _critereMinParents_(const gum::MixedGraph &graph, gum::NodeId x, gum::NodeId y)
When resolving double-headed arcs, prioritize selecting the option that minimizes the number of paren...
MixedGraph propagate(const MixedGraph &mg)
Propagates the orientation of a MixedGraph (no double-headed arcs) and return a PDAG.
std::vector< Arc > _choices_
static bool _existsDirectedPath_(const MixedGraph &graph, NodeId n1, NodeId n2)
bool _applyMeekRules_(MixedGraph &graph, NodeId xj)
Propagates the orientation from a node to its neighbours.
virtual ~MeekRules()
destructor
void _complete_(MixedGraph &graph)
bool _isOrientable_(const gum::MixedGraph &graph, gum::NodeId xi, gum::NodeId xj) const
void _propagatesOrientationInChainOfRemainingEdges_(gum::MixedGraph &graph)
heuristic for remaining edges when everything else has been tried
void _orientDoubleHeadedArcs_(MixedGraph &mg)
Tells us if we can orient the edge xi - xj to xi -> xj.
DAG propagateToDAG(const MixedGraph &mg)
Propagates the orientation of a MixedGraph and completes it as a DAG.
MeekRules()
default constructor
Base class for mixed graphs.
NodeSet boundary(NodeId node) const
returns the set of node adjacent to a given node
std::vector< NodeId > mixedOrientedPath(NodeId node1, NodeId node2) const
returns a mixed edge/directed arc path from node1 to node2 in the arc/edge set
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
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
void addArc(NodeId tail, NodeId head) final
insert a new arc into the directed graph
iterator begin() const
The usual unsafe begin iterator to parse the set.
Size size() const noexcept
Returns the number of elements in 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.
void clear()
Removes all the elements, if any, from the set.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities