Skip to content

Commit

Permalink
Merge pull request #11 from kdw503/dwk/update
Browse files Browse the repository at this point in the history
Update for julia 0.7
  • Loading branch information
JoshChristie authored Oct 7, 2018
2 parents 37449a9 + d4ca7d9 commit 90a94a1
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 53 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ os:
- linux
- osx
julia:
- 0.4
- 0.5
- 0.6
- 0.7
- 1.0
- nightly
notifications:
email: false
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.4
julia 0.7
46 changes: 24 additions & 22 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1
- julia_version: nightly

platform:
- x86 # 32-bit
- x64 # 64-bit

# # Uncomment the following lines to allow failures on nightly julia
# # (tests will run but not make your overall status red)
# matrix:
# allow_failures:
# - julia_version: nightly

branches:
only:
Expand All @@ -21,21 +26,18 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia

build: off
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"Munkres\"); Pkg.build(\"Munkres\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"Munkres\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
30 changes: 15 additions & 15 deletions src/Munkres.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Munkres

export munkres

immutable Location
struct Location
row::Int
col::Int
end
Expand All @@ -14,13 +14,13 @@ valid(loc::Location) = loc.row > 0 && loc.col > 0
const StarMark=1
const PrimeMark=2

type ModifiedCost
mutable struct ModifiedCost
m::Matrix{Float64}
row_offsets::Vector{Float64}
column_offsets::Vector{Float64}
end

function ModifiedCost{T<:Real}(cost_matrix::Matrix{T})
function ModifiedCost(cost_matrix::Matrix{T}) where T<:Real
ModifiedCost(cost_matrix,
zeros(eltype(cost_matrix), size(cost_matrix,1)),
zeros(eltype(cost_matrix), size(cost_matrix,2)))
Expand Down Expand Up @@ -65,7 +65,7 @@ function munkres(cost_matrix)
flipped = false
if n > m
#always use more jobs than workers (current implmentation doesn't work in other case, so just transpose)
cost_matrix = cost_matrix'
cost_matrix = Array(cost_matrix')
flipped = true
n,m = size(cost_matrix)
end
Expand Down Expand Up @@ -107,8 +107,8 @@ end

function step_one!(cost)
#remove row minimum from cost matrix and find locations of all zeros
cost.row_offsets = vec(minimum(cost.m,2))
zero_locations = [find(j->iszero(cost,i,j), 1:size(cost,2)) for i=1:size(cost,1)]
cost.row_offsets = vec(minimum(cost.m, dims=2))
zero_locations = [findall(j->iszero(cost,i,j), 1:size(cost,2)) for i=1:size(cost,1)]
end


Expand All @@ -124,8 +124,8 @@ function step_two!(cost, mask_array, row_cover, column_cover)
end
end
end
row_cover[:] = false
column_cover[:] = false
row_cover[:] .= false
column_cover[:] .= false
end


Expand Down Expand Up @@ -201,7 +201,7 @@ function step_five!(mask_array, row_cover, column_cover, path_start)
row = -1
column = -1

path = Vector{Location}(0)
path = Vector{Location}()
push!(path, path_start)

while ~done
Expand All @@ -217,8 +217,8 @@ function step_five!(mask_array, row_cover, column_cover, path_start)
end
end
augment_path!(path, mask_array)
row_cover[:] = false
column_cover[:] = false
row_cover[:] .= false
column_cover[:] .= false
erase_primes!(mask_array)
return 3
end
Expand All @@ -236,8 +236,8 @@ function step_six!(cost,row_cover,column_cover, zero_locations)
push!(zero_locations[min_locations[i][1]],min_locations[i][2])
end

cost.row_offsets[row_cover] -= min_value
cost.column_offsets[map(!, column_cover)] += min_value
cost.row_offsets[row_cover] .-= min_value
cost.column_offsets[map(!, column_cover)] .+= min_value

#need to deal with any zeros going away in covered columns and rows
for i = 1:length(zero_locations)
Expand Down Expand Up @@ -302,8 +302,8 @@ end
function find_smallest_uncovered(cost, row_cover, column_cover)
#find the locations and value of the minimum of the cost matrix in the uncovered rows and columns
min_value = typemax(eltype(cost))
uncovered_row_inds = find(map(!, row_cover))
uncovered_col_inds = find(map(!, column_cover))
uncovered_row_inds = findall(map(!, row_cover))
uncovered_col_inds = findall(map(!, column_cover))
min_locations = Tuple{Int, Int}[]
for j in uncovered_col_inds, i in uncovered_row_inds
@inbounds c = cost[i,j]
Expand Down
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Combinatorics
LinearAlgebra
24 changes: 12 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Munkres
using Base.Test
using Combinatorics # Required for permutations() on 0.5
using Test
using Combinatorics, LinearAlgebra # Required for permutations() on 0.5


"""
Expand Down Expand Up @@ -36,29 +36,29 @@ tst = [1 2 3;


for i=1:10
tst = rand(8,8)
@test munkres(tst) == brute_force_optima(tst)
tst1 = rand(8,8)
@test munkres(tst1) == brute_force_optima(tst1)
end

for i=1:10
# Exponentially distributed test for pathological floating point truncation
tst = 10.^(50*rand(8,8))
@test munkres(tst) == brute_force_optima(map(BigFloat, tst))
tst1 = 10 .^(50*rand(8,8))
@test munkres(tst1) == brute_force_optima(map(BigFloat, tst1))
end

tst = -eye(10)
tst = -Matrix(1.0I, 10, 10)
@test munkres(tst) == brute_force_optima(tst)

#test non-square behaviour on 1 x n and n x 1 arrays

for i=1:10
tst = rand(1,10)
@test munkres(tst)[1] == indmin(tst)
tst1 = rand(1,10)
@test munkres(tst1)[1] == argmin(tst1)[2]
end

for i=1:10
tst = rand(10,1)
@test findfirst(munkres(tst).==1) == indmin(tst)
tst1 = rand(10,1)
@test findfirst(munkres(tst1).==1) == argmin(tst1)[1]
end

#test against solutions from Yi Cao's matlab code
Expand All @@ -85,7 +85,7 @@ tst = [ 678.0 24.0 601.0 34.0 747.0 455.0 871.0 714.0 64.0 547.0
442.0 59.0 979.0 463.0 161.0 240.0 328.0 949.0 409.0 299.0
116.0 313.0 820.0 929.0 347.0 958.0 918.0 806.0 999.0 400.0]

p = [9, 2, 0, 4, 0, 7, 0, 0, 1, 0, 6, 0, 0, 0, 3, 5, 8, 10, 0, 0]
p = [9, 2, nothing, 4, nothing, 7, nothing, nothing, 1, nothing, 6, nothing, nothing, nothing, 3, 5, 8, 10, nothing, nothing]

@test munkres(tst) == p

Expand Down

0 comments on commit 90a94a1

Please sign in to comment.