@@ -188,7 +188,6 @@ function rep_pars_vals!(e, p) end
188
188
```julia
189
189
function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem,u0map,
190
190
parammap=DiffEqBase.NullParameters();
191
- lb=nothing, ub=nothing,
192
191
grad = false,
193
192
hess = false, sparse = false,
194
193
checkbounds = false,
@@ -211,11 +210,6 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map,
211
210
linenumbers = true , parallel = SerialForm (),
212
211
use_union = false ,
213
212
kwargs... ) where {iip}
214
- if ! (isnothing (lb) && isnothing (ub))
215
- Base. depwarn (" `lb` and `ub` are deprecated. Use the `bounds` metadata for the variables instead." ,
216
- :OptimizationProblem , force = true )
217
- end
218
-
219
213
if haskey (kwargs, :lcons ) || haskey (kwargs, :ucons )
220
214
Base. depwarn (" `lcons` and `ucons` are deprecated. Specify constraints directly instead." ,
221
215
:OptimizationProblem , force = true )
@@ -225,11 +219,16 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map,
225
219
ps = parameters (sys)
226
220
cstr = constraints (sys)
227
221
228
- lb = first .(getbounds .(dvs))
229
- ub = last .(getbounds .(dvs))
222
+ if isnothing (lb) && isnothing (ub) # use the symbolically specified bounds
223
+ lb = first .(getbounds .(dvs))
224
+ ub = last .(getbounds .(dvs))
225
+ lb[isbinaryvar .(dvs)] .= 0
226
+ ub[isbinaryvar .(dvs)] .= 1
227
+ else # use the user supplied variable bounds
228
+ xor (isnothing (lb), isnothing (ub)) && throw (ArgumentError (" Expected both `lb` and `ub` to be supplied" ))
229
+ end
230
+
230
231
int = isintegervar .(dvs) .| isbinaryvar .(dvs)
231
- lb[isbinaryvar .(dvs)] .= 0
232
- ub[isbinaryvar .(dvs)] .= 1
233
232
234
233
defs = defaults (sys)
235
234
defs = mergedefaults (defs, parammap, ps)
@@ -240,7 +239,7 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map,
240
239
lb = varmap_to_vars (dvs .=> lb, dvs; defaults = defs, tofloat = false , use_union)
241
240
ub = varmap_to_vars (dvs .=> ub, dvs; defaults = defs, tofloat = false , use_union)
242
241
243
- if all (lb .== - Inf ) && all (ub .== Inf )
242
+ if ! isnothing (lb) && all (lb .== - Inf ) && ! isnothing (ub ) && all (ub .== Inf )
244
243
lb = nothing
245
244
ub = nothing
246
245
end
337
336
```julia
338
337
function DiffEqBase.OptimizationProblemExpr{iip}(sys::OptimizationSystem,
339
338
parammap=DiffEqBase.NullParameters();
340
- u0=nothing, lb=nothing, ub=nothing,
339
+ u0=nothing,
341
340
grad = false,
342
341
hes = false, sparse = false,
343
342
checkbounds = false,
@@ -364,11 +363,6 @@ function OptimizationProblemExpr{iip}(sys::OptimizationSystem, u0,
364
363
linenumbers = false , parallel = SerialForm (),
365
364
use_union = false ,
366
365
kwargs... ) where {iip}
367
- if ! (isnothing (lb) && isnothing (ub))
368
- Base. depwarn (" `lb` and `ub` are deprecated. Use the `bounds` metadata for the variables instead." ,
369
- :OptimizationProblem , force = true )
370
- end
371
-
372
366
if haskey (kwargs, :lcons ) || haskey (kwargs, :ucons )
373
367
Base. depwarn (" `lcons` and `ucons` are deprecated. Specify constraints directly instead." ,
374
368
:OptimizationProblem , force = true )
@@ -378,6 +372,31 @@ function OptimizationProblemExpr{iip}(sys::OptimizationSystem, u0,
378
372
ps = parameters (sys)
379
373
cstr = constraints (sys)
380
374
375
+ if isnothing (lb) && isnothing (ub) # use the symbolically specified bounds
376
+ lb = first .(getbounds .(dvs))
377
+ ub = last .(getbounds .(dvs))
378
+ lb[isbinaryvar .(dvs)] .= 0
379
+ ub[isbinaryvar .(dvs)] .= 1
380
+ else # use the user supplied variable bounds
381
+ xor (isnothing (lb), isnothing (ub)) && throw (ArgumentError (" Expected both `lb` and `ub` to be supplied" ))
382
+ end
383
+
384
+ int = isintegervar .(dvs) .| isbinaryvar .(dvs)
385
+
386
+ defs = defaults (sys)
387
+ defs = mergedefaults (defs, parammap, ps)
388
+ defs = mergedefaults (defs, u0map, dvs)
389
+
390
+ u0 = varmap_to_vars (u0map, dvs; defaults = defs, tofloat = false )
391
+ p = varmap_to_vars (parammap, ps; defaults = defs, tofloat = false , use_union)
392
+ lb = varmap_to_vars (dvs .=> lb, dvs; defaults = defs, tofloat = false , use_union)
393
+ ub = varmap_to_vars (dvs .=> ub, dvs; defaults = defs, tofloat = false , use_union)
394
+
395
+ if ! isnothing (lb) && all (lb .== - Inf ) && ! isnothing (ub) && all (ub .== Inf )
396
+ lb = nothing
397
+ ub = nothing
398
+ end
399
+
381
400
idx = iip ? 2 : 1
382
401
f = generate_function (sys, checkbounds = checkbounds, linenumbers = linenumbers,
383
402
expression = Val{true })
@@ -402,26 +421,6 @@ function OptimizationProblemExpr{iip}(sys::OptimizationSystem, u0,
402
421
hess_prototype = nothing
403
422
end
404
423
405
- lb = first .(getbounds .(dvs))
406
- ub = last .(getbounds .(dvs))
407
- int = isintegervar .(dvs) .| isbinaryvar .(dvs)
408
- lb[isbinaryvar .(dvs)] .= 0
409
- ub[isbinaryvar .(dvs)] .= 1
410
-
411
- defs = defaults (sys)
412
- defs = mergedefaults (defs, parammap, ps)
413
- defs = mergedefaults (defs, u0map, dvs)
414
-
415
- u0 = varmap_to_vars (u0map, dvs; defaults = defs, tofloat = false )
416
- p = varmap_to_vars (parammap, ps; defaults = defs, tofloat = false , use_union)
417
- lb = varmap_to_vars (dvs .=> lb, dvs; defaults = defs, tofloat = false , use_union)
418
- ub = varmap_to_vars (dvs .=> ub, dvs; defaults = defs, tofloat = false , use_union)
419
-
420
- if all (lb .== - Inf ) && all (ub .== Inf )
421
- lb = nothing
422
- ub = nothing
423
- end
424
-
425
424
obj_expr = toexpr (subs_constants (objective (sys)))
426
425
pairs_arr = if p isa SciMLBase. NullParameters
427
426
[Symbol (_s) => Expr (:ref , :x , i) for (i, _s) in enumerate (dvs)]
0 commit comments