@@ -5,6 +5,7 @@ using Reexport
5
5
using Optimization. SciMLBase
6
6
7
7
SciMLBase. allowsbounds (opt:: Evolutionary.AbstractOptimizer ) = true
8
+ SciMLBase. allowsconstraints (opt:: Evolutionary.AbstractOptimizer ) = true
8
9
9
10
decompose_trace (trace:: Evolutionary.OptimizationTrace ) = last (trace)
10
11
decompose_trace (trace:: Evolutionary.OptimizationTraceRecord ) = trace
@@ -20,8 +21,9 @@ function __map_optimizer_args(prob::OptimizationProblem,
20
21
maxiters:: Union{Number, Nothing} = nothing ,
21
22
maxtime:: Union{Number, Nothing} = nothing ,
22
23
abstol:: Union{Number, Nothing} = nothing ,
23
- reltol:: Union{Number, Nothing} = nothing )
24
- mapped_args = (;)
24
+ reltol:: Union{Number, Nothing} = nothing ,
25
+ kwargs... )
26
+ mapped_args = (;kwargs... )
25
27
26
28
if ! isnothing (callback)
27
29
mapped_args = (; mapped_args... , callback = callback)
@@ -74,6 +76,8 @@ function SciMLBase.__solve(prob::OptimizationProblem, opt::Evolutionary.Abstract
74
76
maxiters = Optimization. _check_and_convert_maxiters (maxiters)
75
77
maxtime = Optimization. _check_and_convert_maxtime (maxtime)
76
78
79
+ f = Optimization. instantiate_function (prob. f, prob. u0, prob. f. adtype, prob. p,
80
+ prob. ucons === nothing ? 0 : length (prob. ucons))
77
81
_loss = function (θ)
78
82
x = prob. f (θ, prob. p, cur... )
79
83
return first (x)
@@ -84,10 +88,21 @@ function SciMLBase.__solve(prob::OptimizationProblem, opt::Evolutionary.Abstract
84
88
kwargs... )
85
89
86
90
t0 = time ()
87
- if isnothing (prob. ub) || isnothing (prob. ub)
88
- opt_res = Evolutionary. optimize (_loss, prob. u0, opt, opt_args)
91
+ if isnothing (prob. lb) || isnothing (prob. ub)
92
+ if ! isnothing (f. cons)
93
+ c = x -> (res = zeros (length (prob. lcons)); f. cons (res, x); res)
94
+ cons = WorstFitnessConstraints (Float64[], Float64[], prob. lcons, prob. ucons, c)
95
+ opt_res = Evolutionary. optimize (_loss, cons, prob. u0, opt, opt_args)
96
+ else
97
+ opt_res = Evolutionary. optimize (_loss, prob. u0, opt, opt_args)
98
+ end
89
99
else
90
- cons = Evolutionary. BoxConstraints (prob. lb, prob. ub)
100
+ if ! isnothing (f. cons)
101
+ c = x -> (res = zeros (length (prob. lcons)); f. cons (res, x); res)
102
+ cons = WorstFitnessConstraints (prob. lb, prob. ub, prob. lcons, prob. ucons, c)
103
+ else
104
+ cons = BoxConstraints (prob. lb, prob. ub)
105
+ end
91
106
opt_res = Evolutionary. optimize (_loss, cons, prob. u0, opt, opt_args)
92
107
end
93
108
t1 = time ()
0 commit comments