43# ifndef GRAPH_TRAVERSE_H
44# define GRAPH_TRAVERSE_H
82template <AlephGraph
GT,
class Itor,
129 template <
class Node_Op>
142 for (Itor it(start,
sa); it.has_curr(); it.next_ne())
144 typename GT::Arc *a = it.get_curr();
150 const size_t n =
g.
vsize();
153 typename GT::Arc *arc = q.get();
169 for (Itor it(curr,
sa); it.has_curr(); it.next_ne())
171 typename GT::Arc *a = it.get_curr();
184 template <
class Node_Op>
187 return (*
this)(start, op);
208 if (
not op(start,
nullptr))
211 using Pair = std::tuple<typename GT::Node *, typename GT::Arc *>;
213 for (Itor it(start,
sa); it.has_curr(); it.next_ne())
215 typename GT::Arc *a = it.get_curr();
218 q.put(std::make_tuple(start, a));
221 const size_t n =
g.
vsize();
224 const Pair p = q.get();
234 if (
not op(curr, arc))
237 for (Itor it(curr,
sa); it.has_curr(); it.next_ne())
239 typename GT::Arc *a = it.get_curr();
244 q.put(std::make_tuple(curr, a));
252 template <
class Operation>
255 return exec(start, op);
265 template <
class Node_Op,
class Arc_Op>
274 size_t node_count = 1;
279 return std::make_tuple(1, 0);
281 for (Itor it(start,
sa); it.has_curr(); it.next_ne())
283 typename GT::Arc *a = it.get_curr();
300 return std::make_tuple(node_count,
arc_count);
306 while (
not q.is_empty())
308 typename GT::Arc *arc = q.get();
322 return std::make_tuple(node_count,
arc_count);
324 for (Itor it(curr,
sa); it.has_curr(); it.next_ne())
326 typename GT::Arc *a = it.get_curr();
337 return std::make_tuple(node_count,
arc_count);
344 return std::make_tuple(node_count,
arc_count);
348 template <
class Node_Op,
class Arc_Op>
350 Node_Op &&
node_op = Node_Op(),
358template <
class GT,
class Itor,
362template <
class GT,
class Itor,
C++20 concepts for the protocol shared by graph algorithms.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Dynamic stack of elements of generic type T based on a singly linked list.
void set_state(unsigned int s) noexcept
Set the state of arc to value s
unsigned int state() const noexcept
Return the state of arc.
unsigned int state() const noexcept
Return the state's value.
void set_state(unsigned int s) noexcept
Set the state to value s
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.
constexpr size_t vsize() const noexcept
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)
Traverse a graph depth-first or breadth-first and execute a visit function.
static bool seed_arc(typename GT::Arc *a, typename GT::Node *tgt) noexcept
Prepare arc a (leading to tgt) for frontier expansion out of start/curr, and report whether the calle...
size_t operator()(typename GT::Node *start, Node_Op &op)
Traverse the graph starting from start and execute op on each node.
Graph_Traverse(GT &__g, Show_Arc __sa=Show_Arc())
Construct a traverser with a graph and arc filter.
size_t exec(typename GT::Node *start, Operation &&op=Operation())
This is an overloaded member function, provided for convenience. It differs from the above function o...
size_t exec(typename GT::Node *start, Op &op)
Execute operation op(curr, arc) where curr is the visited node and arc is the incoming arc.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
and
Check uniqueness with explicit hash + equality functors.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Default filter for filtered iterators on arcs.
Array-based graph implementation.
Dynamic queue implementation based on linked lists.
Dynamic stack implementation based on linked lists.