@@ -40,6 +40,14 @@ using Test, Random
40
40
@test sol. retcode == ReturnCode. Success
41
41
@test 10 * sol. objective < l1
42
42
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
+
43
51
prob = OptimizationProblem (optprob, x0, _p, lb = [- 1.0 , - 1.0 ], ub = [0.8 , 0.8 ])
44
52
sol = solve (prob, NLopt. LD_LBFGS ())
45
53
@test sol. retcode == ReturnCode. Success
@@ -79,7 +87,21 @@ using Test, Random
79
87
@test sol. objective < 0.8
80
88
end
81
89
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
+
82
103
@testset " constrained" begin
104
+ Random. seed! (1 )
83
105
cons = (res, x, p) -> res .= [x[1 ]^ 2 + x[2 ]^ 2 - 1.0 ]
84
106
x0 = zeros (2 )
85
107
optprob = OptimizationFunction (rosenbrock, Optimization. AutoZygote ();
@@ -108,20 +130,21 @@ using Test, Random
108
130
res .= [x[1 ]^ 2 + x[2 ]^ 2 - 1.0 , x[2 ] * sin (x[1 ]) - x[1 ] - 2.0 ]
109
131
end
110
132
133
+ # FTOL_REACHED
111
134
optprob = OptimizationFunction (
112
135
rosenbrock, Optimization. AutoForwardDiff (); cons = con2_c)
113
136
Random. seed! (1 )
114
137
prob = OptimizationProblem (
115
138
optprob, rand (2 ), _p, lcons = [0.0 , - Inf ], ucons = [0.0 , 0.0 ])
116
139
sol = solve (prob, NLopt. LD_AUGLAG (), local_method = NLopt. LD_LBFGS ())
117
- # @test sol.retcode == ReturnCode.Success
140
+ @test sol. retcode == ReturnCode. Success
118
141
@test 10 * sol. objective < l1
119
142
120
143
Random. seed! (1 )
121
144
prob = OptimizationProblem (optprob, [0.5 , 0.5 ], _p, lcons = [- Inf , - Inf ],
122
145
ucons = [0.0 , 0.0 ], lb = [- 1.0 , - 1.0 ], ub = [1.0 , 1.0 ])
123
146
sol = solve (prob, NLopt. GN_ISRES (), maxiters = 1000 )
124
147
@test sol. retcode == ReturnCode. MaxIters
125
- @test 10 * sol. objective < l1
148
+ @test sol. objective < l1
126
149
end
127
150
end
0 commit comments