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

Tests Ore's sufficient condition for Hamiltonian graphs. More...

#include <hamiltonian.H>

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

Public Member Functions

 Test_Hamiltonian_Sufficiency (SN &&__sn=SN(), SA &&__sa=SA())
 Construct a Hamiltonian sufficiency tester.
 
bool operator() (GT &g)
 Test if a graph satisfies Ore's Hamiltonian condition.
 

Private Member Functions

bool test_graph (GT &g)
 Test Ore's condition for undirected graphs.
 
bool test_digraph (GT &g)
 Test Ore-like condition for directed graphs.
 

Private Attributes

Kept_Filter< SN > sn
 
Kept_Filter< SA > sa
 

Detailed Description

template<AlephGraph GT, NodeFilter< GT > SN = Dft_Show_Node<GT>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
class Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >

Tests Ore's sufficient condition for Hamiltonian graphs.

This class tests whether a graph satisfies Ore's theorem, which provides a sufficient (but not necessary) condition for a graph to be Hamiltonian.

Ore's Theorem

For an undirected graph G with n ≥ 3 vertices: if for every pair of non-adjacent vertices u and v, deg(u) + deg(v) ≥ n, then G has a Hamiltonian cycle.

For directed graphs, the condition is extended to in-degree + out-degree.

Template Parameters
GTGraph type (List_Graph, Array_Graph, etc.)
SNNode filter for iteration (default: show all nodes)
SAArc filter for iteration (default: show all arcs)

Complexity

  • Undirected: O(V²) - checks all pairs of non-adjacent vertices
  • Directed: O(V² + E) - also counts in-degrees
Example
// Complete graph K5 satisfies Ore's condition
// ... build K5 ...
assert(test(k5) == true); // All deg sums ≥ n for non-adjacent
Graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:439
Tests Ore's sufficient condition for Hamiltonian graphs.
void test()
Definition test-comb.C:40
Warning
A graph may be Hamiltonian without satisfying this condition. This is a sufficiency test only.
Author
Leandro R. León

Definition at line 184 of file hamiltonian.H.

Constructor & Destructor Documentation

◆ Test_Hamiltonian_Sufficiency()

template<AlephGraph GT, NodeFilter< GT > SN = Dft_Show_Node<GT>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::Test_Hamiltonian_Sufficiency ( SN &&  __sn = SN(),
SA &&  __sa = SA() 
)
inline

Construct a Hamiltonian sufficiency tester.

Parameters
__snNode filter (default: show all nodes)
__saArc filter (default: show all arcs)

Definition at line 288 of file hamiltonian.H.

Member Function Documentation

◆ operator()()

template<AlephGraph GT, NodeFilter< GT > SN = Dft_Show_Node<GT>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
bool Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::operator() ( GT &  g)
inline

Test if a graph satisfies Ore's Hamiltonian condition.

Automatically detects directed vs undirected and applies the appropriate test.

Parameters
gGraph to test
Returns
true if Ore's sufficient condition is satisfied
Note
Returns true only guarantees the graph IS Hamiltonian. Returns false does NOT mean it isn't Hamiltonian.

Definition at line 306 of file hamiltonian.H.

References GraphCommon< GT, Node, Arc >::is_digraph(), Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::test_digraph(), and test_graph().

◆ test_digraph()

template<AlephGraph GT, NodeFilter< GT > SN = Dft_Show_Node<GT>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
bool Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::test_digraph ( GT &  g)
inlineprivate

Test Ore-like condition for directed graphs.

For digraphs, checks that for each pair (u,v) without arc u→v: out-deg(u) + in-deg(v) ≥ n, in the simple digraph of the arcs that the filter shows

This is Woodall's theorem, the extension of Ore's to digraphs.

Parameters
gDirected graph to test
Returns
true if the digraph version of Ore's condition is satisfied

Definition at line 249 of file hamiltonian.H.

References Aleph::hamiltonian_detail::Simple_Graph< GT, SA >::degree(), GraphCommon< GT, Node, Arc >::get_num_nodes(), Aleph::hamiltonian_detail::Simple_Graph< GT, SA >::in_degree(), GraphCommon< GT, Node, Arc >::is_digraph(), Aleph::hamiltonian_detail::Simple_Graph< GT, SA >::joined(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::sa, and Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::sn.

Referenced by Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::operator()().

◆ test_graph()

template<AlephGraph GT, NodeFilter< GT > SN = Dft_Show_Node<GT>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
bool Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::test_graph ( GT &  g)
inlineprivate

Test Ore's condition for undirected graphs.

Checks that for all pairs of NON-ADJACENT vertices u, v: deg(u) + deg(v) ≥ n, in the simple graph of the arcs that the filter shows

Parameters
gUndirected graph to test
Returns
true if Ore's condition is satisfied

Definition at line 199 of file hamiltonian.H.

References Aleph::hamiltonian_detail::Simple_Graph< GT, SA >::degree(), GraphCommon< GT, Node, Arc >::get_num_nodes(), GraphCommon< GT, Node, Arc >::is_digraph(), Aleph::hamiltonian_detail::Simple_Graph< GT, SA >::joined(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::sa, and Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::sn.

Member Data Documentation

◆ sa

template<AlephGraph GT, NodeFilter< GT > SN = Dft_Show_Node<GT>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Kept_Filter<SA> Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::sa
private

◆ sn

template<AlephGraph GT, NodeFilter< GT > SN = Dft_Show_Node<GT>, ArcFilter< GT > SA = Dft_Show_Arc<GT>>
Kept_Filter<SN> Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::sn
private

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