120namespace eulerian_detail
128 template <
class GT,
class SA>
133 d += (not g.
is_digraph()
and it.get_tgt_node_ne() == p) ? 2 : 1;
144 template <
class GT,
class SA>
173 bool together =
true;
174 Node * component =
nullptr;
178 if (component ==
nullptr)
180 together =
r == component;
237template <AlephGraph
GT,
257 size_t odd_degree_count = 0;
261 if (odd_degree_count != 0
and odd_degree_count != 2)
290 size_t start_vertices = 0;
291 size_t end_vertices = 0;
292 size_t imbalanced = 0;
296 typename GT::Node * p = it.get_curr();
299 const long diff = out_deg - in_deg;
311 const bool cycle = start_vertices == 0
and end_vertices == 0;
312 if (imbalanced > 0 or not (cycle or (start_vertices == 1
and end_vertices == 1)))
416 typename GT::Node * p = it.get_curr();
473template <AlephGraph
GT,
493 typename GT::Node * start =
nullptr;
494 typename GT::Node * odd_vertex =
nullptr;
505 typename GT::Node * p = it.get_curr();
509 if (start ==
nullptr)
521 typename GT::Node * p = it.get_curr();
525 if (start ==
nullptr)
563 typename GT::Arc * unused_arc =
nullptr;
566 typename GT::Arc * arc = it.get_curr();
574 if (unused_arc !=
nullptr)
583 current_path.
insert(unused_arc);
622 typename GT::Arc * unused_arc =
nullptr;
625 typename GT::Arc * arc = it.get_curr();
633 if (unused_arc !=
nullptr)
642 current_path.
insert(unused_arc);
715 if (start ==
nullptr)
735 return (*
this)(g).path;
746 Result result = (*this)(g);
767 for (
auto arc : result.
path)
C++20 concepts for the protocol shared by graph algorithms.
WeightedDigraph::Node Node
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
void append(Dlink *node) noexcept
Insert node before this.
Doubly-linked list (defined in tpl_dynList.H).
T & get_first()
Return the first item of the list.
T & insert(const T &item)
T remove_first()
See remove().
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Finds and constructs an Eulerian path or cycle using Hierholzer's algorithm.
GT::Node * find_start_vertex(GT &g, Eulerian_Type type)
Find starting vertex for Eulerian path/cycle.
DynList< typename GT::Node * > find_node_sequence(GT &g)
Get the node sequence of the Eulerian path/cycle.
DynList< typename GT::Arc * > find_path(GT &g)
Get only the arc list (convenience method).
DynList< typename GT::Arc * > hierholzer_undirected(GT &g, typename GT::Node *start)
Hierholzer's algorithm for undirected graphs.
DynList< typename GT::Arc * > hierholzer_directed(GT &g, typename GT::Node *start)
Hierholzer's algorithm for directed graphs.
Find_Eulerian_Path(SN &&__sn=SN(), SA &&__sa=SA())
Construct an Eulerian path finder with optional filters.
Result operator()(GT &g)
Find an Eulerian path or cycle in the graph.
constexpr bool is_empty() const noexcept
A filter that an algorithm object keeps: one given as an lvalue is used where it is,...
Graph_Node< Node_Info > Node
The graph type.
Filtered iterator on the nodes of a graph.
Tests whether a graph or digraph is Eulerian.
Eulerian_Type compute(GT &g)
Compute detailed Eulerian classification.
bool operator()(GT &g)
Test if a graph has an Eulerian cycle.
Eulerian_Type analyze_digraph(GT &g)
Analyze Eulerian properties of a directed graph.
Test_Eulerian(SN &&__sn=SN(), SA &&__sa=SA())
Construct an Eulerian tester with optional filters.
bool test_degree_only(GT &g)
Check only degree conditions (without connectivity check).
Eulerian_Type analyze_graph(GT &g)
Analyze Eulerian properties of an undirected graph.
bool has_eulerian_path(GT &g)
Test if a graph has an Eulerian path.
void reset_arcs() const
Reset all the arcs of graph (the control bits, the state, the counter and the cookie)
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
bool is_digraph() const noexcept
Return true if the graph this is directed.
void reset_cookie_nodes() const noexcept
Reset all the cookies to `nullptr for all the nodes of graph.
void reset_counter_nodes() const noexcept
Reset all the counters to zero for all the nodes of graph.
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
DynArray< Graph::Node * > nodes
#define NODE_COUNTER(p)
Get the counter of a node.
#define ARC_BITS(p)
Return the control bits of arc p.
#define NODE_COOKIE(p)
Return the node cookie
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
bool arcs_are_together(const GT &g, SA &sa)
Whether the arcs that sa shows are all in one component.
size_t degree(const GT &g, typename GT::Node *p, SA &sa)
Degree of a node as an Eulerian walk counts it.
Main namespace for Aleph-w library functions.
Eulerian_Type
Enumeration for Eulerian graph classification.
@ Cycle
Graph has an Eulerian cycle.
@ None
Graph is not Eulerian.
@ Path
Graph has an Eulerian path but not a cycle.
and
Check uniqueness with explicit hash + equality functors.
bool diff(const C1 &c1, const C2 &c2, Eq e=Eq())
Check if two containers differ.
void next()
Advance all underlying iterators (bounds-checked).
Filtered iterator on all the arcs of a graph.
Default filter for filtered iterators on arcs.
Default filter for the graph nodes.
Result type: path and its classification.
Eulerian_Type type
Classification (Cycle, Path, or None)
DynList< typename GT::Arc * > path
The Eulerian path/cycle as arc list.
Filtered iterator of adjacent arcs of a node.
Represents a missing value.
Generic graph and digraph implementations.
Utility algorithms and operations for graphs.