52# ifndef TPL_FIND_PATH_H
53# define TPL_FIND_PATH_H
94 template <AlephGraph
GT,
126 [[gnu::always_inline]]
177 auto here = dfs_here<Frame>(curr,
sa);
234 for (Itor<GT, SA> i(start,
sa); i.has_curr(); i.next())
236 auto arc = i.get_curr();
243 if (
find_path(frames, next_node, arc, path, op))
255 return find(g, start, path, op);
260 :
sa(
std::move(__sa))
284 return find(g, start, path, [end](
auto p) {
return p == end; });
301 find(g, start, ret, [end](
auto p) {
return p == end; });
321 find<Op>(g, start, ret, op);
325 template <
class Op = Dft_Goal_Node<GT>>
329 find<Op>(g, start, ret, op);
359 template <AlephGraph
GT,
387 for (Itor<GT, SA> i(start,
sa); i.has_curr(); i.next())
388 q.
put(i.get_current_arc());
416 for (Itor<GT, SA> i(tgt,
sa); i.has_curr(); i.next())
418 auto a = i.get_current_arc();
500 return find_path(g, start, path, [end](
auto p) {
return p == end; });
516 find_path(g, start, ret, [end](
auto p) {
return p == end; });
530 template <AlephGraph
GT,
538 template <
template <
typename T>
class Q,
class Op>
549 Q<typename GT::Arc *> q;
550 for (Itor<GT, SA> it(start,
sa); it.has_curr(); it.next())
552 auto a = it.get_curr();
561 typename GT::Node *end =
nullptr, *curr =
nullptr;
562 while (not q.is_empty())
581 for (Itor<GT, SA> it(curr,
sa); it.has_curr(); it.next())
583 auto a = it.get_curr();
619 :
g(__g),
sa(
std::move(__sa)) {}
624 return find<DynListStack, Op>(start, op);
630 return find<DynListStack, Op>(start, op);
636 return find<DynListQueue, Op>(start, op);
642 return find<DynListQueue, Op>(start, op);
647 return dfs(start, [end](
auto p) {
return p == end; });
652 return bfs(start, [end](
auto p) {
return p == end; });
Exception handling system with formatted messages for Aleph-w.
#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
Stack of the frames of a depth-first search that does not recurse.
void clear() noexcept
Destroys all the frames, and keeps the room.
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.
Path search on directed graphs defined through a graph class (not a digraph).
Directed_Find_Path(const GT &__g, SA &__sa)
Path< GT > dfs(typename GT::Node *start, Op &&op)
Path< GT > dfs(typename GT::Node *start, Op &op)
Path< GT > bfs(typename GT::Node *start, typename GT::Node *end)
Path< GT > dfs(typename GT::Node *start, typename GT::Node *end)
Directed_Find_Path(const GT &__g, SA &&__sa=SA())
Path< GT > find(typename GT::Node *start, Op &op)
Path< GT > bfs(typename GT::Node *start, Op &&op)
Path< GT > bfs(typename GT::Node *start, Op &op)
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.
Performs a breadth-first search for a path between a pair of nodes.
Path< GT > operator()(const GT &g, typename GT::Node *start, Op &op)
Invokes the breadth-first path search.
Find_Path_Breadth_First(SA &_sa)
bool find_path(const GT &g, typename GT::Node *start, Path< GT > &path, Op &&op)
bool find_path(const GT &g, typename GT::Node *start, Path< GT > &path, Op &op)
Find_Path_Breadth_First(SA &&_sa=SA())
Performs a depth-first search for a path between a pair of nodes.
Find_Path_Depth_First(SA &&__sa=SA())
Find_Path_Depth_First(SA &__sa)
bool operator()(const GT &g, typename GT::Node *start, typename GT::Node *end, Path< GT > &path)
Invokes the depth-first path search.
bool find_path(Dfs_Stack< Frame > &frames, typename GT::Node *curr, typename GT::Arc *arc, Path< GT > &path, Op &op)
GT::Node * next_target(Frame &f, Op &op, bool &found)
static void remove_last_node(Path< GT > &path)
bool find(const GT &g, typename GT::Node *start, Path< GT > &path, Op &&op)
bool find(const GT &g, typename GT::Node *start, Path< GT > &path, Op &op)
A filter that an algorithm object keeps: one given as an lvalue is used where it is,...
Filtered iterator for outcoming arcs of a node.
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 insert_directed(Node *p)
Insert a node at the beginning of a directed path.
Node * get_first_node() const
Return the first node of path; throws overflow_error if path is empty.
bool inside_graph(const GT &gr) const noexcept
Return true if this is on graph gr
void set_graph(const GT &__g, Node *start_node=nullptr)
Set the graph of the path.
void append(Arc *arc)
Append an arc to the path.
Node * remove_last_node()
Remove the last node of path.
void set_state(unsigned int s) noexcept
Set the state to value s
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)
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
void reset_bit_arcs(int bit) const noexcept
Reset bit 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)
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
const unsigned char Processed
The node or arc has already been processed.
void dfs_replace(T &here, Args &&...args)
Replaces the frame that a Dfs_Here holds with one built with args, by assignment.
const unsigned char Processing
The node are being processed; probably it is inside a queue, stack or heap.
#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
decltype(auto) dfs_curr(const It &it)
The current item of an iterator that has one.
T & dfs_frame(T &here) noexcept
The frame that a Dfs_Here holds.
#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()
Advance all underlying iterators (bounds-checked).
bool operator()(typename GT::Node *) const noexcept
Default filter for filtered iterators on arcs.
Frame(typename GT::Node *p, SA &sa)
Filtered iterator of adjacent arcs of a node.
Stack of the frames of a depth-first search that does not recurse.
Dynamic queue implementation based on linked lists.
Dynamic stack implementation based on linked lists.
Utility algorithms and operations for graphs.