49# ifndef TPL_BIPARTITE_H
50# define TPL_BIPARTITE_H
93 template <
class GT,
class SA = Dft_Show_Arc<GT>>
113 typename GT::Arc *a = it.get_curr();
119 typename GT::Node *q = it.get_tgt_node();
134 typename GT::Arc *a = it.get_curr();
141 typename GT::Node *q = it.get_tgt_node();
163 template <
class GT,
class SA = Dft_Show_Arc<GT>>
228 typename GT::Node *p = it.get_curr();
233 typename AN::Node *source = net.insert_node();
239 typename GT::Node *p = i.get_curr();
241 net.insert_arc(source, src, 1);
245 typename GT::Arc *arc = j.get_current_arc_ne();
247 typename AN::Arc *a = net.insert_arc(src, tgt, 1);
253 typename AN::Node *sink = net.insert_node();
259 typename GT::Node *p = it.get_curr();
267 typename AN::Arc *a = it.get_curr();
329 template <
class GT,
class SA = Dft_Show_Arc<GT>>
378 template <
class GT,
class SA>
384 constexpr long INF = std::numeric_limits<long>::max();
389 Arc *arc = it.get_current_arc_ne();
435 template <
class GT,
class SA = Dft_Show_Arc<GT>>
442 constexpr long INF = std::numeric_limits<long>::max();
468 auto bfs = [&]() ->
bool
493 Arc *arc = it.get_current_arc_ne();
539 template <
class GT,
class 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.
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.
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.
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 & insert(const T &item)
Insert a new item by copy.
T & append(const T &item)
Append a new item by copy.
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>.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
constexpr bool is_empty() const noexcept
Return true if list is empty.
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< int > Node
The graph type.
Graph_Arc< int > 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)
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
RAII guards for graph node/arc cookies.
List_Graph< Graph_Node< int >, Graph_Arc< int > > GT
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
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)
static long & color(typename GT::Node *p)
DynList< T > maps(const C &c, Op op)
Classic map operation.
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 graph implemented with double-linked adjacency lists.
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.