@@ -114,6 +114,8 @@ struct ControllerConstraint{NT<:Real, GCfunc<:Union{Nothing, Function}}
114
114
Aeq :: Matrix{NT}
115
115
# b vector for the linear equality constraints:
116
116
beq :: Vector{NT}
117
+ # nonlinear equality constraints:
118
+ neq :: Int
117
119
# constraint softness parameter vectors for the nonlinear inequality constraints:
118
120
C_ymin :: Vector{NT}
119
121
C_ymax :: Vector{NT}
404
406
model::LinModel, transcription::TranscriptionMethod, nc::Int,
405
407
i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max,
406
408
args...
407
- ) -> i_b, i_g, A, Aeq
409
+ ) -> i_b, i_g, A, Aeq, neq
408
410
409
- Init `i_b`, `i_g`, `A` and `Aeq` matrices for the linear and nonlinear constraints.
411
+ Init `i_b`, `i_g`, `neq`, and ` A` and `Aeq` matrices for the all the MPC constraints.
410
412
411
413
The linear and nonlinear constraints are respectively defined as:
412
414
```math
@@ -420,25 +422,27 @@ The linear and nonlinear constraints are respectively defined as:
420
422
The argument `nc` is the number of custom nonlinear inequality constraints in
421
423
``\m athbf{g_c}``. `i_b` is a `BitVector` including the indices of ``\m athbf{b}`` that are
422
424
finite numbers. `i_g` is a similar vector but for the indices of ``\m athbf{g}``. The method
423
- also returns the ``\m athbf{A, A_{eq}}`` matrices if `args` is provided. In such a case,
424
- `args` needs to contain all the inequality and equality constraint matrices:
425
- `A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max, A_ŝ`.
425
+ also returns the ``\m athbf{A, A_{eq}}`` matrices and `neq` if `args` is provided. In such a
426
+ case, `args` needs to contain all the inequality and equality constraint matrices:
427
+ `A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max, A_ŝ`. The integer `neq`
428
+ is the number of nonlinear equality constraints in ``\m athbf{g_{eq}}``.
426
429
"""
427
430
function init_matconstraint_mpc (
428
431
:: LinModel{NT} , :: TranscriptionMethod , nc:: Int ,
429
432
i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max,
430
433
args...
431
434
) where {NT<: Real }
432
435
if isempty (args)
433
- A, Aeq = nothing , nothing
436
+ A, Aeq, neq = nothing , nothing , nothing
434
437
else
435
438
A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max, A_ŝ = args
436
439
A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax; A_Ymin; A_Ymax; A_x̂min; A_x̂max]
437
440
Aeq = A_ŝ
441
+ neq = 0
438
442
end
439
443
i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax; i_Ymin; i_Ymax; i_x̂min; i_x̂max]
440
444
i_g = trues (nc)
441
- return i_b, i_g, A, Aeq
445
+ return i_b, i_g, A, Aeq, neq
442
446
end
443
447
444
448
" Init `i_b` without output constraints if [`NonLinModel`](@ref) & [`MultipleShooting`](@ref)."
@@ -448,15 +452,17 @@ function init_matconstraint_mpc(
448
452
args...
449
453
) where {NT<: Real }
450
454
if isempty (args)
451
- A, Aeq = nothing , nothing
455
+ A, Aeq, neq = nothing , nothing , nothing
452
456
else
453
457
A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max, A_ŝ = args
454
458
A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax; A_Ymin; A_Ymax; A_x̂min; A_x̂max]
455
459
Aeq = A_ŝ
460
+ nΔŨ, nZ̃ = size (A_ΔŨmin)
461
+ neq = nZ̃ - nΔŨ
456
462
end
457
463
i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax; i_x̂min; i_x̂max]
458
464
i_g = [i_Ymin; i_Ymax; trues (nc)]
459
- return i_b, i_g, A, Aeq
465
+ return i_b, i_g, A, Aeq, neq
460
466
end
461
467
462
468
" Init `i_b` without output & terminal constraints if [`NonLinModel`](@ref) & [`SingleShooting`](@ref)."
@@ -466,15 +472,16 @@ function init_matconstraint_mpc(
466
472
args...
467
473
) where {NT<: Real }
468
474
if isempty (args)
469
- A, Aeq = nothing , nothing
475
+ A, Aeq, neq = nothing , nothing , nothing
470
476
else
471
477
A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max, A_ŝ = args
472
478
A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax; A_Ymin; A_Ymax; A_x̂min; A_x̂max]
473
479
Aeq = A_ŝ
480
+ neq = 0
474
481
end
475
482
i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax]
476
483
i_g = [i_Ymin; i_Ymax; i_x̂min; i_x̂max; trues (nc)]
477
- return i_b, i_g, A, Aeq
484
+ return i_b, i_g, A, Aeq, neq
478
485
end
479
486
480
487
@@ -603,7 +610,7 @@ function init_defaultcon_mpc(
603
610
i_ΔŨmin, i_ΔŨmax = .! isinf .(ΔŨmin), .! isinf .(ΔŨmax)
604
611
i_Ymin, i_Ymax = .! isinf .(Y0min), .! isinf .(Y0max)
605
612
i_x̂min, i_x̂max = .! isinf .(x̂0min), .! isinf .(x̂0max)
606
- i_b, i_g, A, Aeq = init_matconstraint_mpc (
613
+ i_b, i_g, A, Aeq, neq = init_matconstraint_mpc (
607
614
model, transcription, nc,
608
615
i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max,
609
616
A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂max, A_x̂min,
@@ -619,6 +626,7 @@ function init_defaultcon_mpc(
619
626
A , b , i_b ,
620
627
A_ŝ ,
621
628
Aeq , beq ,
629
+ neq ,
622
630
C_ymin , C_ymax , c_x̂min , c_x̂max , i_g,
623
631
gc! , nc
624
632
)
0 commit comments