@@ -144,9 +144,8 @@ function setconstraint!(
144
144
C_Δumin = C_Deltaumin, C_Δumax = C_Deltaumax,
145
145
)
146
146
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ϵ
148
148
notSolvedYet = (JuMP. termination_status (optim) == JuMP. OPTIMIZE_NOT_CALLED)
149
- C = mpc. C
150
149
isnothing (Umin) && ! isnothing (umin) && (Umin = repeat (umin, Hp))
151
150
isnothing (Umax) && ! isnothing (umax) && (Umax = repeat (umax, Hp))
152
151
isnothing (ΔUmin) && ! isnothing (Δumin) && (ΔUmin = repeat (Δumin, Hc))
@@ -160,7 +159,7 @@ function setconstraint!(
160
159
isnothing (C_ymin) && ! isnothing (c_ymin) && (C_ymin = repeat (c_ymin, Hp))
161
160
isnothing (C_ymax) && ! isnothing (c_ymax) && (C_ymax = repeat (c_ymax, Hp))
162
161
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" ))
164
163
notSolvedYet || error (" Cannot set softness parameters after calling moveinput!" )
165
164
end
166
165
if ! isnothing (Umin)
@@ -605,6 +604,7 @@ function init_defaultcon_mpc(
605
604
) where {NT<: Real }
606
605
model = estim. model
607
606
nu, ny, nx̂ = model. nu, model. ny, estim. nx̂
607
+ nϵ = isinf (C) ? 0 : 1
608
608
u0min, u0max = fill (convert (NT,- Inf ), nu), fill (convert (NT,+ Inf ), nu)
609
609
Δumin, Δumax = fill (convert (NT,- Inf ), nu), fill (convert (NT,+ Inf ), nu)
610
610
y0min, y0max = fill (convert (NT,- Inf ), ny), fill (convert (NT,+ Inf ), ny)
@@ -617,12 +617,12 @@ function init_defaultcon_mpc(
617
617
repeat_constraints (Hp, Hc, u0min, u0max, Δumin, Δumax, y0min, y0max)
618
618
C_umin, C_umax, C_Δumin, C_Δumax, C_ymin, C_ymax =
619
619
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)
621
621
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
623
623
)
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̂)
626
626
i_Umin, i_Umax = .! isinf .(U0min), .! isinf .(U0max)
627
627
i_ΔŨmin, i_ΔŨmax = .! isinf .(ΔŨmin), .! isinf .(ΔŨmax)
628
628
i_Ymin, i_Ymax = .! isinf .(Y0min), .! isinf .(Y0max)
@@ -639,7 +639,7 @@ function init_defaultcon_mpc(
639
639
A_Umin , A_Umax, A_ΔŨmin, A_ΔŨmax , A_Ymin , A_Ymax , A_x̂min , A_x̂max,
640
640
A , b , i_b , C_ymin , C_ymax , c_x̂min , c_x̂max , i_g
641
641
)
642
- return con, S̃, Ñ_Hc, Ẽ
642
+ return con, nϵ, S̃, Ñ_Hc, Ẽ
643
643
end
644
644
645
645
" Repeat predictive controller constraints over prediction `Hp` and control `Hc` horizons."
656
656
657
657
658
658
@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̃
660
660
661
661
Augment manipulated inputs constraints with slack variable ϵ for softening.
662
662
@@ -678,8 +678,8 @@ constraints:
678
678
in which ``\m athbf{U_{min}, U_{max}}`` and ``\m athbf{U_{op}}`` vectors respectively contains
679
679
``\m athbf{u_{min}, u_{max}}`` and ``\m athbf{u_{op}}`` repeated ``H_p`` times.
680
680
"""
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; ϵ]
683
683
# ϵ impacts ΔU → U conversion for constraint calculations:
684
684
A_Umin, A_Umax = - [S C_umin], [S - C_umax]
685
685
# ϵ has no impact on ΔU → U conversion for prediction calculations:
693
693
694
694
@doc raw """
695
695
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
697
697
) -> A_ΔŨmin, A_ΔŨmax, ΔŨmin, ΔŨmax, Ñ_Hc
698
698
699
699
Augment input increments constraints with slack variable ϵ for softening.
@@ -714,9 +714,9 @@ returns the augmented constraints ``\mathbf{ΔŨ_{min}}`` and ``\mathbf{ΔŨ_{
714
714
\e nd{bmatrix}
715
715
```
716
716
"""
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
718
718
nΔU = size (N_Hc, 1 )
719
- if ! isinf (C) # ΔŨ = [ΔU; ϵ]
719
+ if nϵ == 1 # ΔŨ = [ΔU; ϵ]
720
720
# 0 ≤ ϵ ≤ ∞
721
721
ΔŨmin, ΔŨmax = [ΔUmin; NT[0.0 ]], [ΔUmax; NT[Inf ]]
722
722
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
732
732
end
733
733
734
734
@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, Ẽ
736
736
737
737
Augment linear output prediction constraints with slack variable ϵ for softening.
738
738
@@ -753,8 +753,8 @@ Denoting the input increments augmented with the slack variable
753
753
in which ``\m athbf{Y_{min}, Y_{max}}`` and ``\m athbf{Y_{op}}`` vectors respectively contains
754
754
``\m athbf{y_{min}, y_{max}}`` and ``\m athbf{y_{op}}`` repeated ``H_p`` times.
755
755
"""
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; ϵ]
758
758
# ϵ impacts predicted output constraint calculations:
759
759
A_Ymin, A_Ymax = - [E C_ymin], [E - C_ymax]
760
760
# ϵ has no impact on output predictions:
@@ -767,14 +767,14 @@ function relaxŶ(::LinModel{NT}, C, C_ymin, C_ymax, E) where {NT<:Real}
767
767
end
768
768
769
769
" 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ϵ)]
772
772
A_Ymin, A_Ymax = - Ẽ, Ẽ
773
773
return A_Ymin, A_Ymax, Ẽ
774
774
end
775
775
776
776
@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̂
778
778
779
779
Augment terminal state constraints with slack variable ϵ for softening.
780
780
@@ -794,8 +794,8 @@ the inequality constraints:
794
794
\e nd{bmatrix}
795
795
```
796
796
"""
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; ϵ]
799
799
# ϵ impacts terminal state constraint calculations:
800
800
A_x̂min, A_x̂max = - [ex̂ c_x̂min], [ex̂ - c_x̂max]
801
801
# ϵ 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
808
808
end
809
809
810
810
" 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ϵ)]
813
813
A_x̂min, A_x̂max = - ẽx̂, ẽx̂
814
814
return A_x̂min, A_x̂max, ẽx̂
815
815
end
@@ -853,7 +853,7 @@ function init_stochpred(estim::StateEstimator{NT}, _ ) where NT<:Real
853
853
end
854
854
855
855
" 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 )
857
857
nu, ny = model. nu, model. ny
858
858
nM, nN, nL = ny* Hp, nu* Hc, nu* Hp
859
859
Hp < 1 && throw (ArgumentError (" Prediction horizon Hp should be ≥ 1" ))
0 commit comments