89
89
function __map_optimizer_args (prob:: OptimizationProblem , opt:: Union{MOI.AbstractOptimizer, MOI.OptimizerWithAttributes} ;
90
90
maxiters:: Union{Number, Nothing} = nothing ,
91
91
maxtime:: Union{Number, Nothing} = nothing ,
92
- abstol:: Union{Number, Nothing} = nothing ,
92
+ abstol:: Union{Number, Nothing} = nothing ,
93
93
reltol:: Union{Number, Nothing} = nothing ,
94
94
kwargs... )
95
-
96
- mapped_args = Vector{Pair{String, Any}}[]
97
- mapped_args = [mapped_args... , [Pair (string (j. first),j. second) for j = kwargs]. .. ]
98
-
99
- if isa (opt, MOI. AbstractOptimizer)
100
- if length (mapped_args) > 0
101
- opt = MOI. OptimizerWithAttributes (typeof (opt), mapped_args... )
102
- else
103
- opt = typeof (opt)
104
- end
105
- end
106
-
107
95
optimizer = MOI. instantiate (opt)
108
-
96
+ for (key, value) in kwargs
97
+ MOI. set (optimizer, MOI. RawOptimizerattribute (" $(key) " ), value)
98
+ end
109
99
if ! isnothing (maxtime)
110
100
MOI. set (optimizer, MOI. TimeLimitSec (), maxtime)
111
101
end
@@ -121,40 +111,42 @@ function __map_optimizer_args(prob::OptimizationProblem, opt::Union{MOI.Abstract
121
111
if ! isnothing (maxiters)
122
112
@warn " common maxiters argument is currently not used by $(optimizer) . Set number of interations via optimizer specific keyword aguments."
123
113
end
124
-
114
+
125
115
return optimizer
126
116
end
127
117
128
118
function __solve (prob:: OptimizationProblem , opt:: Union{MOI.AbstractOptimizer, MOI.OptimizerWithAttributes} ;
129
119
maxiters:: Union{Number, Nothing} = nothing ,
130
120
maxtime:: Union{Number, Nothing} = nothing ,
131
- abstol:: Union{Number, Nothing} = nothing ,
121
+ abstol:: Union{Number, Nothing} = nothing ,
132
122
reltol:: Union{Number, Nothing} = nothing ,
133
123
kwargs... )
134
124
135
125
maxiters = _check_and_convert_maxiters (maxiters)
136
126
maxtime = _check_and_convert_maxtime (maxtime)
137
127
138
128
opt_setup = __map_optimizer_args (prob, opt; abstol= abstol, reltol= reltol, maxiters= maxiters, maxtime= maxtime, kwargs... )
139
-
129
+
140
130
num_variables = length (prob. u0)
141
131
θ = MOI. add_variables (opt_setup, num_variables)
142
132
if prob. lb != = nothing
143
133
@assert eachindex (prob. lb) == Base. OneTo (num_variables)
144
134
for i in 1 : num_variables
145
- MOI. add_constraint (opt_setup, MOI . SingleVariable ( θ[i]) , MOI. GreaterThan (prob. lb[i]))
135
+ MOI. add_constraint (opt_setup, θ[i], MOI. GreaterThan (prob. lb[i]))
146
136
end
147
137
end
148
138
if prob. ub != = nothing
149
139
@assert eachindex (prob. ub) == Base. OneTo (num_variables)
150
140
for i in 1 : num_variables
151
- MOI. add_constraint (opt_setup, MOI . SingleVariable ( θ[i]) , MOI. LessThan (prob. ub[i]))
141
+ MOI. add_constraint (opt_setup, θ[i], MOI. LessThan (prob. ub[i]))
152
142
end
153
143
end
154
144
@assert eachindex (prob. u0) == Base. OneTo (num_variables)
155
- for i in 1 : num_variables
156
- MOI. set (opt_setup, MOI. VariablePrimalStart (), θ[i], prob. u0[i])
157
- end
145
+ if MOI. supports (opt_setup, MOI. VariablePrimalStart (), MOI. VariableIndex)
146
+ for i in 1 : num_variables
147
+ MOI. set (opt_setup, MOI. VariablePrimalStart (), θ[i], prob. u0[i])
148
+ end
149
+ end
158
150
MOI. set (opt_setup, MOI. ObjectiveSense (), prob. sense === MaxSense ? MOI. MAX_SENSE : MOI. MIN_SENSE)
159
151
if prob. lcons === nothing
160
152
@assert prob. ucons === nothing
0 commit comments