33 #endif // GUM_NO_INLINE 38 ArcProperty< NodeSet >
44 for (
const auto node : *
__dag)
52 const Size non_barren = std::numeric_limits< Size >::max();
54 observed_anc.insert(node);
55 for (
Idx i = 0; i < observed_anc.size(); ++i) {
56 const NodeId node = observed_anc[i];
58 mark[node] = non_barren;
59 for (
const auto par : __dag->parents(node)) {
60 if (!mark[par] && !observed_anc.exists(par)) {
76 for (
const auto& edge : junction_tree.
edges()) {
82 if (mark[*iter] || separator.
exists(*iter)) { non_barren1.
erase(iter); }
84 result.
insert(
Arc(edge.first(), edge.second()), std::move(non_barren1));
89 if (mark[*iter] || separator.
exists(*iter)) { non_barren2.
erase(iter); }
91 result.
insert(
Arc(edge.second(), edge.first()), std::move(non_barren2));
98 for (
const auto node : *
__dag)
100 for (
const auto& elt : result) {
102 if (!result[arc].empty()) {
106 for (
const auto node : separator) {
107 node2arc[node].
insert(arc);
150 for (
const auto& elt : node2arc) {
151 if (!elt.second.empty()) {
152 nodes_to_mark.
insert(elt.first);
155 while (!nodes_to_mark.
empty()) {
162 for (
auto par : __dag->parents(node)) {
163 Size parent_mark = mark[par];
164 if (parent_mark != std::numeric_limits< Size >::max()) {
166 if (parent_mark == 0) { nodes_to_mark.
insert(par); }
170 if (nb_par == 0) { path_roots.
insert(node); }
177 for (
const auto node : *__dag) {
178 if (mark[node] != 1) { sweep_dag.
eraseNode(node); }
180 for (
const auto node : sweep_dag) {
181 const Size nb_parents = sweep_dag.parents(node).size();
182 const Size nb_children = sweep_dag.children(node).size();
183 if ((nb_parents > 1) || (nb_children > 1)) {
185 const auto& parents = sweep_dag.parents(node);
188 if (nb_children == 0) {
189 auto iter_par = parents.beginSafe();
190 for (++iter_par; iter_par != parents.endSafe(); ++iter_par) {
191 sweep_dag.eraseArc(
Arc(*iter_par, node));
195 const auto& children = sweep_dag.children(node);
196 NodeId smallest_child = 0;
197 Size smallest_nb_par = std::numeric_limits< Size >::max();
198 for (
const auto child : children) {
199 const auto new_nb = sweep_dag.parents(child).size();
200 if (new_nb < smallest_nb_par) {
201 smallest_nb_par = new_nb;
202 smallest_child = child;
208 if (nb_parents == 0) {
209 for (
auto iter = children.beginSafe(); iter != children.endSafe();
211 if (*iter != smallest_child) {
212 if (sweep_dag.parents(*iter).size() == 1) {
215 sweep_dag.eraseArc(
Arc(node, *iter));
219 auto nb_match =
Size(std::min(nb_parents, nb_children) - 1);
220 auto iter_par = parents.beginSafe();
223 auto iter_child = children.beginSafe();
224 for (
Idx i = 0; i < nb_match; ++i, ++iter_par, ++iter_child) {
225 if (*iter_child == smallest_child) { ++iter_child; }
226 sweep_dag.addArc(*iter_par, *iter_child);
227 sweep_dag.eraseArc(
Arc(*iter_par, node));
228 sweep_dag.eraseArc(
Arc(node, *iter_child));
230 for (; iter_par != parents.endSafe(); ++iter_par) {
231 sweep_dag.eraseArc(
Arc(*iter_par, node));
233 for (; iter_child != children.endSafe(); ++iter_child) {
234 if (*iter_child != smallest_child) {
235 if (sweep_dag.parents(*iter_child).size() == 1) {
236 path_roots.
insert(*iter_child);
238 sweep_dag.eraseArc(
Arc(node, *iter_child));
252 for (
NodeId path : path_roots) {
257 while (!to_mark.empty()) {
260 if (mark[node] < mark_id) {
261 mark[node] = mark_id;
262 for (
const auto par : __dag->parents(node)) {
263 if (mark[par] < mark_id) { to_mark.insert(par); }
271 const ArcSet& arcs = node2arc[path];
272 for (
const auto& arc : arcs) {
275 if (mark[*iter] >= mark_id) {
283 const NodeSet& sweep_children = sweep_dag.children(path);
284 if (sweep_children.
size()) {
285 path = *(sweep_children.
begin());
304 int nb_non_barren = 0;
306 nodes_to_examine.
insert(node);
308 nodes_to_examine.
insert(node);
310 while (!nodes_to_examine.
empty()) {
313 if (barren_mark[node]) {
314 barren_mark[node] =
false;
317 nodes_to_examine.
insert(par);
323 for (
const auto& marked_pair : barren_mark)
324 if (marked_pair.second) barren_nodes.
insert(marked_pair.first);
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
const NodeSet & separator(const Edge &edge) const
returns the separator included in a given edge
Size size() const
alias for sizeNodes
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
const NodeSet * __observed_nodes
the set of observed nodes
NodeProperty< VAL > nodesProperty(VAL(*f)(const NodeId &), Size size=0) const
a method to create a HashTable with key:NodeId and value:VAL
void erase(const Key &k)
Erases an element from the set.
Generic doubly linked lists.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
iterator begin() const
The usual unsafe begin iterator to parse the set.
void popFront()
Removes the first element of a List, if any.
NodeId head() const
returns the head of the arc
The class for generic Hash Tables.
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet barrenNodes()
returns the set of barren nodes
const NodeSet & clique(const NodeId idClique) const
returns the set of nodes included into a given clique
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
Val & front() const
Returns a reference to first element of a list, if any.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
The base class for all undirected edges.
const DAG * __dag
the DAG on which we compute the barren nodes
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
const NodeSet * __target_nodes
the set of targeted nodes
Size Idx
Type for indexes.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size size() const noexcept
Returns the number of elements in the set.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
NodeId first() const
returns one extremal node ID (whichever one it is is unspecified)
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
NodeId tail() const
returns the tail of the arc
void insert(const Key &k)
Insert an element at the end of the sequence.