Skip to main content

linear_sum_assignment

Function linear_sum_assignment 

Source
pub fn linear_sum_assignment(
    cost: &Array2<f64>,
    maximize: bool,
) -> Result<(Vec<usize>, Vec<usize>), ErrorsJSL>
Expand description

The optimal assignment: pairs (rowᵢ, colᵢ), as many as the smaller dimension, sorted by row, minimising Σ cost[rowᵢ][colᵢ] (maximising with maximize). Each row in turn is joined to the current matching by a shortest augmenting path in the reduced costs, and the dual variables u, v are updated so that all reduced costs stay non-negative (the Hungarian method’s invariant). A tall matrix is transposed first. O(n³). Infinite costs forbid a pair; an error is returned if no complete assignment avoids them, or for NaN or −∞.