@@ -75,6 +75,11 @@ struct ControllerConstraint{NT<:Real, GCfunc<:Union{Nothing, Function}}
7575 b :: Vector{NT}
7676 # indices of finite numbers in the b vector (linear inequality constraints):
7777 i_b :: BitVector
78+ # A matrices for the linear equality constraints:
79+ A_ŝ :: Matrix{NT}
80+ Aeq :: Matrix{NT}
81+ # b vector for the linear equality constraints:
82+ beq :: Vector{NT}
7883 # constraint softness parameter vectors for the nonlinear inequality constraints:
7984 C_ymin :: Vector{NT}
8085 C_ymax :: Vector{NT}
@@ -492,17 +497,25 @@ end
492497
493498"""
494499 init_defaultcon_mpc(
495- estim, C, S, E, ex̂, fx̂, gx̂, jx̂, kx̂, vx̂,
500+ estim::StateEstimator,
501+ Hp, Hc, C,
502+ S, E,
503+ ex̂, fx̂, gx̂, jx̂, kx̂, vx̂, bx̂,
504+ Eŝ, Fŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ,
496505 gc!=nothing, nc=0
497- ) -> con, S̃, Ẽ
506+ ) -> con, S̃, Ẽ, Ẽŝ
498507
499508Init `ControllerConstraint` struct with default parameters based on estimator `estim`.
500509
501- Also return `S̃` and `Ẽ ` matrices for the the augmented decision vector `ΔŨ`.
510+ Also return `S̃`, `Ẽ` and `Ẽŝ ` matrices for the the augmented decision vector `ΔŨ`.
502511"""
503512function init_defaultcon_mpc (
504- estim:: StateEstimator{NT} , Hp, Hc, C, S, E, ex̂, fx̂, gx̂, jx̂, kx̂, vx̂, bx̂,
505- gc!:: GCfunc = nothing , nc= 0
513+ estim:: StateEstimator{NT} ,
514+ Hp, Hc, C,
515+ S, E,
516+ ex̂, fx̂, gx̂, jx̂, kx̂, vx̂, bx̂,
517+ Eŝ, Fŝ, Gŝ, Jŝ, Kŝ, Vŝ, Bŝ,
518+ gc!:: GCfunc = nothing , nc = 0
506519) where {NT<: Real , GCfunc<: Union{Nothing, Function} }
507520 model = estim. model
508521 nu, ny, nx̂ = model. nu, model. ny, estim. nx̂
@@ -523,24 +536,29 @@ function init_defaultcon_mpc(
523536 A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax = relaxΔU (model, nϵ, C, C_Δumin, C_Δumax, ΔUmin, ΔUmax)
524537 A_Ymin, A_Ymax, Ẽ = relaxŶ (model, nϵ, C_ymin, C_ymax, E)
525538 A_x̂min, A_x̂max, ẽx̂ = relaxterminal (model, nϵ, c_x̂min, c_x̂max, ex̂)
526- i_Umin, i_Umax = .! isinf .(U0min), .! isinf .(U0max)
539+ A_ŝ, Ẽŝ = augmentdefect (model, nϵ, Eŝ)
540+ i_Umin, i_Umax = .! isinf .(U0min), .! isinf .(U0max)
527541 i_ΔŨmin, i_ΔŨmax = .! isinf .(ΔŨmin), .! isinf .(ΔŨmax)
528- i_Ymin, i_Ymax = .! isinf .(Y0min), .! isinf .(Y0max)
529- i_x̂min, i_x̂max = .! isinf .(x̂0min), .! isinf .(x̂0max)
542+ i_Ymin, i_Ymax = .! isinf .(Y0min), .! isinf .(Y0max)
543+ i_x̂min, i_x̂max = .! isinf .(x̂0min), .! isinf .(x̂0max)
530544 i_b, i_g, A = init_matconstraint_mpc (
531545 model, nc,
532546 i_Umin, i_Umax, i_ΔŨmin, i_ΔŨmax, i_Ymin, i_Ymax, i_x̂min, i_x̂max,
533547 A_Umin, A_Umax, A_ΔŨmin, A_ΔŨmax, A_Ymin, A_Ymax, A_x̂max, A_x̂min
534548 )
535549 b = zeros (NT, size (A, 1 )) # dummy b vector (updated just before optimization)
536550 con = ControllerConstraint {NT, GCfunc} (
537- ẽx̂ , fx̂ , gx̂ , jx̂ , kx̂ , vx̂ , bx̂ ,
538- U0min , U0max , ΔŨmin , ΔŨmax , Y0min , Y0max , x̂0min , x̂0max,
539- A_Umin , A_Umax, A_ΔŨmin, A_ΔŨmax , A_Ymin , A_Ymax , A_x̂min , A_x̂max,
540- A , b , i_b , C_ymin , C_ymax , c_x̂min , c_x̂max , i_g,
551+ ẽx̂ , fx̂ , gx̂ , jx̂ , kx̂ , vx̂ , bx̂ ,
552+ Ẽŝ , Fŝ , Gŝ , Jŝ , Kŝ , Vŝ , Bŝ ,
553+ U0min , U0max , ΔŨmin , ΔŨmax , Y0min , Y0max , x̂0min , x̂0max,
554+ A_Umin , A_Umax , A_ΔŨmin, A_ΔŨmax , A_Ymin , A_Ymax , A_x̂min , A_x̂max,
555+ A , b , i_b ,
556+ A_ŝ ,
557+ Aeq , beq ,
558+ C_ymin , C_ymax , c_x̂min , c_x̂max , i_g,
541559 gc! , nc
542560 )
543- return con, nϵ, S̃, Ẽ
561+ return con, nϵ, S̃, Ẽ, Ẽŝ
544562end
545563
546564" Repeat predictive controller constraints over prediction `Hp` and control `Hc` horizons."
@@ -554,7 +572,7 @@ function repeat_constraints(Hp, Hc, umin, umax, Δumin, Δumax, ymin, ymax)
554572 return Umin, Umax, ΔUmin, ΔUmax, Ymin, Ymax
555573end
556574
557-
575+ # TODO : change all the next docstringgs with Z̃ instead of ΔŨ !!!!!
558576
559577@doc raw """
560578 relaxU(model, nϵ, C_umin, C_umax, S) -> A_Umin, A_Umax, S̃
@@ -710,6 +728,29 @@ function relaxterminal(::SimModel{NT}, nϵ, c_x̂min, c_x̂max, ex̂) where {NT<
710728 return A_x̂min, A_x̂max, ẽx̂
711729end
712730
731+ """
732+ augmentdefect(::LinModel{NT}, nϵ, Eŝ) where NT<:Real
733+
734+ Augment defect equality constraints with slack variable ϵ if `nϵ == 1`.
735+ """
736+ function augmentdefect (:: LinModel{NT} , nϵ, Eŝ) where NT<: Real
737+ if nϵ == 1 # ΔŨ = [ΔU; ϵ]
738+ Ẽŝ = [Eŝ zeros (NT, size (Eŝ, 1 ), 1 )]
739+ else # ΔŨ = ΔU (only hard constraints)
740+ Ẽŝ = Eŝ
741+ end
742+ A_ŝ = Ẽŝ
743+ return A_ŝ, Ẽŝ
744+ end
745+
746+ " Return empty matrices if model is not a [`LinModel`](@ref)"
747+ function augmentdefect (:: SimModel{NT} , nϵ, Eŝ) where NT<: Real
748+ Ẽŝ = [Eŝ zeros (NT, 0 , nϵ)]
749+ A_ŝ = Ẽŝ
750+ return A_ŝ, Ẽŝ
751+ end
752+
753+
713754@doc raw """
714755 init_stochpred(estim::InternalModel, Hp) -> Ks, Ps
715756
0 commit comments