@@ -144,9 +144,8 @@ function setconstraint!(
144144 C_Δumin = C_Deltaumin, C_Δumax = C_Deltaumax,
145145)
146146 model, con, optim = mpc. estim. model, mpc. con, mpc. optim
147- nu, ny, nx̂, Hp, Hc = model. nu, model. ny, mpc. estim. nx̂, mpc. Hp, mpc. Hc
147+ nu, ny, nx̂, Hp, Hc, nϵ = model. nu, model. ny, mpc. estim. nx̂, mpc. Hp, mpc. Hc, mpc . nϵ
148148 notSolvedYet = (JuMP. termination_status (optim) == JuMP. OPTIMIZE_NOT_CALLED)
149- C = mpc. C
150149 isnothing (Umin) && ! isnothing (umin) && (Umin = repeat (umin, Hp))
151150 isnothing (Umax) && ! isnothing (umax) && (Umax = repeat (umax, Hp))
152151 isnothing (ΔUmin) && ! isnothing (Δumin) && (ΔUmin = repeat (Δumin, Hc))
@@ -160,7 +159,7 @@ function setconstraint!(
160159 isnothing (C_ymin) && ! isnothing (c_ymin) && (C_ymin = repeat (c_ymin, Hp))
161160 isnothing (C_ymax) && ! isnothing (c_ymax) && (C_ymax = repeat (c_ymax, Hp))
162161 if ! all (isnothing .((C_umin, C_umax, C_Δumin, C_Δumax, C_ymin, C_ymax, c_x̂min, c_x̂max)))
163- ! isinf (C) || throw (ArgumentError (" Slack variable weight Cwt must be finite to set softness parameters" ))
162+ nϵ == 1 || throw (ArgumentError (" Slack variable weight Cwt must be finite to set softness parameters" ))
164163 notSolvedYet || error (" Cannot set softness parameters after calling moveinput!" )
165164 end
166165 if ! isnothing (Umin)
@@ -605,6 +604,7 @@ function init_defaultcon_mpc(
605604) where {NT<: Real }
606605 model = estim. model
607606 nu, ny, nx̂ = model. nu, model. ny, estim. nx̂
607+ nϵ = isinf (C) ? 0 : 1
608608 u0min, u0max = fill (convert (NT,- Inf ), nu), fill (convert (NT,+ Inf ), nu)
609609 Δumin, Δumax = fill (convert (NT,- Inf ), nu), fill (convert (NT,+ Inf ), nu)
610610 y0min, y0max = fill (convert (NT,- Inf ), ny), fill (convert (NT,+ Inf ), ny)
@@ -617,12 +617,12 @@ function init_defaultcon_mpc(
617617 repeat_constraints (Hp, Hc, u0min, u0max, Δumin, Δumax, y0min, y0max)
618618 C_umin, C_umax, C_Δumin, C_Δumax, C_ymin, C_ymax =
619619 repeat_constraints (Hp, Hc, c_umin, c_umax, c_Δumin, c_Δumax, c_ymin, c_ymax)
620- A_Umin, A_Umax, S̃ = relaxU (model, C , C_umin, C_umax, S)
620+ A_Umin, A_Umax, S̃ = relaxU (model, nϵ , C_umin, C_umax, S)
621621 A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, Ñ_Hc = relaxΔU (
622- model, C, C_Δumin, C_Δumax, ΔUmin, ΔUmax, N_Hc
622+ model, nϵ, C, C_Δumin, C_Δumax, ΔUmin, ΔUmax, N_Hc
623623 )
624- A_Ymin, A_Ymax, Ẽ = relaxŶ (model, C , C_ymin, C_ymax, E)
625- A_x̂min, A_x̂max, ẽx̂ = relaxterminal (model, C , c_x̂min, c_x̂max, ex̂)
624+ A_Ymin, A_Ymax, Ẽ = relaxŶ (model, nϵ , C_ymin, C_ymax, E)
625+ A_x̂min, A_x̂max, ẽx̂ = relaxterminal (model, nϵ , c_x̂min, c_x̂max, ex̂)
626626 i_Umin, i_Umax = .! isinf .(U0min), .! isinf .(U0max)
627627 i_ΔŨmin, i_ΔŨmax = .! isinf .(ΔŨmin), .! isinf .(ΔŨmax)
628628 i_Ymin, i_Ymax = .! isinf .(Y0min), .! isinf .(Y0max)
@@ -639,7 +639,7 @@ function init_defaultcon_mpc(
639639 A_Umin , A_Umax, A_ΔŨmin, A_ΔŨmax , A_Ymin , A_Ymax , A_x̂min , A_x̂max,
640640 A , b , i_b , C_ymin , C_ymax , c_x̂min , c_x̂max , i_g
641641 )
642- return con, S̃, Ñ_Hc, Ẽ
642+ return con, nϵ, S̃, Ñ_Hc, Ẽ
643643end
644644
645645" Repeat predictive controller constraints over prediction `Hp` and control `Hc` horizons."
656656
657657
658658@doc raw """
659- relaxU(model, C , C_umin, C_umax, S) -> A_Umin, A_Umax, S̃
659+ relaxU(model, nϵ , C_umin, C_umax, S) -> A_Umin, A_Umax, S̃
660660
661661Augment manipulated inputs constraints with slack variable ϵ for softening.
662662
@@ -678,8 +678,8 @@ constraints:
678678in which ``\m athbf{U_{min}, U_{max}}`` and ``\m athbf{U_{op}}`` vectors respectively contains
679679``\m athbf{u_{min}, u_{max}}`` and ``\m athbf{u_{op}}`` repeated ``H_p`` times.
680680"""
681- function relaxU (:: SimModel{NT} , C , C_umin, C_umax, S) where { NT<: Real }
682- if ! isinf (C) # ΔŨ = [ΔU; ϵ]
681+ function relaxU (:: SimModel{NT} , nϵ , C_umin, C_umax, S) where NT<: Real
682+ if nϵ == 1 # ΔŨ = [ΔU; ϵ]
683683 # ϵ impacts ΔU → U conversion for constraint calculations:
684684 A_Umin, A_Umax = - [S C_umin], [S - C_umax]
685685 # ϵ has no impact on ΔU → U conversion for prediction calculations:
693693
694694@doc raw """
695695 relaxΔU(
696- model, C, C_Δumin, C_Δumax, ΔUmin, ΔUmax, N_Hc
696+ model, nϵ, C, C_Δumin, C_Δumax, ΔUmin, ΔUmax, N_Hc
697697 ) -> A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, Ñ_Hc
698698
699699Augment input increments constraints with slack variable ϵ for softening.
@@ -714,9 +714,9 @@ returns the augmented constraints ``\mathbf{ΔŨ_{min}}`` and ``\mathbf{ΔŨ_{
714714\e nd{bmatrix}
715715```
716716"""
717- function relaxΔU (:: SimModel{NT} , C, C_Δumin, C_Δumax, ΔUmin, ΔUmax, N_Hc) where { NT<: Real }
717+ function relaxΔU (:: SimModel{NT} , nϵ, C, C_Δumin, C_Δumax, ΔUmin, ΔUmax, N_Hc) where NT<: Real
718718 nΔU = size (N_Hc, 1 )
719- if ! isinf (C) # ΔŨ = [ΔU; ϵ]
719+ if nϵ == 1 # ΔŨ = [ΔU; ϵ]
720720 # 0 ≤ ϵ ≤ ∞
721721 ΔŨmin, ΔŨmax = [ΔUmin; NT[0.0 ]], [ΔUmax; NT[Inf ]]
722722 A_ϵ = [zeros (NT, 1 , length (ΔUmin)) NT[1.0 ]]
@@ -732,7 +732,7 @@ function relaxΔU(::SimModel{NT}, C, C_Δumin, C_Δumax, ΔUmin, ΔUmax, N_Hc) w
732732end
733733
734734@doc raw """
735- relaxŶ(::LinModel, C , C_ymin, C_ymax, E) -> A_Ymin, A_Ymax, Ẽ
735+ relaxŶ(::LinModel, nϵ , C_ymin, C_ymax, E) -> A_Ymin, A_Ymax, Ẽ
736736
737737Augment linear output prediction constraints with slack variable ϵ for softening.
738738
@@ -753,8 +753,8 @@ Denoting the input increments augmented with the slack variable
753753in which ``\m athbf{Y_{min}, Y_{max}}`` and ``\m athbf{Y_{op}}`` vectors respectively contains
754754``\m athbf{y_{min}, y_{max}}`` and ``\m athbf{y_{op}}`` repeated ``H_p`` times.
755755"""
756- function relaxŶ (:: LinModel{NT} , C , C_ymin, C_ymax, E) where { NT<: Real }
757- if ! isinf (C) # ΔŨ = [ΔU; ϵ]
756+ function relaxŶ (:: LinModel{NT} , nϵ , C_ymin, C_ymax, E) where NT<: Real
757+ if nϵ == 1 # ΔŨ = [ΔU; ϵ]
758758 # ϵ impacts predicted output constraint calculations:
759759 A_Ymin, A_Ymax = - [E C_ymin], [E - C_ymax]
760760 # ϵ has no impact on output predictions:
@@ -767,14 +767,14 @@ function relaxŶ(::LinModel{NT}, C, C_ymin, C_ymax, E) where {NT<:Real}
767767end
768768
769769" Return empty matrices if model is not a [`LinModel`](@ref)"
770- function relaxŶ (:: SimModel{NT} , C , C_ymin, C_ymax, E) where { NT<: Real }
771- Ẽ = ! isinf (C) ? [E zeros (NT, 0 , 1 )] : E
770+ function relaxŶ (:: SimModel{NT} , nϵ , C_ymin, C_ymax, E) where NT<: Real
771+ Ẽ = [E zeros (NT, 0 , nϵ)]
772772 A_Ymin, A_Ymax = - Ẽ, Ẽ
773773 return A_Ymin, A_Ymax, Ẽ
774774end
775775
776776@doc raw """
777- relaxterminal(::LinModel, C , c_x̂min, c_x̂max, ex̂) -> A_x̂min, A_x̂max, ẽx̂
777+ relaxterminal(::LinModel, nϵ , c_x̂min, c_x̂max, ex̂) -> A_x̂min, A_x̂max, ẽx̂
778778
779779Augment terminal state constraints with slack variable ϵ for softening.
780780
@@ -794,8 +794,8 @@ the inequality constraints:
794794\e nd{bmatrix}
795795```
796796"""
797- function relaxterminal (:: LinModel{NT} , C , c_x̂min, c_x̂max, ex̂) where {NT<: Real }
798- if ! isinf (C) # ΔŨ = [ΔU; ϵ]
797+ function relaxterminal (:: LinModel{NT} , nϵ , c_x̂min, c_x̂max, ex̂) where {NT<: Real }
798+ if nϵ == 1 # ΔŨ = [ΔU; ϵ]
799799 # ϵ impacts terminal state constraint calculations:
800800 A_x̂min, A_x̂max = - [ex̂ c_x̂min], [ex̂ - c_x̂max]
801801 # ϵ has no impact on terminal state predictions:
@@ -808,8 +808,8 @@ function relaxterminal(::LinModel{NT}, C, c_x̂min, c_x̂max, ex̂) where {NT<:R
808808end
809809
810810" Return empty matrices if model is not a [`LinModel`](@ref)"
811- function relaxterminal (:: SimModel{NT} , C , c_x̂min, c_x̂max, ex̂) where {NT<: Real }
812- ẽx̂ = ! isinf (C) ? [ex̂ zeros (NT, 0 , 1 )] : ex̂
811+ function relaxterminal (:: SimModel{NT} , nϵ , c_x̂min, c_x̂max, ex̂) where {NT<: Real }
812+ ẽx̂ = [ex̂ zeros (NT, 0 , nϵ)]
813813 A_x̂min, A_x̂max = - ẽx̂, ẽx̂
814814 return A_x̂min, A_x̂max, ẽx̂
815815end
@@ -853,7 +853,7 @@ function init_stochpred(estim::StateEstimator{NT}, _ ) where NT<:Real
853853end
854854
855855" Validate predictive controller weight and horizon specified values."
856- function validate_weights (model, Hp, Hc, M_Hp, N_Hc, L_Hp, C, E= nothing )
856+ function validate_weights (model, Hp, Hc, M_Hp, N_Hc, L_Hp, C= Inf , E= nothing )
857857 nu, ny = model. nu, model. ny
858858 nM, nN, nL = ny* Hp, nu* Hc, nu* Hp
859859 Hp < 1 && throw (ArgumentError (" Prediction horizon Hp should be ≥ 1" ))
0 commit comments