@@ -42,7 +42,8 @@ using ModelingToolkit: get_metadata
42
42
sys2. b => 9.0
43
43
β => 10.0 ]
44
44
45
- prob = OptimizationProblem (combinedsys, u0, p, grad = true , hess = true )
45
+ prob = OptimizationProblem (combinedsys, u0, p, grad = true , hess = true , cons_j = true ,
46
+ cons_h = true )
46
47
@test prob. f. sys === combinedsys
47
48
sol = solve (prob, Ipopt. Optimizer (); print_level = 0 )
48
49
@test sol. minimum < - 1e5
58
59
@named sys = OptimizationSystem (loss, [x, y], [a, b], constraints = cons)
59
60
60
61
prob = OptimizationProblem (sys, [x => 0.0 , y => 0.0 ], [a => 1.0 , b => 1.0 ],
61
- grad = true , hess = true )
62
+ grad = true , hess = true , cons_j = true , cons_h = true )
62
63
@test prob. f. sys === sys
63
64
sol = solve (prob, IPNewton ())
64
65
@test sol. minimum < 1.0
65
66
sol = solve (prob, Ipopt. Optimizer (); print_level = 0 )
66
67
@test sol. minimum < 1.0
68
+
69
+ prob = OptimizationProblem (sys, [x => 0.0 , y => 0.0 ], [a => 1.0 , b => 1.0 ],
70
+ grad = false , hess = false , cons_j = false , cons_h = false )
67
71
sol = solve (prob, AmplNLWriter. Optimizer (Ipopt_jll. amplexe))
68
72
@test sol. minimum < 1.0
69
73
end
77
81
@named sys = OptimizationSystem (loss, [x, y, z], [a, b], constraints = cons)
78
82
sys = structural_simplify (sys)
79
83
prob = OptimizationProblem (sys, [x => 0.0 , y => 0.0 , z => 0.0 ], [a => 1.0 , b => 1.0 ],
80
- grad = true , hess = true )
84
+ grad = true , hess = true , cons_j = true , cons_h = true )
81
85
sol = solve (prob, IPNewton ())
82
86
@test sol. minimum < 1.0
83
87
@test sol. u≈ [0.808 , - 0.064 ] atol= 1e-3
86
90
@test sol. minimum < 1.0
87
91
@test sol. u≈ [0.808 , - 0.064 ] atol= 1e-3
88
92
@test sol[x]^ 2 + sol[y]^ 2 ≈ 1.0
93
+
94
+ prob = OptimizationProblem (sys, [x => 0.0 , y => 0.0 , z => 0.0 ], [a => 1.0 , b => 1.0 ],
95
+ grad = false , hess = false , cons_j = false , cons_h = false )
89
96
sol = solve (prob, AmplNLWriter. Optimizer (Ipopt_jll. amplexe))
90
97
@test sol. minimum < 1.0
91
98
@test sol. u≈ [0.808 , - 0.064 ] atol= 1e-3
@@ -178,13 +185,14 @@ end
178
185
sys2. b => 9.0
179
186
β => 10.0 ]
180
187
181
- prob = OptimizationProblem (combinedsys, u0, p, grad = true , hess = true )
188
+ prob = OptimizationProblem (combinedsys, u0, p, grad = true , hess = true , cons_j = true ,
189
+ cons_h = true )
182
190
@test prob. f. sys === combinedsys
183
191
sol = solve (prob, Ipopt. Optimizer (); print_level = 0 )
184
192
@test sol. minimum < - 1e5
185
193
186
194
prob = OptimizationProblem (sys2, [x => 0.0 , y => 0.0 ], [a => 1.0 , b => 100.0 ],
187
- grad = true , hess = true )
195
+ grad = true , hess = true , cons_j = true , cons_h = true )
188
196
@test prob. f. sys === sys2
189
197
sol = solve (prob, IPNewton ())
190
198
@test sol. minimum < 1.0
213
221
])
214
222
215
223
prob = OptimizationProblem (sys, [x[1 ] => 2.0 , x[2 ] => 0.0 ], [], grad = true ,
216
- hess = true )
224
+ hess = true , cons_j = true , cons_h = true )
217
225
sol = Optimization. solve (prob, Ipopt. Optimizer (); print_level = 0 )
218
226
@test sol. u ≈ [1 , 0 ]
219
227
@test prob. lb == [0.0 , 0.0 ]
226
234
@parameters a b
227
235
loss = (a - x)^ 2 + b * (y - x^ 2 )^ 2
228
236
@named sys = OptimizationSystem (loss, [x, y], [a, b, c])
229
- prob = OptimizationProblem (sys, [x => 0.0 , y => 0.0 ], [a => 1.0 , b => 100.0 ],
230
- grad = true , hess = true )
237
+ prob = OptimizationProblem (sys, [x => 0.0 , y => 0.0 ], [a => 1.0 , b => 100.0 ])
231
238
@test prob. lb == [- Inf , 0.0 ]
232
239
@test prob. ub == [Inf , Inf ]
233
240
end
0 commit comments