6666
6767function SciMLBase. allowsconstraints (opt:: NLopt.Algorithm )
6868 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)
7073 return true
7174 else
7275 return false
7578
7679function SciMLBase. requiresconsjac (opt:: NLopt.Algorithm )
7780 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)
7985 return true
8086 else
8187 return false
8288 end
8389end
8490
8591function SciMLBase. __init (prob:: SciMLBase.OptimizationProblem , opt:: NLopt.Algorithm ,
86- ; cons_tol = 1e-6 ,
92+ ; cons_tol = 1e-6 ,
8793 callback = (args... ) -> (false ),
8894 progress = false , kwargs... )
8995 return OptimizationCache (prob, opt; cons_tol, callback, progress,
9096 kwargs... )
9197end
9298
93-
9499function __map_optimizer_args! (cache:: OptimizationCache , opt:: NLopt.Opt ;
95100 callback = nothing ,
96101 maxiters:: Union{Number, Nothing} = nothing ,
@@ -209,8 +214,6 @@ function SciMLBase.__solve(cache::OptimizationCache{
209214 return _loss (θ)
210215 end
211216
212-
213-
214217 opt_setup = if isa (cache. opt, NLopt. Opt)
215218 if ndims (cache. opt) != length (cache. u0)
216219 error (" Passed NLopt.Opt optimization dimension does not match OptimizationProblem dimension." )
@@ -227,33 +230,35 @@ function SciMLBase.__solve(cache::OptimizationCache{
227230 end
228231
229232 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))
232235 if sum (ineqinds) > 0
233236 ineqcons = function (res, θ, J)
234- cons_cache = zeros (eltype (res), sum (eqinds)+ sum (ineqinds))
237+ cons_cache = zeros (eltype (res), sum (eqinds) + sum (ineqinds))
235238 cache. f. cons (cons_cache, θ)
236239 res .= @view (cons_cache[ineqinds])
237240 if length (J) > 0
238- Jcache = zeros (eltype (J), sum (ineqinds)+ sum (eqinds), length (θ))
241+ Jcache = zeros (eltype (J), sum (ineqinds) + sum (eqinds), length (θ))
239242 cache. f. cons_j (Jcache, θ)
240243 J .= @view (Jcache[ineqinds, :])'
241244 end
242245 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)])
244248 end
245249 if sum (eqinds) > 0
246250 eqcons = function (res, θ, J)
247- cons_cache = zeros (eltype (res), sum (eqinds)+ sum (ineqinds))
251+ cons_cache = zeros (eltype (res), sum (eqinds) + sum (ineqinds))
248252 cache. f. cons (cons_cache, θ)
249253 res .= @view (cons_cache[eqinds])
250254 if length (J) > 0
251- Jcache = zeros (eltype (res), sum (eqinds)+ sum (ineqinds), length (θ))
255+ Jcache = zeros (eltype (res), sum (eqinds) + sum (ineqinds), length (θ))
252256 cache. f. cons_j (Jcache, θ)
253257 J .= @view (Jcache[eqinds, :])'
254258 end
255259 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)])
257262 end
258263 end
259264
0 commit comments