|
ADS
Algorithms and Data Structures
|
Matchings, the sets of edges of a graph no two of which share an end beyond the capacities of the ends. More...
Files | |
| file | ADS/graph/Matching.h |
| Matchings, the sets of edges of a graph no two of which share an end beyond the capacities of the ends: | |
Functions | |
| std::vector< std::pair< int, int > > | ADS::bipartiteBMatching (const std::vector< std::vector< int > > &A, int nr, const std::vector< long long > &capL, const std::vector< long long > &capR) |
| the pairs \( ( u , v ) \) of a \( b \)-matching of largest size, \( A[ u ] \) the nodes on the right adjacent to the node \( u \) on the left, \( u \) in at most \( \mathit{capL}[ u ] \) pairs and \( v \) in at most \( \mathit{capR}[ v ] \) | |
| template<class W> | |
| std::pair< W, std::vector< std::size_t > > | ADS::branchAndBoundMatching (int n, const std::vector< std::tuple< int, int, W > > &E) |
| the largest total weight of a matching of the graph of \( n \) nodes and of the edges \( E = ( u , v , w ) \) by a branch and bound, and the places in \( E \) of its edges, in increasing order | |
Matchings, the sets of edges of a graph no two of which share an end beyond the capacities of the ends.
The definitions, the invariants and the costs of the area are in Theory of graphs.
|
inline |
the pairs \( ( u , v ) \) of a \( b \)-matching of largest size, \( A[ u ] \) the nodes on the right adjacent to the node \( u \) on the left, \( u \) in at most \( \mathit{capL}[ u ] \) pairs and \( v \) in at most \( \mathit{capR}[ v ] \)
In pseudocode (a maximum flow of section 15.2):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{bipartiteBMatching}( A , n_r , \mathit{capL} , \mathit{capR} ) \cr 2 & \quad N \gets \text{a network of the nodes on the left, those on the } \text{right, a source } s \text{ and a sink } t \cr 3 & \quad \textbf{foreach}\ u\ \textbf{do}\ \text{add } ( s , u ) \text{ } \text{with capacity } \mathit{capL}[ u ] \cr 4 & \quad \textbf{foreach}\ u , v \in A[ u ]\ \textbf{do}\ \text{add } ( u , v ) \text{ with capacity } 1 \cr 5 & \quad \textbf{foreach}\ v\ \textbf{do}\ \text{add } ( v , t ) \text{ } \text{with capacity } \mathit{capR}[ v ] \cr 6 & \quad N.\mathrm{maxFlow}( s , t ) \cr 7 & \quad \textbf{return}\ \text{the pairs } ( u , v ) \text{ whose edge } \text{carries flow 1} \end{array}} \]
| std::pair< W, std::vector< std::size_t > > ADS::branchAndBoundMatching | ( | int | n, |
| const std::vector< std::tuple< int, int, W > > & | E ) |
the largest total weight of a matching of the graph of \( n \) nodes and of the edges \( E = ( u , v , w ) \) by a branch and bound, and the places in \( E \) of its edges, in increasing order
In pseudocode (a branch and bound): the nodes are decided in increasing order, and a branch is cut when twice its weight plus the best weight at each node left cannot beat twice the best one found, since each edge touches two nodes.
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{search}( u ) \cr 2 & \quad \textbf{while}\ u < n\ \textbf{and}\ \mathit{used}[ u ] \ \textbf{do}\ u \gets u + 1 \cr 3 & \quad \textbf{if}\ u = n\ \textbf{then} \cr 4 & \qquad \textbf{if}\ w( S ) > w( B )\ \textbf{then}\ B \gets S \cr 5 & \qquad \textbf{return} \cr 6 & \quad \textbf{if}\ 2 w( S ) + \sum_{x \ge u} \mathit{top}[ x ] \le 2 w( B )\ \textbf{then return} \cr 7 & \quad \textbf{foreach}\ \text{edge } e = [ u , v ] \text{ with } v > u\ \textbf{and not}\ \mathit{used}[ v ]\ \textbf{do} \cr 8 & \qquad \mathit{used}[ u ] , \mathit{used}[ v ] \gets \textbf{true};\ S \gets S \cup \{ e \};\ \mathrm{search}( u + 1 ) \cr 9 & \qquad S \gets S \setminus \{ e \};\ \mathit{used}[ u ] , \mathit{used}[ v ] \gets \textbf{false} \cr 10 & \quad \mathrm{search}( u + 1 )\quad \triangleright\ u \text{ left } \text{unmatched} \end{array}} \]