Skip to content

Commit

Permalink
Avoid emptying all the minimisers if hitting minimum at the begining (#…
Browse files Browse the repository at this point in the history
…63)

* Avoid emptying all the minimisers if hitting minimum at the begining

* Add tests to edge cases of minimise

* Modify test to avoid passing test if `global_min` is empty

* bump patch version to `0.4.6`

Co-authored-by: lucaferranti <[email protected]>
  • Loading branch information
Suavesito-Olimpiada and lucaferranti authored Jan 23, 2022
1 parent 9bddaed commit c7de3d4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "IntervalOptimisation"
uuid = "c7c68f13-a4a2-5b9a-b424-07d005f8d9d2"
version = "0.4.5"
version = "0.4.6"

[deps]
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
Expand Down
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

2 comments on commit c7de3d4

@lucaferranti
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/53023

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.6 -m "<description of version>" c7de3d4e7b243a064423d531ad2e55c584896845
git push origin v0.4.6

Please sign in to comment.