munkres {truecluster}R Documentation

Hungarian method for rectangular cost matrices

Description

Rows and columns of a cost matrix are matched such that the trace costs are minimized.

Usage

  munkres(x, tieorder = TRUE, tiebreak = TRUE, decreasing = FALSE)

Arguments

x numeric cost matrix
tieorder default TRUE to order the diagonal
tiebreak default TRUE to break ties at random when ordering the diagonal
decreasing TRUE to order decreasing (default FALSE)

Details

The is a version of Munkres' hungarian method, which allows for non-square rectangular cost matrices.

Value

A list

row index for reordering the rows
col index for reordering the columns

Author(s)

Jens Oehlschlägel

References

xx

See Also

tieorder, matchindex, solve_LSAP, matchClasses

Examples

 rows <- 4
 cols <- 6
 mat <- matrix(runif(rows*cols), nrow=rows, ncol=cols)
 cat("find the matching minimizing costs\n")
 ind <- munkres(mat); mat[ind$row, ind$col]
 cat("the same with decreasing order\n")
 ind <- munkres(mat, decreasing=TRUE); mat[ind$row, ind$col]
 cat("find the matchings maximizing costs\n")
 ind <- munkres(-mat); mat[ind$row, ind$col]

[Package truecluster version 0.3 Index]