87# ifndef TPL_CUT_NODES_H
88# define TPL_CUT_NODES_H
155 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
193 [[gnu::always_inline]]
198 const long p_df = df<GT>(p) =
curr_df++;
199 return &frames.
push(p, a,
sa, p_df);
211 for (; f.it.has_curr(); f.it.next_ne())
213 auto arc = f.it.get_curr_ne();
217 auto tgt = f.it.get_tgt_node_ne();
221 p_low = std::min(df<GT>(tgt), p_low);
248 f =
visit(frames, tgt, f->
it.get_curr_ne());
254 const long child_low = f->
low;
265 f->
low = std::min(child_low, f->
low);
266 if (child_low >= df<GT>(f->
p)
and df<GT>(child) != 0)
305 int call_counter = 0;
310 it.has_curr()
and curr_df < gptr->get_num_nodes(); it.
next_ne())
312 auto tgt = it.get_tgt_node();
316 auto arc = it.get_curr();
325 if (call_counter > 1)
353 for (; f.it.has_curr(); f.it.next_ne())
355 auto arc = f.it.get_curr_ne();
356 if (is_arc_painted<GT>(arc))
359 auto tgt = f.it.get_tgt_node_ne();
360 if (is_a_cut_node<GT>(tgt))
364 if (is_node_painted<GT>(tgt))
379 assert(not is_a_cut_node <GT> (p));
381 if (is_node_painted<GT>(p))
392 f = &frames.
push(tgt,
sa);
407 assert(is_a_cut_node <GT> (p));
412 auto arc = it.get_curr();
414 assert(not is_arc_painted <GT> (arc));
416 auto tgt_node = it.get_tgt_node();
417 if (is_a_cut_node<GT>(tgt_node))
423 if (is_node_painted<GT>(tgt_node))
431 assert(not is_arc_painted <GT> (arc));
440 assert(get_color<GT>(gp) ==
color);
471 noexcept(
noexcept(f.it.next_ne()))
473 for (; f.it.has_curr(); f.it.next_ne())
475 auto garc = f.it.get_curr_ne();
492 assert(get_color <GT> (gsrc) ==
color);
500 auto gtgt = f.
it.get_tgt_node_ne();
503 assert(get_color <GT> (gtgt) ==
color);
507 ttgt = mapped_node<GT>(gtgt);
523 std::optional<Map_Frame> here(std::in_place, gsrc,
sa);
528 auto gtgt =
copy(*here, garc);
529 frames.
push(std::move(*here));
530 here.emplace(gtgt,
sa);
543 here.emplace(
copy(f, garc),
sa);
620 <<
"Cut nodes have not been computed or the class is in another phase";
656 bool copied_before =
false;
657 for (
typename GT::Node_Iterator it(*
gptr); it.has_curr(); it.next_ne())
658 if (get_color<GT>(it.get_curr()) ==
color)
660 first = it.get_curr();
664 if (first ==
nullptr)
718 auto gp = it.get_curr();
720 assert(is_a_cut_node <GT> (gp));
733 auto garc = it.get_curr();
734 if (is_a_cross_arc<GT>(garc))
736 cross_arc_list.
append(garc);
740 if (not is_an_cut_arc<GT>(garc))
746 assert(src !=
nullptr and tgt !=
nullptr);
804 for (
long i = 0; i < num_blocks; ++i)
808 for (
typename GT::Node_Iterator it(*
gptr); it.has_curr(); it.next_ne())
810 auto p = it.get_curr();
814 if (is_a_cut_node<GT>(p))
820 const long color = get_color<GT>(p);
873 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
903 long p_low = low<GT>(f.p);
905 for (; f.it.has_curr(); f.it.next_ne())
907 auto arc = f.it.get_curr_ne();
908 if (arc == f.parent_arc)
911 auto tgt = f.it.get_tgt_node_ne();
917 p_low = std::min(df<GT>(tgt), p_low);
928 low<GT>(f.p) = p_low;
939 auto visit = [&frames, &curr_df,
this](
typename GT::Node *n,
943 low<GT>(n) = df<GT>(n) = curr_df++;
944 return &frames.
push(n, a,
sa);
947 Frame *f = visit(p,
nullptr);
952 f = visit(tgt, f->
it.get_curr_ne());
963 low<GT>(f->
p) = std::min(low<GT>(child), low<GT>(f->
p));
965 if (low<GT>(child) > df<GT>(f->
p))
1018 __dfs(frames, start, curr_df, bridges);
1024 __dfs(frames, p, curr_df, bridges);
1085 template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
1096 template <AlephGraph GT>
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_logic_error_if(C)
Throws std::logic_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.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Find bridge edges (isthmuses) of a connected undirected graph.
DynList< typename GT::Arc * > operator()(typename GT::Node *start)
This is an overloaded member function, provided for convenience. It differs from the above function o...
GT::Node * next_child(Frame &f) noexcept(noexcept(f.it.next_ne()))
Compute_Bridges(const GT &g, SA sa=SA())
Constructor.
void __dfs(Dfs_Stack< Frame > &frames, typename GT::Node *p, long &curr_df, DynList< typename GT::Arc * > &bridges)
DynList< typename GT::Arc * > find_bridges()
This is an overloaded member function, provided for convenience. It differs from the above function o...
DynList< typename GT::Arc * > find_bridges(typename GT::Node *start)
Find all bridge edges in the graph, starting from start.
DynList< typename GT::Arc * > operator()()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Computation of cut nodes (articulation points) of a graph.
void map_cut_graph(GT &cut_graph, DynDlist< typename GT::Arc * > &cross_arc_list)
Computes the mapped cut graph of a graph.
Cut_Frame * visit(Dfs_Stack< Cut_Frame > &frames, typename GT::Node *p, typename GT::Arc *a)
void map_subgraph(GT &sg, typename GT::Node *gsrc, const long &color)
GT::Node * create_and_map_node(typename GT::Node *gp, const long &color, GT &sg)
enum Aleph::Compute_Cut_Nodes::State state
void map_subgraph(GT &sg, const long &color)
Obtains a mapped copy of the component with the given color.
void operator()(DynDlist< typename GT::Node * > &list)
This is an overloaded member function, provided for convenience. It differs from the above function o...
GT::Arc * next_to_map(Map_Frame &f, const long &color) noexcept(noexcept(f.it.next_ne()))
void paint_subgraph(typename GT::Node *p)
GT::Node * next_to_paint(Arc_Frame &f) noexcept(noexcept(f.it.next_ne()))
void cut_nodes(Dfs_Stack< Cut_Frame > &frames, typename GT::Node *p, typename GT::Arc *a)
DynDlist< typename GT::Node * > * list_ptr
GT::Node * next_child(Cut_Frame &f) noexcept(noexcept(f.it.next_ne()))
Compute_Cut_Nodes(const GT &g, SA __sa=SA())
Constructor for cut nodes calculator.
void compute_blocks(DynDlist< GT > &block_list, GT &cut_graph, DynDlist< typename GT::Arc * > &cross_arc_list)
Build mapped graphs around cut nodes.
void cut_nodes(typename GT::Node *start, DynDlist< typename GT::Node * > &list)
Computes the cut nodes.
long paint_subgraphs()
Paints the connected components around the cut nodes.
void paint_from_cut_node(typename GT::Node *p)
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.
bool has_curr() const noexcept
Return true if the iterator has current item.
T & access(const size_t i) noexcept
Fast access without checking allocation and bound_min_clock checking.
void reserve(const size_t l, const size_t r)
Allocate a range of entries.
Dynamic doubly linked list with O(1) size and bidirectional access.
T & append(const T &item)
Append a copied item at the end of the list.
void empty() noexcept
@brief Empties the container.
Doubly-linked list (defined in tpl_dynList.H).
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Node * get_first_node() const
Return any node in the graph.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
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.
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.
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.
void reset_counter_arcs() const noexcept
Reset all the counters to zero for all the arcs 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.
GT::Node * mapped_node(typename GT::Node *p) noexcept
Return the mapped node through the cookie of p
#define ARC_COOKIE(p)
Return the arc cookie
#define NODE_COUNTER(p)
Get the counter of a node.
#define IS_NODE_VISITED(p, bit)
Determine whether the control bit is set or not to one.
#define ARC_BITS(p)
Return the control bits of arc p.
#define NODE_COOKIE(p)
Return the node cookie
void clear_graph(GT &g)
Clean a graph: all its nodes and arcs are removed and freed.
#define IS_ARC_VISITED(p, bit)
Determine whether the bit field is or not set to one.
DynList< typename GT::Arc * > find_bridges(const GT &g, typename GT::Node *start, SA sa=SA())
Find all bridge edges in a connected undirected graph.
#define NODE_BITS(p)
Get the control bits of a node.
#define ALEPH_FLATTEN
[[gnu::flatten]], or nothing where it would only make the compilation slower.
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
and
Check uniqueness with explicit hash + equality functors.
constexpr long Cross_Arc
Special marker for arcs connecting a cut node to a non-cut block.
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)
Filtered iterator on all the arcs of a graph.
Node_Arc_Iterator< GT, SA > it
void next_arc() noexcept(noexcept(it.next_ne()))
Frame(typename GT::Node *n, typename GT::Arc *a, SA &sa)
Node_Arc_Iterator< GT, SA > it
Arc_Frame(typename GT::Node *p, SA &sa)
void next_arc() noexcept(noexcept(it.next_ne()))
Node_Arc_Iterator< GT, SA > it
void next_arc() noexcept(noexcept(it.next_ne()))
Cut_Frame(typename GT::Node *n, typename GT::Arc *arc, SA &sa, const long n_low)
Map_Frame(typename GT::Node *gsrc, SA &sa)
void next_arc() noexcept(noexcept(it.next_ne()))
Node_Arc_Iterator< GT, SA > it
Filtered iterator of adjacent arcs of a node.
Stack of the frames of a depth-first search that does not recurse.
Utility algorithms and operations for graphs.