80#ifndef __ADS_Assignment
81 #define __ADS_Assignment
102#if defined( ADS_WITH_LEMON ) && ! defined( ADS_ASSIGNMENT_LEMON ) && \
103 __has_include( <lemon/bipartite_matching.h> )
104 #define ADS_ASSIGNMENT_LEMON 1
106#if defined( ADS_ASSIGNMENT_LEMON ) && ADS_ASSIGNMENT_LEMON
107 #include <lemon/bipartite_matching.h>
108 #include <lemon/smart_graph.h>
133template<
class E ,
class W >
135 std::default_initializable< E > &&
136 requires( E & x ,
int n ,
const std::vector< W > & C ,
bool all ,
137 const std::vector< std::pair< int , int > > & D ,
138 std::vector< int > & col , std::vector< W > & u ,
139 std::vector< W > & v )
141 { x.solve( n , C , all , D , col , u , v ) } -> std::convertible_to< int >;
147template<
class W =
long long , ReoptPolicy P = RatioPolicy ,
class E =
void >
148 requires std::is_arithmetic_v< W > &&
163 [[nodiscard]]
int n(
void )
const {
return( f_n ); }
167 [[nodiscard]] W
cost(
int i ,
int j )
const;
176 void setRow(
int i ,
const std::vector< W > & R );
214 [[nodiscard]]
int row(
int j );
235 [[nodiscard]]
int outcome(
void )
const {
return( f_outcome ); }
243 [[nodiscard]]
int cause(
void )
const {
return( f_cause ); }
247 [[nodiscard]]
long long byCause(
int c )
const {
249 return( f_byCause[ c ] );
254 [[nodiscard]] P &
policy(
void ) {
return( f_policy ); }
256 [[nodiscard]]
const P &
policy(
void )
const {
return( f_policy ); }
264 [[nodiscard]] W reduced(
int i ,
int j )
const {
265 return( f_C[ std::size_t( i ) * std::size_t( f_n ) + std::size_t( j ) ] -
266 f_u[ i ] - f_v[ j ] );
270 [[nodiscard]]
bool finite(
int i ,
int j )
const {
271 return( f_C[ std::size_t( i ) * std::size_t( f_n ) + std::size_t( j ) ] !=
276 void freeRow(
int i );
280 bool engineSolve(
void );
282#if defined( ADS_ASSIGNMENT_LEMON ) && ADS_ASSIGNMENT_LEMON
285 bool lemonScratch(
void );
318 bool augment(
int i0 );
321 [[nodiscard]]
bool optimal(
void )
const;
324 std::vector< W > f_C;
325 std::vector< W > f_u;
326 std::vector< W > f_v;
327 std::vector< int > f_col;
328 std::vector< int > f_row;
329 std::vector< char > f_dirtyR;
330 std::vector< char > f_dirtyC;
331 std::vector< int > f_DR;
332 std::vector< int > f_DC;
333 std::vector< std::pair< int , int > > f_cells;
335 std::vector< W > f_dist;
336 std::vector< int > f_pred;
337 std::vector< char > f_scanned;
338 std::vector< int > f_order;
339 bool f_ready =
false;
340 bool f_pending =
false;
343 long long f_count[ 3 ] = { 0 , 0 , 0 };
348 std::conditional_t< std::is_void_v< E > , std::monostate , E > f_engine{};
361#include "ADS/graph/impl/Assignment.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The typed modifications, beyond the book: the vocabulary by which a structure tells the observers att...
The shortest paths of chapter 11 from a node of an oriented GRAPH whose edges have a cost [see Grap...
W rowPotential(int i)
the potential of the row , a solution of the dual with those of the columns
void setCost(int i, int j, W c)
the cost of set to , worked at the next query
long long byCause(int c) const
the solves of each cause so far
Definition Assignment.h:247
void solve(void)
brings the assignment up to date
void setRow(int i, const std::vector< W > &R)
the costs of the row set to
int column(int i)
the column of the row , if none (no perfect matching of finite costs)
long long count(int outcome) const
the solves of each outcome so far
Definition Assignment.h:238
W Weight
the type of the costs
Definition Assignment.h:155
bool perfect(void)
whether every row has a column, i.e., a perfect matching of finite costs exists
int row(int j)
the row of the column , if none
Assignment(int n, std::vector< W > C)
the assignment of the costs , the row in , computed at the first query
void setColumn(int j, const std::vector< W > &K)
the costs of the column set to
int outcome(void) const
how the last solve() with changes, or with no assignment yet, did it [see Reopt of Modification....
Definition Assignment.h:235
W columnPotential(int j)
the potential of the column
long long augmentations(void) const
the augmentations so far
Definition Assignment.h:259
P & policy(void)
the recompute policy, whose abandon() decides the scratch of line 2 [see RatioPolicy]
Definition Assignment.h:254
int n(void) const
the number of rows, and of columns
Definition Assignment.h:163
int cause(void) const
why: the cause of the last outcome [see Reopt]
Definition Assignment.h:243
W cost(int i, int j) const
the cost of the row and the column
const P & policy(void) const
the recompute policy
Definition Assignment.h:256
W total(void)
the total cost of the pairs of the assignment
the engines of the solves of an Assignment, objects that it keeps: solve( n , C , all ,...
Definition Assignment.h:134
#define ADS_PRE(cond)
[check]
Definition Contract.h:121
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
constexpr D infinity(void)
the infinite distance of the type D
Definition ShortestPaths.h:146
static constexpr int SCRATCH_BY_EVENT
from scratch, Rebuilt,
Definition Modification.h:191
static constexpr int CAUSES
the number of the causes
Definition Modification.h:196