Use the algorithm of Jonker & Volgenant (1987) to solve the Linear Sum Assignment Problem.




Square matrix of costs.


A list with two entries: score, the score of the optimal matching; and matching, the columns matched to each row of the matrix in turn.


The Linear Assignment Problem seeks to match each row of a matrix with a column, such that the cost of the matching is minimized.

The Jonker & Volgenant approach is a faster alternative to the Hungarian algorithm (Munkres 1957), which is implemented in clue::solve_LSAP().

Note: the JV algorithm expects integers. In order to apply the function to a non-integer n, as in the tree distance calculations in this package, each n is multiplied by the largest available integer before applying the JV algorithm. If two values of n exhibit a trivial difference -- e.g. due to floating point errors -- then this can lead to interminable run times. (If numbers of the magnitude of billions differ only in their last significant digit, then the JV algorithm may undergo billions of iterations.) To avoid this, integers over 2^22 that differ by a value of 8 or less are treated as equal.

NB. At present, only square matrices are supported; if you need support for non-square matrices, drop a note at issue #25 and I'll prioritize development.


Jonker R, Volgenant A (1987). “A shortest augmenting path algorithm for dense and sparse linear assignment problems.” Computing, 38, 325--340. doi:10.1007/BF02278710 .

Munkres J (1957). “Algorithms for the assignment and transportation problems.” Journal of the Society for Industrial and Applied Mathematics, 5(1), 32--38. doi:10.1137/0105003 .


C++ code by Roy Jonker, MagicLogic Optimization Inc., with contributions from Yong Yang, after Yi Cao


problem <- matrix(c(7, 9, 8, 9,
                    2, 8, 5, 7,
                    1, 6, 6, 9,
                    3, 6, 2, 2), 4, 4, byrow=TRUE)

#> $score
#> [1] 17
#> $matching
#> [1] 2 3 1 4