44# ifndef TPL_GRAPH_UTILS_H
45# define TPL_GRAPH_UTILS_H
55# include <type_traits>
82 template <AlephGraph GT>
inline static bool
85 bool (*visit)(
const GT & g,
typename GT::Node *,
113 template <AlephGraph GT>
inline size_t
115 bool (*visit)(
const GT & g,
typename GT::Node *,
128 template <AlephGraph GT>
inline
130 bool (*visit)(
const GT &,
typename GT::Node *,
170 template <AlephGraph
GT,
205 if (
enter(node, arc))
213 std::optional<Frame> here(std::in_place, node,
sa);
216 if (
auto tgt = here->template next_target<Depth_First>())
218 if (
enter(tgt, here->it.get_current_arc_ne()))
221 frames.
push(std::move(*here));
222 here.emplace(tgt,
sa);
233 if (
auto tgt = f.template next_target<Depth_First>())
235 if (
enter(tgt, f.
it.get_current_arc_ne()))
238 here.emplace(tgt,
sa);
301 Operation op = Operation())
303 return dft(g, sn, op);
308 template <AlephGraph GT>
inline static bool
311 bool (*visit)(
const GT & g,
typename GT::Node *,
322 [[gnu::always_inline]]
static bool
338 if (Visit::enter(g, node, arc, visit,
count))
348 if (
auto tgt = here.template next_target<Depth_First>())
350 if (Visit::enter(g, tgt, here.it.get_current_arc_ne(), visit,
count))
353 frames.
push(std::move(here));
363 Frame & f = frames.
top();
365 if (
auto tgt = f.template next_target<Depth_First>())
367 if (Visit::enter(g, tgt, f.it.get_current_arc_ne(), visit,
count))
404 template <AlephGraph GT>
inline size_t
406 bool (*visit)(
const GT &,
typename GT::Node *,
413 for (
auto it = g.
get_arc_it(start); it.has_curr(); it.next_ne())
414 q.
put(it.get_current_arc_ne());
417 size_t node_counter = 1;
419 if (visit !=
nullptr)
420 if ((*visit)(g, start,
nullptr))
435 if (visit !=
nullptr)
436 if ((*visit)(g, visit_node, arc))
442 for (
auto it = g.
get_arc_it(visit_node); it.has_curr(); it.next_ne())
444 auto curr_arc = it.get_current_arc_ne();
460 template <AlephGraph GT>
inline size_t
462 bool (*visit)(
const GT &,
typename GT::Node *,
490 template <AlephGraph
GT,
505 q.
put(it.get_current_arc_ne());
510 if (op (g, start,
nullptr))
526 if (op (g, curr, arc))
534 auto curr_arc = it.get_current_arc_ne();
589 Operation && op = Operation())
591 return bft(g, p, op);
606 return bft(g, p, op);
632 template <AlephGraph GT>
inline
637 <<
"find_path_breadth_first(): start and end must be non-null";
647 for (
auto it = g.
get_arc_it(start); it.has_curr(); it.next_ne())
648 q.
put(it.get_current_arc_ne());
652 bool path_found =
false;
676 for (
auto it = g.
get_arc_it(tgt); it.has_curr(); it.next_ne())
678 auto a = it.get_current_arc_ne();
719 template <AlephGraph GT>
inline
723 <<
"test_connectivity() does not work on digraphs";
732 return depth_first_traversal<GT>(g,
nullptr) ==
num_nodes;
737 template <AlephGraph GT>
inline static
757 template <AlephGraph GT>
inline
761 <<
"test_for_cycle(): src must be non-null";
765 for (
auto it = g.
get_arc_it(src); it.has_curr(); it.next_ne())
767 auto arc = it.get_curr();
780 template <AlephGraph GT>
inline static bool
801 if (
auto tgt = here.template next_target<Test_Cycle>(src))
807 frames.
push(std::move(here));
817 Frame & f = frames.
top();
819 if (
auto tgt = f.template next_target<Test_Cycle>(src))
839 template <AlephGraph GT>
inline static
854 if (
auto tgt = here.template next_target<Test_Cycle, true>())
860 frames.
push(std::move(here));
870 Frame & f = frames.
top();
872 if (
auto tgt = f.template next_target<Test_Cycle, true>())
906 template <AlephGraph GT>
inline
910 <<
"is_graph_acyclique() does not work for digraphs";
917 <<
"is_graph_acyclique(): start_node must be non-null";
943 template <AlephGraph GT>
inline
947 <<
"is_graph_acyclique() does not work for digraphs";
959 for (
auto it = g.
get_node_it(); it.has_curr(); it.next_ne())
961 auto current_node = it.get_current_node_ne();
981 template <AlephGraph GT>
1003 template <AlephGraph GT>
inline
1008 <<
"test_for_path(): start_node and end_node must be non-null";
1010 if (start_node == end_node)
1016 for (
auto it = g.
get_arc_it(start_node); it.has_curr(); it.next_ne())
1018 auto arc = it.get_current_arc_ne();
1034 template <AlephGraph GT>
inline static
1038 if (curr_node == end_node)
1053 if (
auto tgt = here.template next_target<Find_Path>(end_node))
1055 if (tgt == end_node)
1059 frames.
push(std::move(here));
1069 Frame & f = frames.
top();
1071 if (
auto tgt = f.template next_target<Find_Path>(end_node))
1073 if (tgt == end_node)
1086 template <AlephGraph GT>
inline
1090 template <AlephGraph GT>
inline
1092 typename GT::Node * g_src,
size_t & node_count);
1117 template <AlephGraph GT>
inline
1121 <<
"inconnected_components() does not work on digraphs";
1130 auto curr = it.get_current_node_ne();
1163 template <AlephGraph GT>
inline
1165 typename GT::Node * g_src,
size_t & node_count)
1175 typename GT::Node_Arc_Iterator it;
1182 void next_arc()
noexcept(
noexcept(it.next_ne())) { it.next_ne(); }
1186 [[gnu::always_inline]]
static Frame
1192 auto sg_p = mapped_node<GT>(p);
1193 if (sg_p ==
nullptr)
1198 return Frame(gr, p, sg_p);
1205 [[gnu::always_inline]]
typename GT::Node * next_to_visit(
GT & sgr)
1207 for (; it.has_curr(); next_arc())
1209 auto arc = it.get_current_arc_ne();
1215 auto g_tgt = it.get_tgt_node_ne();
1217 auto sg_tgt = mapped_node<GT>(g_tgt);
1218 if (sg_tgt ==
nullptr)
1240 Frame here = Frame::visit(g, sg, g_src, node_count);
1243 if (
auto g_tgt = here.next_to_visit(sg))
1245 frames.
push(std::move(here));
1246 here = Frame::visit(g, sg, g_tgt, node_count);
1255 Frame & f = frames.
top();
1257 if (
auto g_tgt = f.next_to_visit(sg))
1259 here = Frame::visit(g, sg, g_tgt, node_count);
1269 template <AlephGraph GT>
inline static
1295 template <AlephGraph GT>
inline
1308 for (
auto it = g.
get_arc_it(gnode); it.has_curr(); it.next_ne())
1310 auto arc = it.get_current_arc_ne();
1314 auto arc_tgt_node = it.get_tgt_node_ne();
1326 template <AlephGraph GT>
inline
1333 template <AlephGraph GT>
inline static
1343 typename GT::Node_Arc_Iterator it;
1350 void next_arc()
noexcept(
noexcept(it.next_ne())) { it.next_ne(); }
1356 noexcept(
noexcept(it.next_ne()))
1358 for (; it.has_curr(); it.next_ne())
1360 auto arc = it.get_current_arc_ne();
1364 auto arc_tgt_node = it.get_tgt_node_ne();
1366 return arc_tgt_node;
1376 [[gnu::always_inline]]
static typename GT::Node *
1393 return tree_tgt_node;
1402 auto image = Tree::put(g, tree, gnode, garc, tnode);
1403 if (image ==
nullptr)
1407 Frame here(g, gnode, image);
1410 if (
auto tgt = here.next_target())
1412 image = Tree::put(g, tree, tgt, here.it.get_current_arc_ne(), here.tnode);
1413 if (image ==
nullptr)
1416 frames.
push(std::move(here));
1417 here = Frame(g, tgt, image);
1426 Frame & f = frames.
top();
1428 if (
auto tgt = f.next_target())
1430 image = Tree::put(g, tree, tgt, f.it.get_current_arc_ne(), f.tnode);
1431 if (image ==
nullptr)
1434 here = Frame(g, tgt, image);
1460 template <AlephGraph GT>
inline
1475 for (
auto it = g.
get_arc_it(gp); it.has_curr(); it.next_ne())
1476 q.
put(it.get_curr());
1480 auto garc = q.
get();
1490 std::swap(gsrc, gtgt);
1492 auto tsrc = mapped_node<GT>(gsrc);
1501 auto tarc = tree.
insert_arc(tsrc, ttgt, garc->get_info());
1508 for (
auto it = g.
get_arc_it(gtgt); it.has_curr(); it.next_ne())
1510 auto current_arc = it.get_current_arc_ne();
1542 template <AlephGraph GT>
1555 Node * gsrc =
static_cast<Node *
>(ga->src_node);
1556 Node * gtgt =
static_cast<Node *
>(ga->tgt_node);
1559 auto * pair_ptr = table.
search(gsrc);
1561 tsrc = pair_ptr->second;
1565 table.
insert(gsrc, tsrc);
1570 pair_ptr = table.
search(gtgt);
1572 ttgt = pair_ptr->second;
1576 table.
insert(gtgt, ttgt);
1589 template <AlephGraph GT>
inline static
1597 template <AlephGraph GT>
inline static
1603 namespace graph_utils_detail
1615 typename GT::Node_Arc_Iterator
it;
1622 :
p(n),
a(arc),
it(g.get_arc_it(n)),
low(n_low) {}
1630 [[gnu::always_inline]]
inline Cut_Frame<GT> *
1635 const long n_df = df<GT>(n) = curr_df++;
1636 return &frames.push(g, n, arc, n_df);
1646 for (; f.it.has_curr(); f.it.next_ne())
1648 auto arc = f.it.get_current_arc_ne();
1652 auto tgt = f.it.get_tgt_node_ne();
1656 if (df<GT>(tgt) < f.low)
1657 f.low = df<GT>(tgt);
1673 template <AlephGraph GT>
inline static
1703 template <AlephGraph GT>
1710 <<
"compute_cut_nodes() does not work on digraphs";
1716 <<
"compute_cut_nodes(): start must be non-null";
1726 long current_df = 0;
1728 df<GT>(start) = current_df++;
1729 int call_counter = 0;
1736 auto tgt = it.get_tgt_node_ne();
1740 auto arc = it.get_current_arc_ne();
1750 if (call_counter > 1)
1760 template <AlephGraph GT>
1773 template <AlephGraph GT>
inline static
1783 Frame * f = visit_cut(g, frames, p, a, curr_df);
1786 if (
auto tgt = next_cut_child(*f))
1788 f = visit_cut(g, frames, tgt, f->it.get_current_arc_ne(), curr_df);
1793 const long child_low = f->low;
1794 if (f->p_is_cut_node)
1800 if (frames.is_empty())
1804 if (child_low < f->
low)
1807 if (child_low >= df<GT>(f->p)
and df<GT>(child) != 0)
1808 f->p_is_cut_node =
true;
1821 template <AlephGraph GT>
inline static
1828 template <AlephGraph GT>
inline static
1835 template <AlephGraph GT>
inline static
1842 template <AlephGraph GT>
inline static
1849 template <AlephGraph GT>
inline static
1856 template <AlephGraph GT>
inline static
1863 template <AlephGraph GT>
inline static
1870 template <AlephGraph GT>
inline static
1877 template <AlephGraph GT>
inline static
1883 namespace graph_utils_detail
1889 typename GT::Node_Arc_Iterator
it;
1903 for (;
it.has_curr();
it.next_ne())
1905 auto arc =
it.get_current_arc_ne();
1906 if (is_arc_painted <GT> (arc))
1909 auto tgt =
it.get_tgt_node_ne();
1910 if (is_a_cut_node <GT> (tgt))
1913 paint_arc <GT> (arc,
color);
1914 if (is_node_painted <GT> (tgt))
1917 paint_node <GT> (tgt,
color);
1931 template <AlephGraph GT>
inline static
1934 typename GT::Node * p,
long current_color)
1936 assert(not is_a_cut_node <GT> (p));
1938 if (is_node_painted <GT> (p))
1941 paint_node <GT> (p, current_color);
1950 if (
auto tgt = here.next_to_paint(current_color))
1952 frames.push(std::move(here));
1953 here = Frame(g, tgt);
1959 if (frames.is_empty())
1962 Frame & f = frames.top();
1964 if (
auto tgt = f.next_to_paint(current_color))
1966 here = Frame(g, tgt);
1975 template <AlephGraph GT>
inline static
1979 typename GT::Node * p,
long & current_color)
1981 assert(is_a_cut_node <GT> (p));
1984 for (
auto it = g.
get_arc_it(p); it.has_curr(); it.next_ne())
1986 auto arc = it.get_current_arc_ne();
1988 assert(not is_arc_painted <GT> (arc));
1990 auto tgt_node = it.get_tgt_node_ne();
1991 if (is_a_cut_node <GT> (tgt_node))
1997 if (is_node_painted<GT>(tgt_node))
2004 assert(not is_arc_painted <GT> (arc));
2043 template <AlephGraph GT>
inline long
2048 long current_color = 1;
2051 for (
auto it = cut_node_list.
get_it(); it.has_curr(); it.next_ne())
2054 return current_color;
2065 template <AlephGraph GT>
inline static
2069 assert(get_color <GT> (gsrc) ==
color);
2076 typename GT::Node_Arc_Iterator it;
2080 : tsrc(mapped_node<GT>(n)), it(gr.
get_arc_it(n)) {}
2083 void next_arc()
noexcept(
noexcept(it.next_ne())) { it.next_ne(); }
2088 typename GT::Arc * next_to_map(
const long c)
noexcept(
noexcept(it.next_ne()))
2090 for (; it.has_curr(); it.next_ne())
2092 auto garc = it.get_current_arc_ne();
2107 Frame here(g, gsrc);
2111 auto garc = here.next_to_map(
color);
2112 if (garc ==
nullptr)
2117 here = std::move(frames.
top());
2125 auto gtgt = here.it.get_tgt_node_ne();
2128 assert(get_color <GT> (gtgt) ==
color);
2130 typename GT::Node * ttgt =
nullptr;
2132 ttgt = mapped_node<GT> (gtgt);
2147 frames.
push(std::move(here));
2148 here = Frame(g, gtgt);
2171 template <AlephGraph GT>
2177 typename GT::Node * first =
nullptr;
2178 for (
auto it = g.
get_node_it(); it.has_curr(); it.next_ne())
2179 if (get_color <GT> (it.get_current_node_ne()) ==
color)
2181 first = it.get_current_node_ne();
2186 <<
"Color does not exist in the graph";
2220 template <AlephGraph GT>
2221 std::tuple<GT, DynList<typename GT::Arc*>>
2227 for (
auto it = cut_node_list.
get_it(); it.has_curr(); it.next_ne())
2229 auto gp = it.get_curr();
2231 assert(is_a_cut_node <GT> (gp));
2240 for (
auto it = g.
get_arc_it(); it.has_curr(); it.next_ne())
2242 auto garc = it.get_current_arc_ne();
2243 if (is_a_cross_arc <GT> (garc))
2245 cross_arc_list.
append(garc);
2249 if (not is_an_cut_arc <GT> (garc))
2255 assert(src !=
nullptr and tgt !=
nullptr);
2257 auto arc = cut_graph.
insert_arc(src, tgt, garc->get_info());
2263 return { std::move(cut_graph), std::move(cross_arc_list) };
2276 template <
class GT,
class Distance>
2307 template <AlephGraph GT>
2311 <<
"invert_digraph() requires a digraph (or a graph temporarily treated as a digraph)";
2318 for (
auto it = g.
get_node_it(); it.has_curr(); it.next_ne())
2320 auto gp = it.get_curr();
2325 for (
auto it = g.
get_arc_it(); it.has_curr(); it.next_ne())
2327 auto arc = it.get_curr();
2332 auto rsrc = mapped_node<GT>(ssrc);
2333 auto rtgt = mapped_node<GT>(stgt);
2335 assert(rsrc !=
nullptr and rtgt !=
nullptr);
2357 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2377 <<
"Invert_Digraph requires a digraph (or a graph temporarily treated as a digraph)";
2384 for (
auto it = g.
get_node_it(); it.has_curr(); it.next_ne())
2386 auto gp = it.get_curr();
2393 auto arc = it.get_curr();
2398 auto rsrc = mapped_node<GT>(ssrc);
2399 auto rtgt = mapped_node<GT>(stgt);
2401 assert(rsrc !=
nullptr and rtgt !=
nullptr);
2447 std::numeric_limits<typename Dft_Dist<GT>::Distance_Type>
::max();
2466 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
2472 assert(src !=
nullptr and tgt !=
nullptr);
2476 std::swap(tgt, src);
2478 typename GT::Arc * first_match =
nullptr;
2481 if (it.get_tgt_node_ne() != tgt)
2484 auto arc = it.get_current_arc_ne();
2490 if (first_match ==
nullptr)
2513 template <AlephGraph GT, ArcDistance<GT> Distance = Dft_Dist<GT>>
2521 <<
"get_min_path(): s and end must be non-null";
2523 Distance_Type dist{};
2540 <<
"get_min_path(): broken cookie chain (nullptr)";
2543 auto arc = search_spanning_tree_arc<GT>(path.
get_graph(), prev, curr);
2545 <<
"get_min_path(): no arc connecting nodes in path";
2547 node_arc_list.
insert(std::make_pair(curr, arc));
2556 for (
auto it = node_arc_list.
get_it(); it.has_curr(); it.next())
2558 auto & [node, arc] = it.get_curr();
2561 dist += distance(arc);
2583 template <AlephGraph
GT,
2606 for (Arc_Iterator <GT, SA> it(g,
sa); it.has_curr(); it.next_ne())
2607 sum +=
dist(it.get_current_arc_ne());
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_unless(C)
Throws std::domain_error if condition does NOT hold.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
C++20 concepts for the protocol shared by graph algorithms.
WeightedDigraph::Node Node
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Stateful breadth-first traversal functor.
Breadth_First_Traversal(SA __sa=SA())
Construct a traversal functor using the arc filter __sa.
size_t operator()(const GT &g, Operation op)
Traverse starting from the first node of the graph.
size_t bft(const GT &g, typename GT::Node *start, Operation &op)
Stateful depth-first traversal functor.
bool __dft(typename GT::Node *node, typename GT::Arc *arc=nullptr)
Depth_First_Traversal(SA __sa=SA())
Construct a traversal functor using the arc filter __sa.
bool enter(typename GT::Node *node, typename GT::Arc *arc)
size_t operator()(const GT &g, Operation op=Operation())
Traverse starting from the first node of the graph.
size_t dft(const GT &g, typename GT::Node *start_node, Operation &__op)
Stack of the frames of a depth-first search that does not recurse.
T & push(Args &&...args)
Builds a frame on top of the stack.
bool is_empty() const noexcept
Whether the stack has no frames.
T & top() noexcept
The top frame; the stack must not be empty.
void pop() noexcept
Destroys the top frame; the stack must not be empty.
Default distance accessor for arc weights.
static const Distance_Type Max_Distance
Distance_Type & operator()(typename GT::Arc *a) const
GT::Arc_Type Distance_Type
static const Distance_Type Zero_Distance
static void set_zero(typename GT::Arc *a)
Dynamic queue of elements of generic type T based on single linked list.
T & put(const T &data)
The type of element.
T get()
Remove the oldest item of the queue.
void empty() noexcept
Empty the queue.
bool is_empty() const noexcept
Return true if this is empty.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
T & insert(const T &item)
T & get_last()
Return the last item of the list.
Generic key-value map implemented on top of a binary search tree.
Pair * search(const Key &key) noexcept(nothrow_search)
Collect all keys.
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Functor for computing the transposed digraph, filtering arcs.
Invert_Digraph(SA __sa)
Construct a functor using the arc filter __sa.
GT operator()(const GT &g) const
Compute the transposed graph.
Node * get_first_node() const
Return any node in the graph.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Graph_Node< Node_Info > Node
The graph type.
Graph_Arc< Arc_Info > Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
typename Arc::Arc_Type Arc_Type
The type of data stored in the arc.
void insert(Arc *arc)
Insert an arc as the first of a path.
void empty()
Clean the path: all the nodes and arc are removed.
void init(Node *start_node)
Set the first node of a path.
void append(Arc *arc)
Append an arc to the path.
const GT & get_graph() const noexcept
Get a constant reference to the graph.
Compute the total cost (sum of arc weights) of a graph.
Distance::Distance_Type sum
Distance::Distance_Type operator()(GT &g)
See total_cost.
Distance::Distance_Type total_cost(GT &g)
Compute the total cost.
Total_Cost(Distance __dist=Distance(), SA __sa=SA())
Distance::Distance_Type value() const noexcept
Return the accumulated value (after using operator()(Arc*)).
void reset() noexcept
Reset the internal accumulator used by operator()(Arc*).
void for_each(Operation &operation) const
Traverse all the container and performs an operation on each element.
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
size_t num_arcs
data associated to the node. Access it with get_info()
void reset_bit_nodes(int bit) const noexcept
Reset bit to zero for all the nodes of graph.
void reset_arcs() const
Reset all the arcs of graph (the control bits, the state, the counter and the cookie)
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Node * get_node() const
Return any node in the graph.
void set_bit(Node *node, int bit, int value) const noexcept
Set the control bit of node to value
bool is_digraph() const noexcept
Return true if the graph this is directed.
static void map_arcs(A1 *p, A2 *q) noexcept
Map the arcs through their cookies.
void reset_counter_nodes() const noexcept
Reset all the counters to zero for all the nodes of graph.
void reset_bit_arcs(int bit) const noexcept
Reset bit to zero for all the arcs of graph.
void for_each_node(Operation &operation) const
Unconditionally traverse all the nodes of graph and on each one perform an operation.
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
void reset_counter_arcs() const noexcept
Reset all the counters to zero for all the arcs of graph.
void reset_nodes() const
Reset all the nodes of graph (the control bits, the state, the counter and the cookie)
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
static void map_nodes(N1 *p, N2 *q) noexcept
Map the nodes through their cookies.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
QuadTree - Hierarchical spatial index for 2D points.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
DynArray< Graph::Arc * > arcs
size_t depth_first_traversal(const GT &g, typename GT::Node *start_node, bool(*visit)(const GT &g, typename GT::Node *, typename GT::Arc *))
Depth-first traversal starting from a given node.
constexpr bool nothrow_arc_filter_v
Whether a filter of type SA of the arcs of GT is copied, moved and called without exceptions: then an...
GT build_spanning_tree(const DynArray< typename GT::Arc * > &arcs)
Build a graph from a list of arcs (typically a spanning tree).
#define ARC_COOKIE(p)
Return the arc cookie
bool has_cycle(const GT &g)
Return true if an undirected graph has at least one cycle.
#define NODE_COUNTER(p)
Get the counter of a node.
DynList< GT > inconnected_components(const GT &g)
Forward declaration for inconnected_components().
bool test_for_cycle(const GT &g, typename GT::Node *src)
Search for a cycle reachable from a given node.
GT find_breadth_first_spanning_tree(GT &g, typename GT::Node *gp)
Build a breadth-first spanning tree (mapped to the original graph).
#define ARC_COUNTER(p)
Return the counter of arc p.
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
GT invert_digraph(const GT &g)
Compute the transpose (arc-reversed) digraph.
bool test_connectivity(const GT &g)
Connectivity test for undirected graphs.
#define ARC_BITS(p)
Return the control bits of arc p.
#define NODE_COOKIE(p)
Return the node cookie
long paint_subgraphs(const GT &g, const DynList< typename GT::Node * > &cut_node_list)
Paint connected blocks around articulation points.
DynList< typename GT::Node * > compute_cut_nodes(const GT &g, typename GT::Node *start)
Compute articulation points (cut vertices) of an undirected graph.
Path< GT > find_path_breadth_first(const GT &g, typename GT::Node *start, typename GT::Node *end)
Breadth-first search of a (shortest-by-edges) path between two nodes.
bool test_for_path(const GT &g, typename GT::Node *start_node, typename GT::Node *end_node)
Return true if there is a path between two nodes.
size_t breadth_first_traversal(const GT &g, typename GT::Node *start, bool(*visit)(const GT &, typename GT::Node *, typename GT::Arc *))
Breadth-first traversal starting from a given node.
void build_subgraph(const GT &g, GT &sg, typename GT::Node *g_src, size_t &node_count)
Forward declaration for build_subgraph().
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
GT find_depth_first_spanning_tree(const GT &g, typename GT::Node *gnode)
Build a depth-first spanning tree (mapped to the original graph).
bool is_graph_acyclique(const GT &g, typename GT::Node *start_node)
Return true if an undirected graph is acyclic.
std::tuple< GT, DynList< typename GT::Arc * > > map_cut_graph(const GT &g, const DynList< typename GT::Node * > &cut_node_list)
Extract the cut graph and cross-arc list.
#define NODE_BITS(p)
Get the control bits of a node.
GT map_subgraph(const GT &g, const long color)
Extract a mapped subgraph containing a given color.
#define ALEPH_FLATTEN
[[gnu::flatten]], or nothing where it would only make the compilation slower.
Cut_Frame< GT > * visit_cut(const GT &g, Dfs_Stack< Cut_Frame< GT > > &frames, typename GT::Node *n, typename GT::Arc *arc, long &curr_df)
GT::Node * next_cut_child(Cut_Frame< GT > &f) noexcept(noexcept(f.it.next_ne()))
Main namespace for Aleph-w library functions.
static bool __test_cycle(const GT &g, typename GT::Node *, typename GT::Node *)
Internal helper used by test_for_cycle().
static void __paint_subgraph(const GT &g, Dfs_Stack< graph_utils_detail::Paint_Frame< GT > > &frames, typename GT::Node *p, long current_color)
Internal DFS that paints a non-cut block with current_color.
static void paint_arc(typename GT::Arc *a, const long &color)
Set the arc color (stored in ARC_COUNTER).
static long & low(typename GT::Node *p)
Internal helper: low-link value stored directly in NODE_COOKIE(p).
static bool is_node_painted(typename GT::Node *p)
Return true if the node has a positive color.
static const long & get_color(typename GT::Node *p)
Return the node color (stored in NODE_COUNTER).
static bool __test_for_path(const GT &g, typename GT::Node *curr_node, typename GT::Node *end_node)
Internal DFS used by test_for_path().
static void paint_node(typename GT::Node *p, const long &color)
Set the node color (stored in NODE_COUNTER).
static bool is_a_cross_arc(typename GT::Arc *a)
Return true if the arc is marked as a cross-arc by paint_subgraphs().
static void __paint_from_cut_node(const GT &g, Dfs_Stack< graph_utils_detail::Paint_Frame< GT > > &frames, typename GT::Node *p, long ¤t_color)
Internal step that paints all blocks adjacent to a cut node.
and
Check uniqueness with explicit hash + equality functors.
static bool is_arc_painted(typename GT::Arc *arc)
Return true if the arc has a positive color.
static long & df(typename GT::Node *p)
Internal helper: DFS discovery time stored in NODE_COUNTER(p).
static bool is_an_cut_arc(typename GT::Arc *a)
Return true if the arc is marked as a cut-arc (between cut nodes).
constexpr long Cross_Arc
Special marker for arcs connecting a cut node to a non-cut block.
static bool __is_graph_acyclique(const GT &g, typename GT::Node *curr_node)
Internal DFS used by is_graph_acyclique().
Distance::Distance_Type get_min_path(typename GT::Node *s, typename GT::Node *end, Path< GT > &path, Distance distance=Distance())
Extracts a shortest path from a graph painted by a shortest paths algorithm.
static void __map_subgraph(const GT &g, GT &sg, typename GT::Node *gsrc, const long color)
Internal step used by map_subgraph().
static bool __depth_first_traversal(const GT &g, typename GT::Node *node, typename GT::Arc *arc, bool(*visit)(const GT &g, typename GT::Node *, typename GT::Arc *), size_t &count)
Internal DFS used by depth_first_traversal().
static bool is_a_cut_node(typename GT::Node *p)
Return true if the node is marked as an articulation point.
GT::Arc * search_spanning_tree_arc(const GT &g, typename GT::Node *src, typename GT::Node *tgt, SA sa=SA()) noexcept(nothrow_arc_filter_v< GT, SA >)
Helper to find the spanning tree arc between two nodes in a multigraph.
static void __compute_cut_nodes(const GT &g, DynList< typename GT::Node * > &list, Dfs_Stack< graph_utils_detail::Cut_Frame< GT > > &frames, typename GT::Node *p, typename GT::Arc *a, long &curr_df)
Internal DFS step used by compute_cut_nodes().
static bool __find_depth_first_spanning_tree(const GT &g, typename GT::Node *gnode, typename GT::Arc *garc, GT &tree, typename GT::Node *tnode)
Internal DFS used by find_depth_first_spanning_tree().
void next_ne() noexcept(noexcept(std::declval< Aleph::const_iterator_t< HeadC > & >().next_ne()) and noexcept(std::declval< ZipIterator< TailC... > & >().next_ne()))
Advance all underlying iterators (unchecked variant).
static long & color(typename GT::Node *p)
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Filtered iterator on all the arcs of a graph.
Default visit operation for traversals (never stops).
bool operator()(const GT &, typename GT::Node *, typename GT::Arc *)
Always continues the traversal (never stops early).
The next arc of a node to look at, for a depth-first search that keeps only that in a frame.
It it
The arcs of the node, on the next one to look at.
void next_arc() noexcept(noexcept(it.next_ne()))
Moves to the next arc; inlined, with all it calls.
Default filter for filtered iterators on arcs.
Comparison functor for arc weights/distances.
Distance_Compare(Distance __dist=Distance())
bool operator()(typename GT::Arc *a1, typename GT::Arc *a2) const
Filtered iterator of adjacent arcs of a node.
A node that waits for the one that it visits, the arc through which it was visited,...
Cut_Frame(const GT &g, typename GT::Node *n, typename GT::Arc *arc, const long n_low)
void next_arc() noexcept(noexcept(it.next_ne()))
The next arc of a node of a block being painted.
void next_arc() noexcept(noexcept(it.next_ne()))
Paint_Frame(const GT &g, typename GT::Node *n)
GT::Node * next_to_paint(const long color) noexcept(noexcept(it.next_ne()))
Array-based graph implementation.
Stack of the frames of a depth-first search that does not recurse.
Dynamic queue implementation based on linked lists.