@@ -40,6 +40,14 @@ using Test, Random
4040 @test sol. retcode == ReturnCode. Success
4141 @test 10 * sol. objective < l1
4242
43+ # XTOL_REACHED
44+ sol = solve (prob, NLopt. LD_LBFGS (), xtol_abs = 1e10 )
45+ @test sol. retcode == ReturnCode. Success
46+
47+ # STOPVAL_REACHED
48+ sol = solve (prob, NLopt. LD_LBFGS (), stopval = 1e10 )
49+ @test sol. retcode == ReturnCode. Success
50+
4351 prob = OptimizationProblem (optprob, x0, _p, lb = [- 1.0 , - 1.0 ], ub = [0.8 , 0.8 ])
4452 sol = solve (prob, NLopt. LD_LBFGS ())
4553 @test sol. retcode == ReturnCode. Success
@@ -79,7 +87,21 @@ using Test, Random
7987 @test sol. objective < 0.8
8088 end
8189
90+ @testset " MAXTIME_REACHED" begin
91+ # without maxtime=... this will take time
92+ n = 2000
93+ A, b = rand (n, n), rand (n)
94+ system (x, p) = sum ((A * x - b) .^ 2 )
95+ x0 = zeros (n)
96+ __p = Float64[]
97+ optprob = OptimizationFunction ((x, p) -> - system (x, p), Optimization. AutoZygote ())
98+ prob = OptimizationProblem (optprob, x0, __p; sense = Optimization. MaxSense)
99+ sol = solve (prob, NLopt. Opt (:LD_LBFGS , n), maxtime = 1e-6 )
100+ @test sol. retcode == ReturnCode. MaxTime
101+ end
102+
82103 @testset " constrained" begin
104+ Random. seed! (1 )
83105 cons = (res, x, p) -> res .= [x[1 ]^ 2 + x[2 ]^ 2 - 1.0 ]
84106 x0 = zeros (2 )
85107 optprob = OptimizationFunction (rosenbrock, Optimization. AutoZygote ();
@@ -108,13 +130,14 @@ using Test, Random
108130 res .= [x[1 ]^ 2 + x[2 ]^ 2 - 1.0 , x[2 ] * sin (x[1 ]) - x[1 ] - 2.0 ]
109131 end
110132
133+ # FTOL_REACHED
111134 optprob = OptimizationFunction (
112135 rosenbrock, Optimization. AutoForwardDiff (); cons = con2_c)
113136 Random. seed! (1 )
114137 prob = OptimizationProblem (
115138 optprob, rand (2 ), _p, lcons = [0.0 , - Inf ], ucons = [0.0 , 0.0 ])
116139 sol = solve (prob, NLopt. LD_AUGLAG (), local_method = NLopt. LD_LBFGS ())
117- # @test sol.retcode == ReturnCode.Success
140+ @test sol. retcode == ReturnCode. Success
118141 @test 10 * sol. objective < l1
119142
120143 Random. seed! (1 )
0 commit comments