@@ -7,8 +7,11 @@ using NOMAD, Optimization.SciMLBase
7
7
export NOMADOpt
8
8
struct NOMADOpt end
9
9
10
+ @enum ConstraintBarrierType ExtremeBarrierMethod ProgressiveBarrierMethod
11
+
10
12
SciMLBase. allowsbounds (:: NOMADOpt ) = true
11
13
SciMLBase. allowscallback (:: NOMADOpt ) = false
14
+ SciMLBase. allowsconstraints (:: NOMADOpt ) = true
12
15
13
16
function __map_optimizer_args! (prob:: OptimizationProblem , opt:: NOMAD.NomadProblem ;
14
17
callback = nothing ,
@@ -40,12 +43,14 @@ function __map_optimizer_args!(prob::OptimizationProblem, opt::NOMAD.NomadProble
40
43
return nothing
41
44
end
42
45
46
+ @inline strcnsmethod (m:: ConstraintBarrierType ) = m === ExtremeBarrierMethod ? " EB" : " PB"
47
+
43
48
function SciMLBase. __solve (prob:: OptimizationProblem , opt:: NOMADOpt ;
44
49
maxiters:: Union{Number, Nothing} = nothing ,
45
50
maxtime:: Union{Number, Nothing} = nothing ,
46
51
abstol:: Union{Number, Nothing} = nothing ,
47
52
reltol:: Union{Number, Nothing} = nothing ,
48
- progress = false ,
53
+ cons_method = ExtremeBarrierMethod ,
49
54
kwargs... )
50
55
local x
51
56
@@ -57,15 +62,27 @@ function SciMLBase.__solve(prob::OptimizationProblem, opt::NOMADOpt;
57
62
return first (x)
58
63
end
59
64
60
- function bb (x)
61
- l = _loss (x)
62
- success = ! isnan (l) && ! isinf (l)
63
- count_eval = true
64
- return (success, count_eval, [l])
65
- end
66
-
67
- if ! isnothing (prob. lcons) | ! isnothing (prob. ucons)
68
- @warn " Linear and nonlinear constraints defined in OptimizationProblem are currently not used by $(opt) "
65
+ if prob. f. cons === nothing
66
+ function bb (x)
67
+ l = _loss (x)
68
+ success = ! isnan (l) && ! isinf (l)
69
+ count_eval = true
70
+ return (success, count_eval, [l])
71
+ end
72
+ else
73
+ eqinds = findall (i -> prob. lcons[i] == prob. ucons[i], 1 : length (prob. ucons))
74
+ function bbcons (x)
75
+ l = _loss (x)
76
+ c = zeros (eltype (x), length (prob. ucons))
77
+ prob. f. cons (c, x, prob. p)
78
+ c -= prob. ucons
79
+ if ! isempty (eqinds)
80
+ c[eqinds] = abs .(c[eqinds])
81
+ end
82
+ success = ! isnan (l) && ! isinf (l)
83
+ count_eval = true
84
+ return (success, count_eval, vcat (l, c))
85
+ end
69
86
end
70
87
71
88
bounds = (;)
@@ -77,7 +94,13 @@ function SciMLBase.__solve(prob::OptimizationProblem, opt::NOMADOpt;
77
94
bounds = (; bounds... , upper_bound = prob. ub)
78
95
end
79
96
80
- opt_setup = NOMAD. NomadProblem (length (prob. u0), 1 , [" OBJ" ], bb; bounds... )
97
+ if prob. f. cons === nothing
98
+ opt_setup = NOMAD. NomadProblem (length (prob. u0), 1 , [" OBJ" ], bb; bounds... )
99
+ else
100
+ opt_setup = NOMAD. NomadProblem (length (prob. u0), 1 + length (prob. ucons),
101
+ vcat (" OBJ" , fill (strcnsmethod (cons_method), length (prob. ucons))),
102
+ bbcons; bounds... )
103
+ end
81
104
82
105
__map_optimizer_args! (prob, opt_setup, maxiters = maxiters, maxtime = maxtime,
83
106
abstol = abstol, reltol = reltol; kwargs... )
0 commit comments