@@ -156,6 +156,64 @@ function test_list_of_constraint_attributes_set()
156
156
return
157
157
end
158
158
159
+ function test_raw_optimizer_attribute_in_optimize ()
160
+ model = NLopt. Optimizer ()
161
+ x = MOI. add_variables (model, 2 )
162
+ f = (x[1 ] - 2.0 ) * (x[1 ] - 2.0 ) + (x[2 ] + 1.0 )^ 2 # * (x[2] + 1)
163
+ MOI. set (model, MOI. ObjectiveSense (), MOI. MIN_SENSE)
164
+ MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
165
+ for (k, v) in (
166
+ " algorithm" => :LD_SLSQP ,
167
+ " stopval" => 1.0 ,
168
+ " ftol_rel" => 1e-6 ,
169
+ " ftol_abs" => 1e-6 ,
170
+ " xtol_rel" => 1e-6 ,
171
+ " xtol_abs" => 1e-6 ,
172
+ " maxeval" => 100 ,
173
+ " maxtime" => 60.0 ,
174
+ " initial_step" => [0.1 , 0.1 ],
175
+ " population" => 10 ,
176
+ " seed" => 1234 ,
177
+ " vector_storage" => 3 ,
178
+ )
179
+ attr = MOI. RawOptimizerAttribute (k)
180
+ MOI. set (model, attr, v)
181
+ end
182
+ MOI. optimize! (model)
183
+ @test ≈ (MOI. get .(model, MOI. VariablePrimal (), x), [2.0 , - 1.0 ]; atol = 1e-4 )
184
+ return
185
+ end
186
+
187
+ function test_local_optimizer_Symbol ()
188
+ model = NLopt. Optimizer ()
189
+ x = MOI. add_variables (model, 2 )
190
+ f = (x[1 ] - 2.0 ) * (x[1 ] - 2.0 ) + (x[2 ] + 1.0 ) * (x[2 ] + 1.0 )
191
+ MOI. set (model, MOI. ObjectiveSense (), MOI. MIN_SENSE)
192
+ MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
193
+ MOI. set (model, MOI. RawOptimizerAttribute (" algorithm" ), :AUGLAG )
194
+ attr = MOI. RawOptimizerAttribute (" local_optimizer" )
195
+ @test MOI. get (model, attr) === nothing
196
+ MOI. set (model, attr, :LD_SLSQP )
197
+ MOI. optimize! (model)
198
+ @test MOI. get (model, MOI. TerminationStatus ()) isa MOI. TerminationStatusCode
199
+ return
200
+ end
201
+
202
+ function test_local_optimizer_Opt ()
203
+ model = NLopt. Optimizer ()
204
+ x = MOI. add_variables (model, 2 )
205
+ f = (x[1 ] - 2.0 ) * (x[1 ] - 2.0 ) + (x[2 ] + 1.0 ) * (x[2 ] + 1.0 )
206
+ MOI. set (model, MOI. ObjectiveSense (), MOI. MIN_SENSE)
207
+ MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
208
+ MOI. set (model, MOI. RawOptimizerAttribute (" algorithm" ), :GD_MLSL )
209
+ attr = MOI. RawOptimizerAttribute (" local_optimizer" )
210
+ @test MOI. get (model, attr) === nothing
211
+ MOI. set (model, attr, NLopt. Opt (:LD_MMA , 2 ))
212
+ MOI. optimize! (model)
213
+ @test MOI. get (model, MOI. TerminationStatus ()) isa MOI. TerminationStatusCode
214
+ return
215
+ end
216
+
159
217
function test_get_objective_function ()
160
218
model = NLopt. Optimizer ()
161
219
x = MOI. add_variable (model)
0 commit comments