Skip to content

Commit

Permalink
Provide munkres! (#11)
Browse files Browse the repository at this point in the history
Implement `munkres!`
  • Loading branch information
dourouc05 authored and Gnimuc committed Feb 9, 2018
1 parent ceda5c4 commit 04d0fed
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Munkres.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,20 @@ julia> full(matching)
```
"""
function munkres(costMat::AbstractMatrix{T}) where T <: Real
size(costMat,2) size(costMat,1) || throw(ArgumentError("Non-square matrix should have more columns than rows."))

A = copy(costMat)
return munkres!(A)
end

"""
munkres(costMat) -> Zs
Identical to `munkres`, except that it directly modifies its input matrix `costMat`
instead of allocating a copy. *As a result, the value of this matrix in the caller
code will be modified and should therefore no more be used!* This function should
rather be used by advanced users to improve performance of critical code.
"""
function munkres!(A::AbstractMatrix{T}) where T <: Real
size(A,2) size(A,1) || throw(ArgumentError("Non-square matrix should have more columns than rows."))

# preliminaries:
# "no lines are covered;"
Expand Down Expand Up @@ -77,7 +88,7 @@ function munkres(costMat::AbstractMatrix{T}) where T <: Real
# preliminaries done, go to step 1
stepNum = 1

# if the assignment is already found, exist
# if the assignment is already found, exit
# here we adjust Munkres's algorithm in order to deal with rectangular matrices,
# so only K columns are counted here, where K = min(size(Zs))
if length(find(columnCovered)) == minimum(size(Zs))
Expand Down

0 comments on commit 04d0fed

Please sign in to comment.