Minimum-cost perfect matching on a square matrix of finite costs (the Hungarian algorithm, O(n³), by shortest augmenting paths with potentials), for BarcodeDistance.wassersteinDistance.
cost must be square (n x n), all entries finite. Returns (assignment, totalCost) where assignment(j) is the row matched to column j, and totalCost = sum_j cost(assignment(j))(j).
cost must be square (n x n), all entries finite. Returns (assignment, totalCost) where assignment(j) is the row matched to column j, and totalCost = sum_j cost(assignment(j))(j).
Classic 1-indexed potential formulation (row/column 0 are sentinels): u/v are the row/column potentials, p(j) is the row currently assigned to column j (0 = none yet), way(j) records the augmenting path taken to reach column j so the final augmentation can be replayed.