@@ -228,6 +228,10 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map,
228
228
else # use the user supplied variable bounds
229
229
xor (isnothing (lb), isnothing (ub)) &&
230
230
throw (ArgumentError (" Expected both `lb` and `ub` to be supplied" ))
231
+ ! isnothing (lb) && length (lb) != length (dvs) &&
232
+ throw (ArgumentError (" Expected both `lb` to be of the same length as the vector of optimization variables" ))
233
+ ! isnothing (ub) && length (ub) != length (dvs) &&
234
+ throw (ArgumentError (" Expected both `ub` to be of the same length as the vector of optimization variables" ))
231
235
end
232
236
233
237
int = isintegervar .(dvs) .| isbinaryvar .(dvs)
@@ -241,10 +245,10 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map,
241
245
lb = varmap_to_vars (dvs .=> lb, dvs; defaults = defs, tofloat = false , use_union)
242
246
ub = varmap_to_vars (dvs .=> ub, dvs; defaults = defs, tofloat = false , use_union)
243
247
244
- if ! isnothing (lb) && all (lb .== - Inf )
248
+ if ! isnothing (lb) && all (lb .== - Inf )
245
249
lb = nothing
246
250
end
247
- if ! isnothing (ub) && all (ub .== Inf )
251
+ if ! isnothing (ub) && all (ub .== Inf )
248
252
ub = nothing
249
253
end
250
254
@@ -288,15 +292,25 @@ function DiffEqBase.OptimizationProblem{iip}(sys::OptimizationSystem, u0map,
288
292
289
293
if length (cstr) > 0
290
294
@named cons_sys = ConstraintsSystem (cstr, dvs, ps)
291
- cons, lcons, ucons = generate_function (cons_sys, checkbounds = checkbounds,
292
- linenumbers = linenumbers,
293
- expression = Val{false })
295
+ cons, lcons_, ucons_ = generate_function (cons_sys, checkbounds = checkbounds,
296
+ linenumbers = linenumbers,
297
+ expression = Val{false })
294
298
cons_j = generate_jacobian (cons_sys; expression = Val{false }, sparse = sparse)[2 ]
295
299
cons_h = generate_hessian (cons_sys; expression = Val{false }, sparse = sparse)[2 ]
296
300
297
301
cons_expr = toexpr .(subs_constants (constraints (cons_sys)))
298
302
rep_pars_vals! .(cons_expr, Ref (pairs_arr))
299
303
304
+ if isnothing (lcons) && isnothing (ucons) # use the symbolically specified bounds
305
+ lcons = lcons_
306
+ ucons = ucons_
307
+ else # use the user supplied variable bounds
308
+ ! isnothing (lcons) && length (lcons) != length (cstr) &&
309
+ throw (ArgumentError (" Expected both `lcons` to be of the same length as the vector of constraints" ))
310
+ ! isnothing (ucons) && length (ucons) != length (cstr) &&
311
+ throw (ArgumentError (" Expected both `ucons` to be of the same length as the vector of constraints" ))
312
+ end
313
+
300
314
if sparse
301
315
cons_jac_prototype = jacobian_sparsity (cons_sys)
302
316
cons_hess_prototype = hessian_sparsity (cons_sys)
@@ -384,6 +398,10 @@ function OptimizationProblemExpr{iip}(sys::OptimizationSystem, u0,
384
398
else # use the user supplied variable bounds
385
399
xor (isnothing (lb), isnothing (ub)) &&
386
400
throw (ArgumentError (" Expected both `lb` and `ub` to be supplied" ))
401
+ ! isnothing (lb) && length (lb) != length (dvs) &&
402
+ throw (ArgumentError (" Expected both `lb` to be of the same length as the vector of optimization variables" ))
403
+ ! isnothing (ub) && length (ub) != length (dvs) &&
404
+ throw (ArgumentError (" Expected both `ub` to be of the same length as the vector of optimization variables" ))
387
405
end
388
406
389
407
int = isintegervar .(dvs) .| isbinaryvar .(dvs)
@@ -397,10 +415,10 @@ function OptimizationProblemExpr{iip}(sys::OptimizationSystem, u0,
397
415
lb = varmap_to_vars (dvs .=> lb, dvs; defaults = defs, tofloat = false , use_union)
398
416
ub = varmap_to_vars (dvs .=> ub, dvs; defaults = defs, tofloat = false , use_union)
399
417
400
- if ! isnothing (lb) && all (lb .== - Inf )
418
+ if ! isnothing (lb) && all (lb .== - Inf )
401
419
lb = nothing
402
420
end
403
- if ! isnothing (ub) && all (ub .== Inf )
421
+ if ! isnothing (ub) && all (ub .== Inf )
404
422
ub = nothing
405
423
end
406
424
@@ -439,15 +457,25 @@ function OptimizationProblemExpr{iip}(sys::OptimizationSystem, u0,
439
457
440
458
if length (cstr) > 0
441
459
@named cons_sys = ConstraintsSystem (cstr, dvs, ps)
442
- cons, lcons, ucons = generate_function (cons_sys, checkbounds = checkbounds,
443
- linenumbers = linenumbers,
444
- expression = Val{false })
460
+ cons, lcons_, ucons_ = generate_function (cons_sys, checkbounds = checkbounds,
461
+ linenumbers = linenumbers,
462
+ expression = Val{false })
445
463
cons_j = generate_jacobian (cons_sys; expression = Val{false }, sparse = sparse)[2 ]
446
464
cons_h = generate_hessian (cons_sys; expression = Val{false }, sparse = sparse)[2 ]
447
465
448
466
cons_expr = toexpr .(subs_constants (constraints (cons_sys)))
449
467
rep_pars_vals! .(cons_expr, Ref (pairs_arr))
450
468
469
+ if isnothing (lcons) && isnothing (ucons) # use the symbolically specified bounds
470
+ lcons = lcons_
471
+ ucons = ucons_
472
+ else # use the user supplied variable bounds
473
+ ! isnothing (lcons) && length (lcons) != length (cstr) &&
474
+ throw (ArgumentError (" Expected both `lcons` to be of the same length as the vector of constraints" ))
475
+ ! isnothing (ucons) && length (ucons) != length (cstr) &&
476
+ throw (ArgumentError (" Expected both `ucons` to be of the same length as the vector of constraints" ))
477
+ end
478
+
451
479
if sparse
452
480
cons_jac_prototype = jacobian_sparsity (cons_sys)
453
481
cons_hess_prototype = hessian_sparsity (cons_sys)
0 commit comments