Function hungarian::hungarian
[−]
[src]
pub fn hungarian(matrix: &[u64], w: usize, h: usize) -> Vec<usize>
Implementation of the Hungarian / Munkres Assignment Algorithm.
Given a cost matrix, this algorithm finds a perfect matching such that the total cost is minimized. Follows the outline explained here.
Takes:
matrix: &[u64]
: a 1D slice in row-major order, representing a 2D matrixw
: width ofmatrix
(i.e. number of columns)h
: height ofmatrix
(i.e. number of rows)
Returns:
v
: A Vec such thatv[i]
is the column assigned to rowi
.
Requires:
matrix
is square (i.e.w
==h
).matrix
can be padded with 0's if non-square, without changing the solution.- Should also work if
w
>h
, but there are currently no test cases for this scenario.