41 #endif // GUM_NOINLINE 54 for (
const auto node : dag) {
55 Size nb_ch = dag.children(node).
size();
56 nb_children.
insert(node, nb_ch);
58 if (!nb_ch) leaves.
insert(node);
60 Size nb_pa = dag.parents(node).size();
61 nb_parents.
insert(node, nb_pa);
63 if (!nb_pa) roots.
insert(node);
74 while (!roots.
empty()) {
78 node_ancestors.
insert(node, 1);
79 const NodeSet& node_children = dag.children(node);
82 for (
const auto ch : node_children) {
86 if (!nb_parents[ch]) { roots.
insert(ch); }
93 for (
const auto node : dag) {
97 while (!leaves.
empty()) {
101 node_descendants.
insert(node, 1);
102 const NodeSet& node_parents = dag.parents(node);
105 for (
const auto pa : node_parents) {
109 if (!nb_children[pa]) { leaves.
insert(pa); }
116 const std::vector< Change >& modifs)
const {
124 for (
const auto& modif : modifs) {
125 Arc arc(modif.tail(), modif.head());
127 switch (modif.type()) {
129 if (deletions.
exists(arc))
137 if (modif.tail() == modif.head())
return true;
139 if (additions.
exists(arc))
147 if (deletions.
exists(arc))
152 arc =
Arc(modif.head(), modif.tail());
154 if (additions.
exists(arc))
168 if (deletions.
exists(iter.key())) {
169 Size& nb_del = deletions[iter.key()];
170 Size& nb_add = iter.val();
172 if (nb_del > nb_add) {
173 additions.
erase(iter);
175 }
else if (nb_del < nb_add) {
176 deletions.
erase(iter.key());
179 deletions.
erase(iter.key());
180 additions.
erase(iter);
188 for (
const auto& modif : modifs) {
189 extremities.
insert(modif.tail());
190 extremities.
insert(modif.head());
198 for (
const auto& modif : modifs) {
199 if (!ancestors.
exists(modif.tail())) {
209 if (!ancestors.
exists(modif.head())) {
231 for (
auto iter = deletions.
cbegin(); iter != deletions.
cend(); ++iter) {
232 const Arc& arc = iter.key();
240 set_to_del.
insert(head, 1);
243 for (
auto iter = anc_tail.
cbegin(); iter != anc_tail.
cend(); ++iter) {
245 descendants[iter.key()], set_to_del, descendants[iter.key()][tail]);
249 set_to_del = anc_tail;
250 set_to_del.
insert(tail, 1);
253 for (
auto iter = desc_head.
cbegin(); iter != desc_head.
cend(); ++iter) {
255 ancestors[iter.key()], set_to_del, ancestors[iter.key()][head]);
270 for (
auto iter = additions.
cbegin(); iter != additions.
cend(); ++iter) {
271 const Arc& arc = iter.key();
277 if (anc_tail.
exists(head)) {
return true; }
283 set_to_add.
insert(tail, 1);
286 for (
auto iter = desc_head.
cbegin(); iter != desc_head.
cend(); ++iter) {
288 ancestors[iter.key()], set_to_add, ancestors[iter.key()][head]);
292 set_to_add = desc_head;
293 set_to_add.
insert(head, 1);
296 for (
auto iter = anc_tail.
cbegin(); iter != anc_tail.
cend(); ++iter) {
298 descendants[iter.key()], set_to_add, descendants[iter.key()][tail]);
313 "the arc would create a directed into a DAG");
325 set_to_add.
insert(tail, 1);
328 for (
auto iter = desc_head.
cbegin(); iter != desc_head.
cend(); ++iter) {
334 set_to_add = desc_head;
335 set_to_add.
insert(head, 1);
338 for (
auto iter = anc_tail.
cbegin(); iter != anc_tail.
cend(); ++iter) {
358 set_to_del.
insert(head, 1);
361 for (
auto iter = anc_tail.
cbegin(); iter != anc_tail.
cend(); ++iter) {
367 set_to_del = anc_tail;
368 set_to_del.
insert(tail, 1);
371 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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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)