66
66
67
67
function SciMLBase. allowsconstraints (opt:: NLopt.Algorithm )
68
68
str_opt = string (opt)
69
- if occursin (" AUGLAG" , str_opt) || occursin (" CCSA" , str_opt) || occursin (" MMA" , str_opt) || occursin (" COBYLA" , str_opt) || occursin (" ISRES" , str_opt) || occursin (" AGS" , str_opt) || occursin (" ORIG_DIRECT" , str_opt) || occursin (" SLSQP" , str_opt)
69
+ if occursin (" AUGLAG" , str_opt) || occursin (" CCSA" , str_opt) ||
70
+ occursin (" MMA" , str_opt) || occursin (" COBYLA" , str_opt) ||
71
+ occursin (" ISRES" , str_opt) || occursin (" AGS" , str_opt) ||
72
+ occursin (" ORIG_DIRECT" , str_opt) || occursin (" SLSQP" , str_opt)
70
73
return true
71
74
else
72
75
return false
75
78
76
79
function SciMLBase. requiresconsjac (opt:: NLopt.Algorithm )
77
80
str_opt = string (opt)
78
- if occursin (" AUGLAG" , str_opt) || occursin (" CCSA" , str_opt) || occursin (" MMA" , str_opt) || occursin (" COBYLA" , str_opt) || occursin (" ISRES" , str_opt) || occursin (" AGS" , str_opt) || occursin (" ORIG_DIRECT" , str_opt) || occursin (" SLSQP" , str_opt)
81
+ if occursin (" AUGLAG" , str_opt) || occursin (" CCSA" , str_opt) ||
82
+ occursin (" MMA" , str_opt) || occursin (" COBYLA" , str_opt) ||
83
+ occursin (" ISRES" , str_opt) || occursin (" AGS" , str_opt) ||
84
+ occursin (" ORIG_DIRECT" , str_opt) || occursin (" SLSQP" , str_opt)
79
85
return true
80
86
else
81
87
return false
82
88
end
83
89
end
84
90
85
91
function SciMLBase. __init (prob:: SciMLBase.OptimizationProblem , opt:: NLopt.Algorithm ,
86
- ; cons_tol = 1e-6 ,
92
+ ; cons_tol = 1e-6 ,
87
93
callback = (args... ) -> (false ),
88
94
progress = false , kwargs... )
89
95
return OptimizationCache (prob, opt; cons_tol, callback, progress,
90
96
kwargs... )
91
97
end
92
98
93
-
94
99
function __map_optimizer_args! (cache:: OptimizationCache , opt:: NLopt.Opt ;
95
100
callback = nothing ,
96
101
maxiters:: Union{Number, Nothing} = nothing ,
@@ -209,8 +214,6 @@ function SciMLBase.__solve(cache::OptimizationCache{
209
214
return _loss (θ)
210
215
end
211
216
212
-
213
-
214
217
opt_setup = if isa (cache. opt, NLopt. Opt)
215
218
if ndims (cache. opt) != length (cache. u0)
216
219
error (" Passed NLopt.Opt optimization dimension does not match OptimizationProblem dimension." )
@@ -227,33 +230,35 @@ function SciMLBase.__solve(cache::OptimizationCache{
227
230
end
228
231
229
232
if cache. f. cons != = nothing
230
- eqinds = map ((y) -> y[1 ]== y[2 ], zip (cache. lcons, cache. ucons))
231
- ineqinds = map ((y) -> y[1 ]!= y[2 ], zip (cache. lcons, cache. ucons))
233
+ eqinds = map ((y) -> y[1 ] == y[2 ], zip (cache. lcons, cache. ucons))
234
+ ineqinds = map ((y) -> y[1 ] != y[2 ], zip (cache. lcons, cache. ucons))
232
235
if sum (ineqinds) > 0
233
236
ineqcons = function (res, θ, J)
234
- cons_cache = zeros (eltype (res), sum (eqinds)+ sum (ineqinds))
237
+ cons_cache = zeros (eltype (res), sum (eqinds) + sum (ineqinds))
235
238
cache. f. cons (cons_cache, θ)
236
239
res .= @view (cons_cache[ineqinds])
237
240
if length (J) > 0
238
- Jcache = zeros (eltype (J), sum (ineqinds)+ sum (eqinds), length (θ))
241
+ Jcache = zeros (eltype (J), sum (ineqinds) + sum (eqinds), length (θ))
239
242
cache. f. cons_j (Jcache, θ)
240
243
J .= @view (Jcache[ineqinds, :])'
241
244
end
242
245
end
243
- NLopt. inequality_constraint! (opt_setup, ineqcons, [cache. solver_args. cons_tol for i in 1 : sum (ineqinds)])
246
+ NLopt. inequality_constraint! (
247
+ opt_setup, ineqcons, [cache. solver_args. cons_tol for i in 1 : sum (ineqinds)])
244
248
end
245
249
if sum (eqinds) > 0
246
250
eqcons = function (res, θ, J)
247
- cons_cache = zeros (eltype (res), sum (eqinds)+ sum (ineqinds))
251
+ cons_cache = zeros (eltype (res), sum (eqinds) + sum (ineqinds))
248
252
cache. f. cons (cons_cache, θ)
249
253
res .= @view (cons_cache[eqinds])
250
254
if length (J) > 0
251
- Jcache = zeros (eltype (res), sum (eqinds)+ sum (ineqinds), length (θ))
255
+ Jcache = zeros (eltype (res), sum (eqinds) + sum (ineqinds), length (θ))
252
256
cache. f. cons_j (Jcache, θ)
253
257
J .= @view (Jcache[eqinds, :])'
254
258
end
255
259
end
256
- NLopt. equality_constraint! (opt_setup, eqcons, [cache. solver_args. cons_tol for i in 1 : sum (eqinds)])
260
+ NLopt. equality_constraint! (
261
+ opt_setup, eqcons, [cache. solver_args. cons_tol for i in 1 : sum (eqinds)])
257
262
end
258
263
end
259
264
0 commit comments