@@ -60,6 +60,7 @@ struct MovingHorizonEstimator{
6060 f̂op:: Vector{NT}
6161 x̂0 :: Vector{NT}
6262 He:: Int
63+ nϵ:: Int
6364 i_ym:: Vector{Int}
6465 nx̂ :: Int
6566 nym:: Int
@@ -125,7 +126,9 @@ struct MovingHorizonEstimator{
125126 )
126127 # dummy values (updated just before optimization):
127128 F, fx̄, Fx̂ = zeros (NT, nym* He), zeros (NT, nx̂), zeros (NT, nx̂* He)
128- con, Ẽ, ẽx̄ = init_defaultcon_mhe (model, He, Cwt, nx̂, nym, E, ex̄, Ex̂, Fx̂, Gx̂, Jx̂, Bx̂)
129+ con, nϵ, Ẽ, ẽx̄ = init_defaultcon_mhe (
130+ model, He, Cwt, nx̂, nym, E, ex̄, Ex̂, Fx̂, Gx̂, Jx̂, Bx̂
131+ )
129132 nZ̃ = size (Ẽ, 2 )
130133 # dummy values, updated before optimization:
131134 H̃, q̃, p = Hermitian (zeros (NT, nZ̃, nZ̃), :L ), zeros (NT, nZ̃), zeros (NT, 1 )
@@ -140,7 +143,7 @@ struct MovingHorizonEstimator{
140143 estim = new {NT, SM, JM, CE} (
141144 model, optim, con, covestim,
142145 Z̃, lastu0, x̂op, f̂op, x̂0,
143- He,
146+ He, nϵ,
144147 i_ym, nx̂, nym, nyu, nxs,
145148 As, Cs_u, Cs_y, nint_u, nint_ym,
146149 Â, B̂u, Ĉ, B̂d, D̂d,
@@ -641,6 +644,7 @@ function init_defaultcon_mhe(
641644) where {NT<: Real }
642645 nŵ = nx̂
643646 nZ̃, nX̂, nŴ, nYm = nx̂+ nŵ* He, nx̂* He, nŵ* He, nym* He
647+ nϵ = isinf (C) ? 0 : 1
644648 x̂min, x̂max = fill (convert (NT,- Inf ), nx̂), fill (convert (NT,+ Inf ), nx̂)
645649 X̂min, X̂max = fill (convert (NT,- Inf ), nX̂), fill (convert (NT,+ Inf ), nX̂)
646650 Ŵmin, Ŵmax = fill (convert (NT,- Inf ), nŴ), fill (convert (NT,+ Inf ), nŴ)
@@ -649,10 +653,10 @@ function init_defaultcon_mhe(
649653 C_x̂min, C_x̂max = fill (0.0 , nX̂), fill (0.0 , nX̂)
650654 C_ŵmin, C_ŵmax = fill (0.0 , nŴ), fill (0.0 , nŴ)
651655 C_v̂min, C_v̂max = fill (0.0 , nYm), fill (0.0 , nYm)
652- A_x̃min, A_x̃max, x̃min, x̃max, ẽx̄ = relaxarrival (model, C , c_x̂min, c_x̂max, x̂min, x̂max, ex̄)
653- A_X̂min, A_X̂max, Ẽx̂ = relaxX̂ (model, C , C_x̂min, C_x̂max, Ex̂)
654- A_Ŵmin, A_Ŵmax = relaxŴ (model, C , C_ŵmin, C_ŵmax, nx̂)
655- A_V̂min, A_V̂max, Ẽ = relaxV̂ (model, C , C_v̂min, C_v̂max, E)
656+ A_x̃min, A_x̃max, x̃min, x̃max, ẽx̄ = relaxarrival (model, nϵ , c_x̂min, c_x̂max, x̂min, x̂max, ex̄)
657+ A_X̂min, A_X̂max, Ẽx̂ = relaxX̂ (model, nϵ , C_x̂min, C_x̂max, Ex̂)
658+ A_Ŵmin, A_Ŵmax = relaxŴ (model, nϵ , C_ŵmin, C_ŵmax, nx̂)
659+ A_V̂min, A_V̂max, Ẽ = relaxV̂ (model, nϵ , C_v̂min, C_v̂max, E)
656660 i_x̃min, i_x̃max = .! isinf .(x̃min), .! isinf .(x̃max)
657661 i_X̂min, i_X̂max = .! isinf .(X̂min), .! isinf .(X̂max)
658662 i_Ŵmin, i_Ŵmax = .! isinf .(Ŵmin), .! isinf .(Ŵmax)
@@ -670,12 +674,12 @@ function init_defaultcon_mhe(
670674 C_x̂min, C_x̂max, C_v̂min, C_v̂max,
671675 i_b, i_g
672676 )
673- return con, Ẽ, ẽx̄
677+ return con, nϵ, Ẽ, ẽx̄
674678end
675679
676680@doc raw """
677681 relaxarrival(
678- model::SimModel, C , c_x̂min, c_x̂max, x̂min, x̂max, ex̄
682+ model::SimModel, nϵ , c_x̂min, c_x̂max, x̂min, x̂max, ex̄
679683 ) -> A_x̃min, A_x̃max, x̃min, x̃max, ẽx̄
680684
681685Augment arrival state constraints with slack variable ϵ for softening the MHE.
@@ -700,9 +704,9 @@ in which
700704``\m athbf{x̃_{max}} = [\b egin{smallmatrix} ∞ \\ \m athbf{x̂_{max}} \e nd{smallmatrix}]`` and
701705``\m athbf{x̃_{op}} = [\b egin{smallmatrix} 0 \\ \m athbf{x̂_{op}} \e nd{smallmatrix}]``
702706"""
703- function relaxarrival (:: SimModel{NT} , C , c_x̂min, c_x̂max, x̂min, x̂max, ex̄) where {NT<: Real }
707+ function relaxarrival (:: SimModel{NT} , nϵ , c_x̂min, c_x̂max, x̂min, x̂max, ex̄) where {NT<: Real }
704708 ex̂ = - ex̄
705- if ! isinf (C) # Z̃ = [ϵ; Z]
709+ if nϵ ≠ 0 # Z̃ = [ϵ; Z]
706710 x̃min, x̃max = [NT[0.0 ]; x̂min], [NT[Inf ]; x̂max]
707711 A_ϵ = [NT[1.0 ] zeros (NT, 1 , size (ex̂, 2 ))]
708712 # ϵ impacts arrival state constraint calculations:
@@ -718,7 +722,7 @@ function relaxarrival(::SimModel{NT}, C, c_x̂min, c_x̂max, x̂min, x̂max, ex
718722end
719723
720724@doc raw """
721- relaxX̂(model::SimModel, C , C_x̂min, C_x̂max, Ex̂) -> A_X̂min, A_X̂max, Ẽx̂
725+ relaxX̂(model::SimModel, nϵ , C_x̂min, C_x̂max, Ex̂) -> A_X̂min, A_X̂max, Ẽx̂
722726
723727Augment estimated state constraints with slack variable ϵ for softening the MHE.
724728
@@ -739,8 +743,8 @@ also returns the ``\mathbf{A}`` matrices for the inequality constraints:
739743in which ``\m athbf{X̂_{min}, X̂_{max}}`` and ``\m athbf{X̂_{op}}`` vectors respectively contains
740744``\m athbf{x̂_{min}, x̂_{max}}`` and ``\m athbf{x̂_{op}}`` repeated ``H_e`` times.
741745"""
742- function relaxX̂ (:: LinModel{NT} , C , C_x̂min, C_x̂max, Ex̂) where {NT<: Real }
743- if ! isinf (C) # Z̃ = [ϵ; Z]
746+ function relaxX̂ (:: LinModel{NT} , nϵ , C_x̂min, C_x̂max, Ex̂) where {NT<: Real }
747+ if nϵ ≠ 0 # Z̃ = [ϵ; Z]
744748 # ϵ impacts estimated process noise constraint calculations:
745749 A_X̂min, A_X̂max = - [C_x̂min Ex̂], [- C_x̂max Ex̂]
746750 # ϵ has no impact on estimated process noises:
@@ -753,14 +757,14 @@ function relaxX̂(::LinModel{NT}, C, C_x̂min, C_x̂max, Ex̂) where {NT<:Real}
753757end
754758
755759" Return empty matrices if model is not a [`LinModel`](@ref)"
756- function relaxX̂ (:: SimModel{NT} , C , C_x̂min, C_x̂max, Ex̂) where {NT<: Real }
757- Ẽx̂ = ! isinf (C) ? [zeros (NT, 0 , 1 ) Ex̂] : Ex̂
760+ function relaxX̂ (:: SimModel{NT} , nϵ , C_x̂min, C_x̂max, Ex̂) where {NT<: Real }
761+ Ẽx̂ = [zeros (NT, 0 , nϵ ) Ex̂]
758762 A_X̂min, A_X̂max = - Ẽx̂, Ẽx̂
759763 return A_X̂min, A_X̂max, Ẽx̂
760764end
761765
762766@doc raw """
763- relaxŴ(model::SimModel, C , C_ŵmin, C_ŵmax, nx̂) -> A_Ŵmin, A_Ŵmax
767+ relaxŴ(model::SimModel, nϵ , C_ŵmin, C_ŵmax, nx̂) -> A_Ŵmin, A_Ŵmax
764768
765769Augment estimated process noise constraints with slack variable ϵ for softening the MHE.
766770
@@ -778,9 +782,9 @@ matrices for the inequality constraints:
778782\e nd{bmatrix}
779783```
780784"""
781- function relaxŴ (:: SimModel{NT} , C , C_ŵmin, C_ŵmax, nx̂) where {NT<: Real }
785+ function relaxŴ (:: SimModel{NT} , nϵ , C_ŵmin, C_ŵmax, nx̂) where {NT<: Real }
782786 A = [zeros (NT, length (C_ŵmin), nx̂) I]
783- if ! isinf (C) # Z̃ = [ϵ; Z]
787+ if nϵ ≠ 0 # Z̃ = [ϵ; Z]
784788 A_Ŵmin, A_Ŵmax = - [C_ŵmin A], [- C_ŵmax A]
785789 else # Z̃ = Z (only hard constraints)
786790 A_Ŵmin, A_Ŵmax = - A, A
@@ -789,7 +793,7 @@ function relaxŴ(::SimModel{NT}, C, C_ŵmin, C_ŵmax, nx̂) where {NT<:Real}
789793end
790794
791795@doc raw """
792- relaxV̂(model::SimModel, C , C_v̂min, C_v̂max, E) -> A_V̂min, A_V̂max, Ẽ
796+ relaxV̂(model::SimModel, nϵ , C_v̂min, C_v̂max, E) -> A_V̂min, A_V̂max, Ẽ
793797
794798Augment estimated sensor noise constraints with slack variable ϵ for softening the MHE.
795799
@@ -808,8 +812,8 @@ also returns the ``\mathbf{A}`` matrices for the inequality constraints:
808812\e nd{bmatrix}
809813```
810814"""
811- function relaxV̂ (:: LinModel{NT} , C , C_v̂min, C_v̂max, E) where {NT<: Real }
812- if ! isinf (C) # Z̃ = [ϵ; Z]
815+ function relaxV̂ (:: LinModel{NT} , nϵ , C_v̂min, C_v̂max, E) where {NT<: Real }
816+ if nϵ ≠ 0 # Z̃ = [ϵ; Z]
813817 # ϵ impacts estimated sensor noise constraint calculations:
814818 A_V̂min, A_V̂max = - [C_v̂min E], [- C_v̂max E]
815819 # ϵ has no impact on estimated sensor noises:
@@ -822,8 +826,8 @@ function relaxV̂(::LinModel{NT}, C, C_v̂min, C_v̂max, E) where {NT<:Real}
822826end
823827
824828" Return empty matrices if model is not a [`LinModel`](@ref)"
825- function relaxV̂ (:: SimModel{NT} , C , C_v̂min, C_v̂max, E) where {NT<: Real }
826- Ẽ = ! isinf (C) ? [zeros (NT, 0 , 1 ) E] : E
829+ function relaxV̂ (:: SimModel{NT} , nϵ , C_v̂min, C_v̂max, E) where {NT<: Real }
830+ Ẽ = [zeros (NT, 0 , nϵ ) E]
827831 A_V̂min, A_V̂max = - Ẽ, Ẽ
828832 return A_V̂min, A_V̂max, Ẽ
829833end
0 commit comments