48#ifndef TPL_BIPARTITE_H
49#define TPL_BIPARTITE_H
69template <AlephGraph GT>
75template <AlephGraph GT>
98template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
119 typename GT::Arc *a = it.get_curr();
125 typename GT::Node *q = it.get_tgt_node();
140 typename GT::Arc *a = it.get_curr();
147 typename GT::Node *q = it.get_tgt_node();
169template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
233 typename GT::Node *p = it.get_curr();
238 typename AN::Node *source = net.insert_node();
243 typename GT::Node *p = i.get_curr();
245 net.insert_arc(source, src, 1);
249 typename GT::Arc *arc = j.get_current_arc_ne();
251 typename AN::Arc *a = net.insert_arc(src, tgt, 1);
257 typename AN::Node *sink = net.insert_node();
262 typename GT::Node *p = it.get_curr();
270 typename AN::Arc *a = it.get_curr();
329template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
378template <AlephGraph GT, ArcFilter<GT> SA>
384 constexpr long INF = std::numeric_limits<long>::max();
389 Arc *arc = it.get_current_arc_ne();
433template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
439 constexpr long INF = std::numeric_limits<long>::max();
457 for (
auto it =
left_nodes.get_it(); it.has_curr(); it.next_ne())
459 for (
auto it =
right_nodes.get_it(); it.has_curr(); it.next_ne())
464 auto bfs = [&]() ->
bool
470 for (
auto it =
left_nodes.get_it(); it.has_curr(); it.next_ne())
489 Arc *arc = it.get_current_arc_ne();
511 for (
auto it =
left_nodes.get_it(); it.has_curr(); it.next_ne())
518 for (
auto it =
left_nodes.get_it(); it.has_curr(); it.next_ne())
535template <AlephGraph GT, ArcFilter<GT> SA = Dft_Show_Arc<GT>>
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
C++20 concepts for the protocol shared by graph algorithms.
WeightedDigraph::Node Node
Class that takes a bipartite graph and computes the partition sets.
void operator()(const GT &g, DynDlist< typename GT::Node * > &l, DynDlist< typename GT::Node * > &r)
Computes the partition sets of a bipartite graph.
Class for computing the maximum cardinality matching of a bipartite graph.
void operator()(const GT &g, DynDlist< typename GT::Arc * > &matching)
Computes the maximum bipartite matching of a graph.
RAII guard that clears graph cookies on destruction.
bool has_curr() const noexcept
Return true if the iterator has current item.
void append(Dlink *node) noexcept
Insert node before this.
Dynamic doubly linked list with O(1) size and bidirectional access.
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.
T & append(const T &item)
Generic key-value map implemented on top of a binary search tree.
Dynamic set implemented using AVL binary search trees of type Avl_Tree<Key>.
Key * append(const Key &key)
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
Functor wrapper for hopcroft_karp_matching.
void operator()(const GT &g, DynDlist< typename GT::Arc * > &matching)
Computes the maximum matching using Hopcroft-Karp.
Node * get_first_node() const
Return any node in the graph.
Graph_Node< Node_Info > Node
The graph type.
Graph_Arc< Arc_Info > Arc
The node class type.
Filtered iterator on the nodes of a 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_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
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)
RAII guards for graph node/arc cookies.
void compute_bipartite(const GT &g, DynDlist< typename GT::Node * > &l, DynDlist< typename GT::Node * > &r)
Computes the partition sets of a bipartite graph.
bool compute_bipartite_all_components(const GT &g, DynDlist< typename GT::Node * > &l, DynDlist< typename GT::Node * > &r)
Computes the partition sets of a bipartite graph handling all connected components.
#define NODE_COUNTER(p)
Get the counter of a node.
void compute_maximum_cardinality_bipartite_matching(const GT &g, DynDlist< typename GT::Arc * > &matching)
Computes the maximum cardinality matching of a bipartite graph.
#define ARC_COUNTER(p)
Return the counter of arc p.
#define NODE_COOKIE(p)
Return the node cookie
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
void hopcroft_karp_matching(const GT &g, DynDlist< typename GT::Arc * > &matching)
Computes a maximum cardinality matching on a bipartite graph using the Hopcroft-Karp algorithm.
Main namespace for Aleph-w library functions.
static bool hopcroft_karp_dfs(const GT &g, typename GT::Node *u)
and
Check uniqueness with explicit hash + equality functors.
static long & color(typename GT::Node *p)
Filtered iterator on all the arcs of a graph.
Default filter for filtered iterators on arcs.
Functor wrapper for ford_fulkerson_maximum_flow().
Arc of a flow network implemented with adjacency lists.
Flow network implemented with adjacency lists.
Filtered iterator of adjacent arcs of a node.
Dynamic doubly linked list implementation.
Dynamic queue implementation based on linked lists.
Dynamic key-value map based on balanced binary search trees.
Network flow graph structures.