Skip to content

Commit 32027e9

Browse files
mforetsdpsanders
authored andcommitted
add kwargs to maximise and tests (#40)
1 parent f28247f commit 32027e9

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/optimise.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Find the global maximum of the function `f` over the `Interval` or `IntervalBox`
6969
using the Moore-Skelboe algorithm. See [`minimise`](@ref) for a description
7070
of the available options.
7171
"""
72-
function maximise(f, X::T; structure = HeapedVector, tol=1e-3) where {T}
73-
bound, minimizers = minimise(x -> -f(x), X, structure, tol)
72+
function maximise(f, X::T; structure=HeapedVector, tol=1e-3) where {T}
73+
bound, minimizers = minimise(x -> -f(x), X, structure=structure, tol=tol)
7474
return -bound, minimizers
7575
end

test/optimise.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using IntervalArithmetic, IntervalOptimisation
1+
using IntervalArithmetic, IntervalOptimisation
22
using Test
33

44
@testset "IntervalOptimisation tests" begin
@@ -9,6 +9,12 @@ using Test
99
@test length(minimisers) == 1
1010
@test minimisers[1] -10 .. -9.999
1111

12+
# same but with maximise
13+
global_max, maximisers = maximise(x->x, -10..10)
14+
@test global_max 9.999 .. 10
15+
@test length(maximisers) == 1
16+
@test maximisers[1] 9.999 .. 10
17+
1218
global_min, minimisers = minimise(x->x^2, -10..11, tol = 1e-10)
1319
@test global_min 0..1e-20
1420
@test length(minimisers) == 1
@@ -28,6 +34,12 @@ using Test
2834
@test length(minimisers) == 1
2935
@test minimisers[1] -10 .. -9.999
3036

37+
# same but with maximise
38+
global_max, maximisers = maximise(x->x, -10..10, structure = Structure)
39+
@test global_max 9.999 .. 10
40+
@test length(maximisers) == 1
41+
@test maximisers[1] 9.999 .. 10
42+
3143
global_min, minimisers = minimise(x->x^2, -10..11, tol=1e-10, structure = Structure)
3244
@test global_min 0..1e-20
3345
@test length(minimisers) == 1
@@ -55,8 +67,14 @@ using Test
5567
global_min, minimisers = minimise( X -> ( (x,y) = X; x^2 + y^2 ), (-10..10) × (-10..10), structure = Structure )
5668
@test global_min 0..1e-7
5769
@test all(X (-1e-3..1e3) × (-1e-3..1e-3) for X in minimisers)
70+
71+
# same but with maximise
72+
global_max, maximisers = maximise( X -> ( (x,y) = X; x^2 + y^2 ), (-10..10) × (-10..10), structure = Structure )
73+
@test global_max 199.9..200
74+
m = (9.99..10)
75+
@test all(X m × m || X -m × m || X m × -m || X -m × -m for X in maximisers)
5876
end
5977

6078
end
6179

62-
end
80+
end

0 commit comments

Comments
 (0)