\name{munkres}
\alias{munkres}
\title{ 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{
  \item{x}{ numeric cost matrix }
  \item{tieorder}{ default TRUE to order the diagonal }
  \item{tiebreak}{ default TRUE to break ties at random when ordering the diagonal}
  \item{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
  \item{row}{index for reordering the rows}
  \item{col}{index for reordering the columns}
}
\references{ xx }
\author{ Jens Oehlschlägel }
\seealso{ \code{\link{tieorder}}, \code{\link{matchindex}}, \code{\link[clue]{solve_LSAP}}, \code{\link[e1071]{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]
}
\keyword{ utilities }
