@@ -114,6 +114,8 @@ struct ControllerConstraint{NT<:Real, GCfunc<:Union{Nothing, Function}}
114114 Aeq :: Matrix{NT}
115115 # b vector for the linear equality constraints:
116116 beq :: Vector{NT}
117+ # nonlinear equality constraints:
118+ neq :: Int
117119 # constraint softness parameter vectors for the nonlinear inequality constraints:
118120 C_ymin :: Vector{NT}
119121 C_ymax :: Vector{NT}
404406 model::LinModel, transcription::TranscriptionMethod, nc::Int,
405407 i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max,
406408 args...
407- ) -> i_b, i_g, A, Aeq
409+ ) -> i_b, i_g, A, Aeq, neq
408410
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.
410412
411413The linear and nonlinear constraints are respectively defined as:
412414```math
@@ -420,25 +422,27 @@ The linear and nonlinear constraints are respectively defined as:
420422The argument `nc` is the number of custom nonlinear inequality constraints in
421423``\m athbf{g_c}``. `i_b` is a `BitVector` including the indices of ``\m athbf{b}`` that are
422424finite 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}}``.
426429"""
427430function init_matconstraint_mpc (
428431 :: LinModel{NT} , :: TranscriptionMethod , nc:: Int ,
429432 i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max,
430433 args...
431434) where {NT<: Real }
432435 if isempty (args)
433- A, Aeq = nothing , nothing
436+ A, Aeq, neq = nothing , nothing , nothing
434437 else
435438 A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max, A_ŝ = args
436439 A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax; A_Ymin; A_Ymax; A_x̂min; A_x̂max]
437440 Aeq = A_ŝ
441+ neq = 0
438442 end
439443 i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax; i_Ymin; i_Ymax; i_x̂min; i_x̂max]
440444 i_g = trues (nc)
441- return i_b, i_g, A, Aeq
445+ return i_b, i_g, A, Aeq, neq
442446end
443447
444448" Init `i_b` without output constraints if [`NonLinModel`](@ref) & [`MultipleShooting`](@ref)."
@@ -448,15 +452,17 @@ function init_matconstraint_mpc(
448452 args...
449453) where {NT<: Real }
450454 if isempty (args)
451- A, Aeq = nothing , nothing
455+ A, Aeq, neq = nothing , nothing , nothing
452456 else
453457 A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max, A_ŝ = args
454458 A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax; A_Ymin; A_Ymax; A_x̂min; A_x̂max]
455459 Aeq = A_ŝ
460+ nΔŨ, nZ̃ = size (A_ΔŨmin)
461+ neq = nZ̃ - nΔŨ
456462 end
457463 i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax; i_x̂min; i_x̂max]
458464 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
460466end
461467
462468" Init `i_b` without output & terminal constraints if [`NonLinModel`](@ref) & [`SingleShooting`](@ref)."
@@ -466,15 +472,16 @@ function init_matconstraint_mpc(
466472 args...
467473) where {NT<: Real }
468474 if isempty (args)
469- A, Aeq = nothing , nothing
475+ A, Aeq, neq = nothing , nothing , nothing
470476 else
471477 A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂min, A_x̂max, A_ŝ = args
472478 A = [A_Umin; A_Umax; A_ΔŨmin; A_ΔŨmax; A_Ymin; A_Ymax; A_x̂min; A_x̂max]
473479 Aeq = A_ŝ
480+ neq = 0
474481 end
475482 i_b = [i_Umin; i_Umax; i_ΔŨmin; i_ΔŨmax]
476483 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
478485end
479486
480487
@@ -603,7 +610,7 @@ function init_defaultcon_mpc(
603610 i_ΔŨmin, i_ΔŨmax = .! isinf .(ΔŨmin), .! isinf .(ΔŨmax)
604611 i_Ymin, i_Ymax = .! isinf .(Y0min), .! isinf .(Y0max)
605612 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 (
607614 model, transcription, nc,
608615 i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max,
609616 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(
619626 A , b , i_b ,
620627 A_ŝ ,
621628 Aeq , beq ,
629+ neq ,
622630 C_ymin , C_ymax , c_x̂min , c_x̂max , i_g,
623631 gc! , nc
624632 )
0 commit comments