Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Fixing problems with MST Kruskal's on SimpleWeightedGraphs #835

Merged
merged 23 commits into from
Feb 6, 2018
Merged
4 changes: 2 additions & 2 deletions src/spanningtrees/kruskal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ distance matrix `distmx` using [Kruskal's algorithm](https://en.wikipedia.org/wi
"""
function kruskal_mst end
# see https://github.com/mauro3/SimpleTraits.jl/issues/47#issuecomment-327880153 for syntax
@traitfn function kruskal_mst{T, U, AG<:AbstractGraph{U}}(
@traitfn function kruskal_mst{T<:Real, U, AG<:AbstractGraph{U}}(
g::AG::(!IsDirected),
distmx::AbstractMatrix{T} = weights(g)
)
Expand All @@ -42,7 +42,7 @@ function kruskal_mst end
sizehint!(mst, ne(g))

for e in edges(g)
heappush!(edge_list, KruskalHeapEntry{T}(e, distmx[src(e), dst(e)]))
heappush!(edge_list, KruskalHeapEntry{T}(Edge(src(e), dst(e)), distmx[src(e), dst(e)]))
end

while !isempty(edge_list) && length(mst) < nv(g) - 1
Expand Down
8 changes: 4 additions & 4 deletions src/spanningtrees/prim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ distance matrix `distmx` using [Prim's algorithm](https://en.wikipedia.org/wiki/
Return a vector of edges.
"""
function prim_mst end
@traitfn function prim_mst(
g::::(!IsDirected),
distmx::AbstractMatrix = weights(g)
@traitfn function prim_mst{T<:Real, U, AG<:AbstractGraph{U}}(
g::AG::(!IsDirected),
distmx::AbstractMatrix{T} = weights(g)
)
pq = Vector{PrimHeapEntry}()
pq = Vector{PrimHeapEntry{T}}()
mst = Vector{Edge}()
marked = zeros(Bool, nv(g))

Expand Down