-
Notifications
You must be signed in to change notification settings - Fork 185
Add Karp's minimum cycle mean algorithm #739
Conversation
I get the following failure Diffusion Simulation: Test Failed
Expression: avg > means[p] - (stds[p] / sqrt(runs)) * 3.5
Evaluated: 0.8999999999999999 > 1.0100505063388334 However, I don't see how the PR have affected this. Is it a known failure ? |
Yes - it happens occasionally. I'll merge and retest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @blegat - this looks pretty cool!
src/digraph/cycles/karp.jl
Outdated
# g::::IsDirected, | ||
# distmx::::AbstractMatrix = weights(g) | ||
# ) | ||
function karp_minimum_cycle_mean(g, distmx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure distmx
has a default:
distmx::AbstractMatrix = weights(g);
(also change the docstring:
"""
karp_minimum_cycle_mean(g[, distmx])
Return minimum cycle mean of the directed graph `g` with optional edge weights contained in `distmx`.
"""
src/digraph/cycles/karp.jl
Outdated
|
||
if iszero(jbest) | ||
return U[], Inf | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short-circuit here:
iszero(jbest) && return U[], Inf
src/digraph/cycles/karp.jl
Outdated
F[1, 1] = 0. | ||
for v in 2:length(component) | ||
F[1, v] = Inf | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use fill
here somehow?
src/digraph/cycles/karp.jl
Outdated
v2j[v] = j | ||
end | ||
n = length(component) | ||
F = Matrix{float(T)}(n+1, n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense just to make this Float64
?
src/digraph/cycles/karp.jl
Outdated
g::AbstractGraph, | ||
distmx::AbstractMatrix{T}, | ||
component::Vector{U} | ||
) where T where U<:Integer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where T <: Real
test/digraph/cycles/karp.jl
Outdated
add_edge!(g, 11, 7) | ||
add_edge!(g, 12, 9) | ||
|
||
c, λ = karp_minimum_cycle_mean(g, w) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure you cycle through all graph types: rename g
to g1
and do
for g in maketestgraphs(g1)
c, λ = @inferred(karp_minimum_cycle_mean(g, w))
@test c == [9, 11, 7]
@test λ == 0.9
end
(repeat for the other tests as well)
Codecov Report
@@ Coverage Diff @@
## master #739 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 63 64 +1
Lines 3185 3233 +48
=====================================
+ Hits 3185 3233 +48 |
Thanks for the comments ! I have improved the PR |
Great. I'll do another quick review and would like @jpfairbanks to check it for functionality and things I've missed. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
awesome. Thank you, @blegat and @jpfairbanks !! |
Fixes #512