Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid emptying all the minimisers if hitting minimum at the begining #63

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/HeapedVectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function bubbledown!(v::HeapedVector{T}, index) where{T}
end

function filter_elements!(A::HeapedVector{T}, x::T) where{T}
func(y) = A.by(y) < A.by(x)
func(y) = A.by(y) <= A.by(x)
filter!(func, A.data)

if length(A.data) == 0
Expand Down
5 changes: 4 additions & 1 deletion src/SortedVectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ popfirst!(v::SortedVector) = popfirst!(v.data)

function filter_elements!(v::SortedVector{T}, x::T) where {T}
cutoff = searchsortedfirst(v.data, x, by=v.by)
resize!(v.data, cutoff-1)
if cutoff >= length(v.data)
return v
end
resize!(v.data, cutoff)
return v
end

Expand Down
6 changes: 6 additions & 0 deletions test/optimise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ using IntervalOptimisation: numeric_type

end

@testset "Non smooth function in 2D" begin
global_min, minimisers = minimise( X -> ( (x,y) = X; abs(x-y) + abs(x) ), (-1..1) × (-1..1), structure = Structure )
@test global_min == 0..0 # it must return the exact minimum (if mid is used to find the first global_min)
@test all(X ⊆ (-2e-3.. 2e-3) × (-2e-3..2e-3) for X in minimisers)
end

end

end