an assignment of least cost of \( n \) rows to \( n \) columns, kept optimal after the changes of the costs, by the code of ADS or, if E is not void, by the engine E
More...
#include <ADS/graph/Assignment.h>
|
| using | Weight = W |
| | the type of the costs
|
|
| | Assignment (int n, std::vector< W > C) |
| | the assignment of the costs \( C \), the row \( i \) in \( C[ i n .. i n + n - 1 ] \), computed at the first query
|
| int | n (void) const |
| | the number of rows, and of columns
|
| W | cost (int i, int j) const |
| | the cost of the row \( i \) and the column \( j \)
|
| void | setCost (int i, int j, W c) |
| | the cost of \( ( i , j ) \) set to \( c \), worked at the next query
|
| void | setRow (int i, const std::vector< W > &R) |
| | the costs of the row \( i \) set to \( R \)
|
| void | setColumn (int j, const std::vector< W > &K) |
| | the costs of the column \( j \) set to \( K \)
|
| void | solve (void) |
| | brings the assignment up to date
|
| int | column (int i) |
| | the column of the row \( i \), \( -1 \) if none (no perfect matching of finite costs)
|
| int | row (int j) |
| | the row of the column \( j \), \( -1 \) if none
|
| bool | perfect (void) |
| | whether every row has a column, i.e., a perfect matching of finite costs exists
|
| W | total (void) |
| | the total cost of the pairs of the assignment
|
| W | rowPotential (int i) |
| | the potential \( u_i \) of the row \( i \), a solution of the dual with those of the columns
|
| W | columnPotential (int j) |
| | the potential \( v_j \) of the column \( j \)
|
| int | outcome (void) const |
| | how the last solve() with changes, or with no assignment yet, did it [see Reopt of Modification.h]: 0 from scratch, 1 by the augmentations of the rows freed, 2 with no work
|
| long long | count (int outcome) const |
| | the solves of each outcome so far
|
| int | cause (void) const |
| | why: the cause of the last outcome [see Reopt]
|
| long long | byCause (int c) const |
| | the solves of each cause so far
|
| P & | policy (void) |
| | the recompute policy, whose abandon() decides the scratch of line 2 [see RatioPolicy]
|
| const P & | policy (void) const |
| | the recompute policy
|
| long long | augmentations (void) const |
| | the augmentations so far
|
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
requires std::is_arithmetic_v< W > && ( std::is_void_v< E > || AssignmentEngine< E , W > )
class ADS::Assignment< W, P, E >
an assignment of least cost of \( n \) rows to \( n \) columns, kept optimal after the changes of the costs, by the code of ADS or, if E is not void, by the engine E
◆ Weight
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
◆ Assignment()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the assignment of the costs \( C \), the row \( i \) in \( C[ i n .. i n + n - 1 ] \), computed at the first query
- Precondition
- \( n \ge 0 \), \( |C| = n^2 \)
◆ augmentations()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
◆ byCause()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the solves of each cause so far
- Precondition
- \( c \in [ 1 , \mathrm{Reopt::CAUSES} ) \)
◆ cause()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
why: the cause of the last outcome [see Reopt]
◆ column()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the column of the row \( i \), \( -1 \) if none (no perfect matching of finite costs)
- Precondition
- \( i \in [ 0 , n ) \)
◆ columnPotential()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the potential \( v_j \) of the column \( j \)
- Precondition
- \( j \in [ 0 , n ) \)
◆ cost()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the cost of the row \( i \) and the column \( j \)
- Precondition
- \( i , j \in [ 0 , n ) \)
◆ count()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the solves of each outcome so far
◆ n()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the number of rows, and of columns
◆ outcome()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
how the last solve() with changes, or with no assignment yet, did it [see Reopt of Modification.h]: 0 from scratch, 1 by the augmentations of the rows freed, 2 with no work
◆ perfect()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
whether every row has a column, i.e., a perfect matching of finite costs exists
◆ policy() [1/2]
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the recompute policy, whose abandon() decides the scratch of line 2 [see RatioPolicy]
◆ policy() [2/2]
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
◆ row()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the row of the column \( j \), \( -1 \) if none
- Precondition
- \( j \in [ 0 , n ) \)
◆ rowPotential()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the potential \( u_i \) of the row \( i \), a solution of the dual with those of the columns
- Precondition
- \( i \in [ 0 , n ) \)
◆ setColumn()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
| void ADS::Assignment< W, P, E >::setColumn |
( |
int | j, |
|
|
const std::vector< W > & | K ) |
the costs of the column \( j \) set to \( K \)
- Precondition
- \( j \in [ 0 , n ) \), \( |K| = n \)
◆ setCost()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the cost of \( ( i , j ) \) set to \( c \), worked at the next query
- Precondition
- \( i , j \in [ 0 , n ) \)
◆ setRow()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
| void ADS::Assignment< W, P, E >::setRow |
( |
int | i, |
|
|
const std::vector< W > & | R ) |
the costs of the row \( i \) set to \( R \)
- Precondition
- \( i \in [ 0 , n ) \), \( |R| = n \)
◆ solve()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
brings the assignment up to date
In pseudocode (beyond the book; it is correct by Lemma 15 of The assignment and its reoptimization), with \( u \) and \( v \) the potentials of the rows and of the columns, \( D_r \) and \( D_c \) the rows and the columns changed since the last query:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{solve}() \cr
2 & \quad \textbf{if}\ \text{there is no assignment yet}
\textbf{ or } p.\mathrm{abandon}( |D_r| + |D_c| , n )
\ \textbf{then} \cr
3 & \qquad v \gets 0;\ u_i \gets \min_j c( i , j ) \text{ for each }
i;\ \text{every row free} \cr
4 & \quad \textbf{else} \cr
5 & \qquad \textbf{foreach}\ i \in D_r\ \textbf{do}\ \text{free } i;
\ u_i \gets \min_j ( c( i , j ) - v_j ) \cr
6 & \qquad \textbf{foreach}\ j \in D_c\ \textbf{do}\ \text{free } j;
\ v_j \gets \min_i ( c( i , j ) - u_i ) \cr
7 & \quad \textbf{foreach}\ \text{free row } i\ \textbf{do}
\ \mathrm{augment}( i )
\end{array}}
\]
◆ total()
template<class W = long long, ReoptPolicy P = RatioPolicy, class E = void>
the total cost of the pairs of the assignment
The documentation for this class was generated from the following file: