The Linear Assignment Problem is a combinatorial optimization problem, where you want to find an optimial assignment between
where
The motivation behind LAP is to find an algorithm that is significantly more efficient than
For the different LAP algorithms, it is common to formulate them in terms of either matrices or bipartite graphs.
The Munkres LAP Algorithm based on previous works from other computer scientist (See paper), is a pretty intuitive version of LAP, where we can directly apply it on a matrix of costs
following the above definitions.
In practice, the Munkres Algorithm is very slow compared to newer versions of the LAP algorithm, such as the one implemented in SciPy. Thus, it's only of theoretical interest and shouldn't be used in practice.
First
pip install -r requirements.txt
Then
from linear_assignment import LinearAssignmentMunkres
import torch
cost_matrix = torch.Tensor([[80, 23, 80, 39, 55, 2],
[19, 59, 36, 98, 19, 94],
[82, 38, 48, 95, 65, 25],
[9, 91, 83, 8, 48, 64],
[73, 22, 23, 86, 33, 42],
[2, 20, 9, 81, 94, 16]])
lap = LinearAssignmentMunkres(cost_matrix, maximize=False)
lap.fit()
indices, sum = lap.transform()
Where the indices consists of the assignments of row
I may implement more efficient versions of this algorithm, starting with Jonker and Volgenant.