52# ifndef TPL_SPANNING_TREE_H
53# define TPL_SPANNING_TREE_H
115template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
142 for (;
it.has_curr()
and tree.get_num_nodes() < g.get_num_nodes();
it.
next_ne())
144 auto arc =
it.get_current_arc_ne();
148 auto arc_tgt_node =
it.get_tgt_node_ne();
159 [[gnu::always_inline]]
181 return tree_tgt_node;
191 if (image ==
nullptr)
200 std::optional<Frame> here(std::in_place, gnode, image,
sa);
203 if (
auto tgt = here->next_target(*
tptr, *
gptr))
205 image =
put_in_tree(tgt, here->it.get_current_arc_ne(), here->tnode);
206 if (image ==
nullptr)
209 frames.
push(std::move(*here));
210 here.emplace(tgt, image,
sa);
224 if (image ==
nullptr)
227 here.emplace(tgt, image,
sa);
260 auto arc = i.get_current_arc_ne();
264 auto arc_tgt_node = i.get_tgt_node();
306 <<
"Find_Depth_First_Spanning_Tree: graph is empty";
335 <<
"Find_Depth_First_Spanning_Tree: source node cannot be null";
387template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
411 q.
put(i.get_current_arc_ne());
431 std::swap(gsrc, gtgt);
433 auto tsrc = mapped_node<GT>(gsrc);
442 auto tarc = tree.
insert_arc(tsrc, ttgt, garc->get_info());
453 auto current_arc = i.get_current_arc_ne();
495 <<
"Find_Breadth_First_Spanning_Tree: source node cannot be null";
515 <<
"Find_Breadth_First_Spanning_Tree: graph is empty";
542template <AlephGraph GT>
558 return build_spanning_tree<GT>(
arcs);
574 <<
"Build_Spanning_Tree: arcs array cannot be null";
575 return build_spanning_tree<GT>(*
arcs);
Exception handling system with formatted messages for Aleph-w.
#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.
EepicNode< long > * build_tree()
Build a spanning tree from an array of arcs.
GT operator()(const DynArray< typename GT::Arc * > &arcs) const
Construct spanning tree from array of arc pointers.
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.
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.
bool is_empty() const noexcept
Return true if this is empty.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Compute a breadth-first spanning tree of a graph.
void build_tree(GT &g, typename GT::Node *gp, GT &tree)
void operator()(GT &g, typename GT::Node *gnode, GT &tree)
Build a breadth-first spanning tree starting from a specific node.
Find_Breadth_First_Spanning_Tree(SA arc_filter=SA())
Construct a BFS spanning tree builder with optional arc filter.
Compute a depth-first spanning tree of a graph.
GT::Node * operator()(GT &g, GT &tree)
Build a depth-first spanning tree starting from the first node.
Find_Depth_First_Spanning_Tree(SA arc_filter=SA())
Construct a DFS spanning tree builder with optional arc filter.
bool build_tree(typename GT::Node *gnode, typename GT::Arc *garc, typename GT::Node *tnode)
bool build_tree(GT &g, typename GT::Node *gnode, GT &tree)
GT::Node * put_in_tree(typename GT::Node *gnode, typename GT::Arc *garc, typename GT::Node *tnode)
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)
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.
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)
static void map_arcs(A1 *p, A2 *q) noexcept
Map the arcs through their cookies.
void reset_bit_arcs(int bit) const noexcept
Reset bit to zero for all the arcs of graph.
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
void reset_nodes() const
Reset all the nodes of graph (the control bits, the state, the counter and the cookie)
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.
DynArray< Graph::Arc * > arcs
#define ARC_COOKIE(p)
Return the arc cookie
#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.
#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.
and
Check uniqueness with explicit hash + equality functors.
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).
GT::Node * next_target(const GT &tree, const GT &g) noexcept(noexcept(it.next_ne()))
Node_Arc_Iterator< GT, SA > it
void next_arc() noexcept(noexcept(it.next_ne()))
Frame(typename GT::Node *gnode, typename GT::Node *image, SA &sa)
Filtered iterator of adjacent arcs of a node.
Stack of the frames of a depth-first search that does not recurse.
Generic graph and digraph implementations.
Utility algorithms and operations for graphs.