38 #endif // GUM_NOINLINE 51 for (
const auto node : dag) {
52 Size nb_ch = dag.children(node).
size();
53 nb_children.
insert(node, nb_ch);
55 if (!nb_ch) leaves.
insert(node);
57 Size nb_pa = dag.parents(node).size();
58 nb_parents.
insert(node, nb_pa);
60 if (!nb_pa) roots.
insert(node);
71 while (!roots.
empty()) {
75 node_ancestors.
insert(node, 1);
76 const NodeSet& node_children = dag.children(node);
79 for (
const auto ch : node_children) {
83 if (!nb_parents[ch]) { roots.
insert(ch); }
90 for (
const auto node : dag) {
94 while (!leaves.
empty()) {
98 node_descendants.
insert(node, 1);
99 const NodeSet& node_parents = dag.parents(node);
102 for (
const auto pa : node_parents) {
106 if (!nb_children[pa]) { leaves.
insert(pa); }
113 const std::vector< Change >& modifs)
const {
121 for (
const auto& modif : modifs) {
122 Arc arc(modif.tail(), modif.head());
124 switch (modif.type()) {
126 if (deletions.
exists(arc))
134 if (modif.tail() == modif.head())
return true;
136 if (additions.
exists(arc))
144 if (deletions.
exists(arc))
149 arc =
Arc(modif.head(), modif.tail());
151 if (additions.
exists(arc))
165 if (deletions.
exists(iter.key())) {
166 Size& nb_del = deletions[iter.key()];
167 Size& nb_add = iter.val();
169 if (nb_del > nb_add) {
170 additions.
erase(iter);
172 }
else if (nb_del < nb_add) {
173 deletions.
erase(iter.key());
176 deletions.
erase(iter.key());
177 additions.
erase(iter);
185 for (
const auto& modif : modifs) {
186 extremities.
insert(modif.tail());
187 extremities.
insert(modif.head());
195 for (
const auto& modif : modifs) {
196 if (!ancestors.
exists(modif.tail())) {
206 if (!ancestors.
exists(modif.head())) {
228 for (
auto iter = deletions.
cbegin(); iter != deletions.
cend(); ++iter) {
229 const Arc& arc = iter.key();
237 set_to_del.
insert(head, 1);
240 for (
auto iter = anc_tail.
cbegin(); iter != anc_tail.
cend(); ++iter) {
242 descendants[iter.key()], set_to_del, descendants[iter.key()][tail]);
246 set_to_del = anc_tail;
247 set_to_del.
insert(tail, 1);
250 for (
auto iter = desc_head.
cbegin(); iter != desc_head.
cend(); ++iter) {
252 ancestors[iter.key()], set_to_del, ancestors[iter.key()][head]);
267 for (
auto iter = additions.
cbegin(); iter != additions.
cend(); ++iter) {
268 const Arc& arc = iter.key();
274 if (anc_tail.
exists(head)) {
return true; }
280 set_to_add.
insert(tail, 1);
283 for (
auto iter = desc_head.
cbegin(); iter != desc_head.
cend(); ++iter) {
285 ancestors[iter.key()], set_to_add, ancestors[iter.key()][head]);
289 set_to_add = desc_head;
290 set_to_add.
insert(head, 1);
293 for (
auto iter = anc_tail.
cbegin(); iter != anc_tail.
cend(); ++iter) {
295 descendants[iter.key()], set_to_add, descendants[iter.key()][tail]);
310 "the arc would create a directed into a DAG");
322 set_to_add.
insert(tail, 1);
325 for (
auto iter = desc_head.
cbegin(); iter != desc_head.
cend(); ++iter) {
331 set_to_add = desc_head;
332 set_to_add.
insert(head, 1);
335 for (
auto iter = anc_tail.
cbegin(); iter != anc_tail.
cend(); ++iter) {
355 set_to_del.
insert(head, 1);
358 for (
auto iter = anc_tail.
cbegin(); iter != anc_tail.
cend(); ++iter) {
364 set_to_del = anc_tail;
365 set_to_del.
insert(tail, 1);
368 for (
auto iter = desc_head.
cbegin(); iter != desc_head.
cend(); ++iter) {
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
DiGraph __dag
the initial dag from which modifications are applied
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
const iterator_safe & endSafe() noexcept
Returns the safe iterator pointing to the end of the hashtable.
Size size() const noexcept
Returns the number of elements stored into the hashtable.
void erase(const Key &key)
Removes a given element from the hash table.
void eraseArc(NodeId x, NodeId y)
removes an arc from the current DAG
void __addWeightedSet(NodeProperty< Size > &nodeset, const NodeProperty< Size > &set_to_add, Size multiplier) const
adds a weighted nodeset to another (weights are added)
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
void addArc(NodeId x, NodeId y)
adds a new arc to the current DAG
void __delWeightedSet(NodeProperty< Size > &nodeset, const NodeProperty< Size > &set_to_del, Size multiplier) const
removes a weighted nodeset from another (weights are subtracted)
void __restrictWeightedSet(NodeProperty< Size > &result_set, const NodeProperty< Size > &set_to_restrict, const NodeSet &extrmities) const
put into a weighted nodeset the nodes of another weighted set that belong to a set of arc extremities...
Generic doubly linked lists.
gum is the global namespace for all aGrUM entities
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.
A class for detecting directed cycles in DAGs when trying to apply many changes to the graph...
bool hasCycleFromModifications(const std::vector< Change > &modifs) const
indicates whether a set of modifications would create a cycle
void setDAG(const DAG &dag)
sets the initial DAG from which changes shall be applied
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
const const_iterator & cend() const noexcept
Returns the unsafe const_iterator pointing to the end of the hashtable.
A class for detecting directed cycles in DAGs when trying to apply many changes to the graph...
const_iterator cbegin() const
Returns an unsafe const_iterator pointing to the beginning of the hashtable.
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.
bool hasCycleFromAddition(NodeId x, NodeId y) const noexcept
indicates whether an arc addition would create a cycle
iterator_safe beginSafe()
Returns the safe iterator pointing to the beginning of the hashtable.
NodeProperty< NodeProperty< Size > > __descendants
the set of descendants of each node in the dag
NodeProperty< NodeProperty< Size > > __ancestors
the set of ancestors of each node in the dag
std::size_t Size
In aGrUM, hashed values are unsigned long int.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
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
#define GUM_ERROR(type, msg)