Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Has_Cycle< GT, SA > Class Template Reference

Determines whether a graph contains cycles. More...

#include <tpl_test_acyclique.H>

Collaboration diagram for Aleph::Has_Cycle< GT, SA >:
[legend]

Public Member Functions

 Has_Cycle (SA &&__sa=SA())
 
 Has_Cycle (SA &__sa)
 
bool operator() (GT &g) const
 Invokes the cycle-existence test.
 
bool operator() (GT &g, size_t num_arcs) const
 Invokes the cycle-existence test, with the number of arcs that the filter shows.
 

Private Attributes

Kept_Filter< SA > sa
 

Detailed Description

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
class Aleph::Has_Cycle< GT, SA >

Determines whether a graph contains cycles.

Has_Cycle performs a depth-first search on graph g, starting from a node, and checks whether the graph contains a cycle.

The class takes two template parameters:

  1. GT: the graph type, which must be derived from List_Graph.
  2. SA: a class responsible for selecting/showing arcs. Internally, the function uses the filtered iterator Node_Arc_Iterator (based on Filter_Iterator) to traverse each node's arcs. SA is the class that decides whether an arc is included in the traversal.

The class uses the Test_Cycle bit and resets it at the beginning of the algorithm to mark already visited nodes and arcs.

Definition at line 233 of file tpl_test_acyclique.H.

Constructor & Destructor Documentation

◆ Has_Cycle() [1/2]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Has_Cycle< GT, SA >::Has_Cycle ( SA &&  __sa = SA())
inline

Definition at line 238 of file tpl_test_acyclique.H.

◆ Has_Cycle() [2/2]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Has_Cycle< GT, SA >::Has_Cycle ( SA &  __sa)
inline

Definition at line 242 of file tpl_test_acyclique.H.

Member Function Documentation

◆ operator()() [1/2]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
bool Aleph::Has_Cycle< GT, SA >::operator() ( GT &  g) const
inline

Invokes the cycle-existence test.

With the default filter, which shows all the arcs, a graph with nodes and with as many arcs as nodes, or more, has a cycle, which is answered without a search; with another filter, which may hide arcs, the graph is searched. A loop is a cycle, and so are two arcs between the same nodes.

Parameters
[in]gthe graph to test.
Returns
true if the graph contains at least one cycle; false otherwise.
Exceptions
domain_errorif g is a digraph.
Note
Because of the initial arc-count check, this routine can be preferable to test_for_cycle(), even if you know the graph is connected, since the latter routine always performs a depth-first search, while is_graph_acyclique() may not.

Definition at line 262 of file tpl_test_acyclique.H.

References Aleph::Has_Cycle< GT, SA >::sa.

◆ operator()() [2/2]

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
bool Aleph::Has_Cycle< GT, SA >::operator() ( GT &  g,
size_t  num_arcs 
) const
inline

Invokes the cycle-existence test, with the number of arcs that the filter shows.

A forest has fewer arcs than nodes, so that a graph with nodes and with num_arcs as large as their number, or larger, has a cycle, which is answered without a search. A loop is a cycle, and so are two arcs between the same nodes.

Parameters
[in]gthe graph to test.
[in]num_arcsnumber of arcs of g that the filter shows.
Returns
true if the graph contains at least one cycle; false otherwise.
Exceptions
domain_errorif g is a digraph.
Note
Because of the initial arc-count check, this routine can be preferable to test_for_cycle(), even if you know the graph is connected, since the latter routine always performs a depth-first search, while is_graph_acyclique() may not.

Definition at line 284 of file tpl_test_acyclique.H.

References Aleph::Has_Cycle< GT, SA >::sa.

Member Data Documentation

◆ sa

template<AlephGraph GT, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Kept_Filter<SA> Aleph::Has_Cycle< GT, SA >::sa
private

The documentation for this class was generated from the following file: