|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Test whether a cycle is reachable from a given node. More...
#include <tpl_test_cycle.H>
Public Member Functions | |
| Test_For_Cycle (SA arc_filter=SA()) | |
| Construct a cycle tester with optional arc filter. | |
| bool | operator() (const GT &g, typename GT::Node *src_node) const |
| Test whether a cycle is reachable from the given source node. | |
Private Member Functions | |
| bool | test_cycle (typename GT::Node *curr) const |
| bool | test_cycle (const GT &g, typename GT::Node *s) const |
Private Attributes | |
| GT::Node * | src = nullptr |
| SA | sa |
Test whether a cycle is reachable from a given node.
The Test_For_Cycle class performs a depth-first search starting from a specified source node to detect whether there exists any path that returns to that source, forming a cycle.
This is a single-source cycle detection algorithm. It only checks for cycles reachable from the specified node. If the node is not part of any cycle, the algorithm returns false, even if the graph contains cycles elsewhere.
The algorithm uses depth-first traversal with the following logic:
Test_Cycle control bit to mark visited nodes and arcsTest_Cycle control bit on all visited nodes and arcs. If you need this bit for other purposes, save and restore it, or use a different algorithm.| GT | Graph type (must satisfy Aleph graph concept). |
| SA | Arc filter type (default: Dft_Show_Arc<GT>). |
Definition at line 107 of file tpl_test_cycle.H.
|
inline |
Construct a cycle tester with optional arc filter.
| arc_filter | Arc filter to control which arcs are traversed (default: show all arcs). |
Definition at line 187 of file tpl_test_cycle.H.
|
inline |
Test whether a cycle is reachable from the given source node.
Performs a depth-first search starting from src_node to detect whether there exists any path that returns to src_node, forming a cycle.
| [in] | g | Graph to search (not modified, but control bits are used). |
| [in] | src_node | Source node to start the search from. |
true if a cycle reachable from src_node is found; false otherwise.| std::invalid_argument | if src_node is nullptr. |
src_node. It does not return the cycle itself or any information about its composition.Test_Cycle control bit on both nodes and arcs. These bits are reset at the beginning of the algorithm.Definition at line 212 of file tpl_test_cycle.H.
References Aleph::Test_For_Cycle< GT, SA >::test_cycle().
|
inlineprivate |
Definition at line 148 of file tpl_test_cycle.H.
References ah_invalid_argument_if, ARC_BITS, IS_ARC_VISITED, Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), GraphCommon< GT, Node, Arc >::reset_bit_arcs(), GraphCommon< GT, Node, Arc >::reset_bit_nodes(), Aleph::Test_For_Cycle< GT, SA >::sa, Aleph::Test_For_Cycle< GT, SA >::src, Aleph::Test_Cycle, and Aleph::Test_For_Cycle< GT, SA >::test_cycle().
Definition at line 113 of file tpl_test_cycle.H.
References ARC_BITS, IS_ARC_VISITED, IS_NODE_VISITED, Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), NODE_BITS, Aleph::Test_For_Cycle< GT, SA >::sa, Aleph::Test_For_Cycle< GT, SA >::src, Aleph::Test_Cycle, and Aleph::Test_For_Cycle< GT, SA >::test_cycle().
Referenced by Aleph::Test_For_Cycle< GT, SA >::operator()(), Aleph::Test_For_Cycle< GT, SA >::test_cycle(), and Aleph::Test_For_Cycle< GT, SA >::test_cycle().
Definition at line 110 of file tpl_test_cycle.H.
Referenced by Aleph::Test_For_Cycle< GT, SA >::test_cycle(), and Aleph::Test_For_Cycle< GT, SA >::test_cycle().
|
mutableprivate |
Definition at line 109 of file tpl_test_cycle.H.
Referenced by Aleph::Test_For_Cycle< GT, SA >::test_cycle(), and Aleph::Test_For_Cycle< GT, SA >::test_cycle().