@@ -60,6 +60,7 @@ struct MovingHorizonEstimator{
60
60
f̂op:: Vector{NT}
61
61
x̂0 :: Vector{NT}
62
62
He:: Int
63
+ nϵ:: Int
63
64
i_ym:: Vector{Int}
64
65
nx̂ :: Int
65
66
nym:: Int
@@ -125,7 +126,9 @@ struct MovingHorizonEstimator{
125
126
)
126
127
# dummy values (updated just before optimization):
127
128
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
+ )
129
132
nZ̃ = size (Ẽ, 2 )
130
133
# dummy values, updated before optimization:
131
134
H̃, q̃, p = Hermitian (zeros (NT, nZ̃, nZ̃), :L ), zeros (NT, nZ̃), zeros (NT, 1 )
@@ -140,7 +143,7 @@ struct MovingHorizonEstimator{
140
143
estim = new {NT, SM, JM, CE} (
141
144
model, optim, con, covestim,
142
145
Z̃, lastu0, x̂op, f̂op, x̂0,
143
- He,
146
+ He, nϵ,
144
147
i_ym, nx̂, nym, nyu, nxs,
145
148
As, Cs_u, Cs_y, nint_u, nint_ym,
146
149
Â, B̂u, Ĉ, B̂d, D̂d,
@@ -641,6 +644,7 @@ function init_defaultcon_mhe(
641
644
) where {NT<: Real }
642
645
nŵ = nx̂
643
646
nZ̃, nX̂, nŴ, nYm = nx̂+ nŵ* He, nx̂* He, nŵ* He, nym* He
647
+ nϵ = isinf (C) ? 0 : 1
644
648
x̂min, x̂max = fill (convert (NT,- Inf ), nx̂), fill (convert (NT,+ Inf ), nx̂)
645
649
X̂min, X̂max = fill (convert (NT,- Inf ), nX̂), fill (convert (NT,+ Inf ), nX̂)
646
650
Ŵmin, Ŵmax = fill (convert (NT,- Inf ), nŴ), fill (convert (NT,+ Inf ), nŴ)
@@ -649,10 +653,10 @@ function init_defaultcon_mhe(
649
653
C_x̂min, C_x̂max = fill (0.0 , nX̂), fill (0.0 , nX̂)
650
654
C_ŵmin, C_ŵmax = fill (0.0 , nŴ), fill (0.0 , nŴ)
651
655
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)
656
660
i_x̃min, i_x̃max = .! isinf .(x̃min), .! isinf .(x̃max)
657
661
i_X̂min, i_X̂max = .! isinf .(X̂min), .! isinf .(X̂max)
658
662
i_Ŵmin, i_Ŵmax = .! isinf .(Ŵmin), .! isinf .(Ŵmax)
@@ -670,12 +674,12 @@ function init_defaultcon_mhe(
670
674
C_x̂min, C_x̂max, C_v̂min, C_v̂max,
671
675
i_b, i_g
672
676
)
673
- return con, Ẽ, ẽx̄
677
+ return con, nϵ, Ẽ, ẽx̄
674
678
end
675
679
676
680
@doc raw """
677
681
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̄
679
683
) -> A_x̃min, A_x̃max, x̃min, x̃max, ẽx̄
680
684
681
685
Augment arrival state constraints with slack variable ϵ for softening the MHE.
@@ -700,9 +704,9 @@ in which
700
704
``\m athbf{x̃_{max}} = [\b egin{smallmatrix} ∞ \\ \m athbf{x̂_{max}} \e nd{smallmatrix}]`` and
701
705
``\m athbf{x̃_{op}} = [\b egin{smallmatrix} 0 \\ \m athbf{x̂_{op}} \e nd{smallmatrix}]``
702
706
"""
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 }
704
708
ex̂ = - ex̄
705
- if ! isinf (C) # Z̃ = [ϵ; Z]
709
+ if nϵ ≠ 0 # Z̃ = [ϵ; Z]
706
710
x̃min, x̃max = [NT[0.0 ]; x̂min], [NT[Inf ]; x̂max]
707
711
A_ϵ = [NT[1.0 ] zeros (NT, 1 , size (ex̂, 2 ))]
708
712
# ϵ 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
718
722
end
719
723
720
724
@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̂
722
726
723
727
Augment estimated state constraints with slack variable ϵ for softening the MHE.
724
728
@@ -739,8 +743,8 @@ also returns the ``\mathbf{A}`` matrices for the inequality constraints:
739
743
in which ``\m athbf{X̂_{min}, X̂_{max}}`` and ``\m athbf{X̂_{op}}`` vectors respectively contains
740
744
``\m athbf{x̂_{min}, x̂_{max}}`` and ``\m athbf{x̂_{op}}`` repeated ``H_e`` times.
741
745
"""
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]
744
748
# ϵ impacts estimated process noise constraint calculations:
745
749
A_X̂min, A_X̂max = - [C_x̂min Ex̂], [- C_x̂max Ex̂]
746
750
# ϵ 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}
753
757
end
754
758
755
759
" 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̂]
758
762
A_X̂min, A_X̂max = - Ẽx̂, Ẽx̂
759
763
return A_X̂min, A_X̂max, Ẽx̂
760
764
end
761
765
762
766
@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
764
768
765
769
Augment estimated process noise constraints with slack variable ϵ for softening the MHE.
766
770
@@ -778,9 +782,9 @@ matrices for the inequality constraints:
778
782
\e nd{bmatrix}
779
783
```
780
784
"""
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 }
782
786
A = [zeros (NT, length (C_ŵmin), nx̂) I]
783
- if ! isinf (C) # Z̃ = [ϵ; Z]
787
+ if nϵ ≠ 0 # Z̃ = [ϵ; Z]
784
788
A_Ŵmin, A_Ŵmax = - [C_ŵmin A], [- C_ŵmax A]
785
789
else # Z̃ = Z (only hard constraints)
786
790
A_Ŵmin, A_Ŵmax = - A, A
@@ -789,7 +793,7 @@ function relaxŴ(::SimModel{NT}, C, C_ŵmin, C_ŵmax, nx̂) where {NT<:Real}
789
793
end
790
794
791
795
@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, Ẽ
793
797
794
798
Augment estimated sensor noise constraints with slack variable ϵ for softening the MHE.
795
799
@@ -808,8 +812,8 @@ also returns the ``\mathbf{A}`` matrices for the inequality constraints:
808
812
\e nd{bmatrix}
809
813
```
810
814
"""
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]
813
817
# ϵ impacts estimated sensor noise constraint calculations:
814
818
A_V̂min, A_V̂max = - [C_v̂min E], [- C_v̂max E]
815
819
# ϵ 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}
822
826
end
823
827
824
828
" 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]
827
831
A_V̂min, A_V̂max = - Ẽ, Ẽ
828
832
return A_V̂min, A_V̂max, Ẽ
829
833
end
0 commit comments