![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
A class for detecting directed cycles in DAGs when trying to apply many changes to the graph. More...
#include <DAGCycleDetector.h>
Public Member Functions | |
Constructors / Destructors | |
DAGCycleDetector () noexcept | |
default constructor More... | |
DAGCycleDetector (const DAGCycleDetector &from) | |
copy constructor More... | |
DAGCycleDetector (DAGCycleDetector &&from) | |
move constructor More... | |
~DAGCycleDetector () | |
destructor More... | |
Operators | |
DAGCycleDetector & | operator= (const DAGCycleDetector &from) |
copy operator More... | |
DAGCycleDetector & | operator= (DAGCycleDetector &&from) |
move operator More... | |
bool | operator== (const DAGCycleDetector &from) const |
check the equality between two DAGCycleDetectors More... | |
bool | operator!= (const DAGCycleDetector &from) const |
check the inequality between two DAGCycleDetectors More... | |
Accessors/Modifiers | |
void | setDAG (const DAG &dag) |
sets the initial DAG from which changes shall be applied More... | |
void | addArc (NodeId x, NodeId y) |
adds a new arc to the current DAG More... | |
void | eraseArc (NodeId x, NodeId y) |
removes an arc from the current DAG More... | |
void | reverseArc (NodeId x, NodeId y) |
reverses an arc from the DAG More... | |
bool | hasCycleFromAddition (NodeId x, NodeId y) const noexcept |
indicates whether an arc addition would create a cycle More... | |
bool | hasCycleFromReversal (NodeId x, NodeId y) const noexcept |
indicates wether an arc reversal would create a cycle More... | |
bool | hasCycleFromDeletion (NodeId x, NodeId y) const noexcept |
indicates whether an arc deletion would create a cycle More... | |
bool | hasCycleFromModifications (const std::vector< Change > &modifs) const |
indicates whether a set of modifications would create a cycle More... | |
Public Types | |
enum | ChangeType { ChangeType::ARC_ADDITION, ChangeType::ARC_DELETION, ChangeType::ARC_REVERSAL } |
Classes | |
class | ArcAdd |
the class to indicate that we wish to add a new arc More... | |
class | ArcDel |
the class to indicate that we wish to remove an arc More... | |
class | ArcReverse |
the class to indicate that we wish to reverse an arc More... | |
class | Change |
the base class indicating the possible changes More... | |
A class for detecting directed cycles in DAGs when trying to apply many changes to the graph.
When trying to assess whether multiple changes applied to a given DAG would induce cycles, use class DAGCycleDetector instead of trying to apply the modifications to the DAG itself and check whether and exception is raised: the class is designed to be fast for such modifications. However, the number of modifications checked should be higher than at least 3 for this class to be competitive.
Definition at line 61 of file DAGCycleDetector.h.
|
strong |
Enumerator | |
---|---|
ARC_ADDITION | |
ARC_DELETION | |
ARC_REVERSAL |
Definition at line 64 of file DAGCycleDetector.h.
|
noexcept |
default constructor
Definition at line 226 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE gum::DAGCycleDetector::DAGCycleDetector | ( | const DAGCycleDetector & | from | ) |
copy constructor
Definition at line 229 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE gum::DAGCycleDetector::DAGCycleDetector | ( | DAGCycleDetector && | from | ) |
move constructor
Definition at line 235 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE gum::DAGCycleDetector::~DAGCycleDetector | ( | ) |
destructor
Definition at line 242 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
adds a weighted nodeset to another (weights are added)
adds a nodeset to another (nodes are weighted, so weights are added)
Definition at line 284 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
removes a weighted nodeset from another (weights are subtracted)
Definition at line 298 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
|
private |
put into a weighted nodeset the nodes of another weighted set that belong to a set of arc extremities
Definition at line 314 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
adds a new arc to the current DAG
worst case complexity: O(h^2) where h is the height of the DAG
InvalidDirectedCycle | if the arc would create a cycle in the dag |
Definition at line 299 of file DAGCycleDetector.cpp.
References gum::Set< Key, Alloc >::emplace().
removes an arc from the current DAG
worst case complexity: O(h^2) where h is the height of the DAG
Definition at line 335 of file DAGCycleDetector.cpp.
References gum::Set< Key, Alloc >::emplace().
indicates whether an arc addition would create a cycle
worst case complexity: O(1)
Definition at line 268 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
indicates whether an arc deletion would create a cycle
worst case complexity: O(1)
Definition at line 278 of file DAGCycleDetector_inl.h.
indicates whether a set of modifications would create a cycle
the Boolean returned corresponds to the existence (or not) of a cycle on the graph resulting from the whole sequence of modifications. This means, for instance, that if, among modifs, there exists an arc (X,Y) addition involving a cycle but also the same arc (X,Y) deletion, the final graph obtained does not contains a cycle (due to the deletion) and the method will thus return false.
Definition at line 114 of file DAGCycleDetector.cpp.
References gum::Set< Key, Alloc >::emplace().
indicates wether an arc reversal would create a cycle
worst case complexity: O(1)
Definition at line 273 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE bool gum::DAGCycleDetector::operator!= | ( | const DAGCycleDetector & | from | ) | const |
check the inequality between two DAGCycleDetectors
used essentally for debugging purposes
Definition at line 339 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE DAGCycleDetector & gum::DAGCycleDetector::operator= | ( | const DAGCycleDetector & | from | ) |
copy operator
Definition at line 246 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE DAGCycleDetector & gum::DAGCycleDetector::operator= | ( | DAGCycleDetector && | from | ) |
move operator
Definition at line 257 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE bool gum::DAGCycleDetector::operator== | ( | const DAGCycleDetector & | from | ) | const |
check the equality between two DAGCycleDetectors
used essentally for debugging purposes
Definition at line 333 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
reverses an arc from the DAG
worst case complexity: O(h^2) where h is the height of the DAG
InvalidDirectedCycle | if the arc reversal would create a cycle in the dag |
Definition at line 323 of file DAGCycleDetector_inl.h.
References gum::Set< Key, Alloc >::emplace().
void gum::DAGCycleDetector::setDAG | ( | const DAG & | dag | ) |
sets the initial DAG from which changes shall be applied
Definition at line 45 of file DAGCycleDetector.cpp.
References gum::Set< Key, Alloc >::emplace().
|
private |
the set of ancestors of each node in the dag
for each ancestor, we keep track of the number of paths leading to it
Definition at line 324 of file DAGCycleDetector.h.
|
private |
the initial dag from which modifications are applied
Definition at line 320 of file DAGCycleDetector.h.
|
private |
the set of descendants of each node in the dag
for each ancestor, we keep track of the number of paths leading to it
Definition at line 328 of file DAGCycleDetector.h.