Last chance! 50% off unlimited learning
Sale ends in
Solve the linear sum assignment problem using the Hungarian method.
solve_LSAP(x, maximum = FALSE)
An object of class "solve_LSAP"
with the optimal assignment of
rows to columns.
a matrix with nonnegative entries and at least as many columns as rows.
a logical indicating whether to minimize of maximize the sum of assigned costs.
Walter Böhm Walter.Boehm@wu.ac.at kindly provided C code implementing the Hungarian method.
If x
, solve_LSAP
finds an optimal assignment of rows
to columns, i.e., a one-to-one map p
of the numbers from 1 to
x
is a square matrix) such that
This assignment can be found using a linear program (and package
lpSolve provides a function lp.assign
for doing so), but
typically more efficiently and provably in polynomial time
C. Papadimitriou and K. Steiglitz (1982), Combinatorial Optimization: Algorithms and Complexity. Englewood Cliffs: Prentice Hall.
x <- matrix(c(5, 1, 4, 3, 5, 2, 2, 4, 4), nrow = 3)
solve_LSAP(x)
solve_LSAP(x, maximum = TRUE)
## To get the optimal value (for now):
y <- solve_LSAP(x)
sum(x[cbind(seq_along(y), y)])
Run the code above in your browser using DataLab