Skip to content

Commit 6023e56

Browse files
committed
debug: soft algebraic variable constraint now works
1 parent b37392e commit 6023e56

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎src/estimator/mhe/execute.jl‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,11 @@ function add_data_windows!(estim::MovingHorizonEstimator, y0m, d0, u0=estim.last
583583
return ismoving
584584
end
585585

586-
"Truncate the bounds `Bmin` and `Bmax` to the window size `Nk` if `Nk < He`."
587-
function trunc_bounds(estim::MovingHorizonEstimator{NT}, Bmin, Bmax, n) where NT<:Real
588-
He, Nk = estim.He, estim.Nk[]
589-
if Nk < He
590-
nB = n*Nk
591-
Bmin_t, Bmax_t = similar(Bmin), similar(Bmax)
586+
"Truncate the bounds `Bmin` and `Bmax` to the window size `N` if `Nk < He`."
587+
function trunc_bounds(estim::MovingHorizonEstimator, Bmin, Bmax, n, N=estim.Nk[])
588+
if estim.Nk[] < estim.He
589+
nB = n*N
590+
Bmin_t, Bmax_t = similar(Bmin), similar(Bmax)
592591
Bmin_t[1:nB] .= @views Bmin[end-nB+1:end]
593592
Bmin_t[nB+1:end] .= -Inf
594593
Bmax_t[1:nB] .= @views Bmax[end-nB+1:end]

‎src/estimator/mhe/transcription.jl‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,6 @@ function linconstraint!(
897897
model.nd > 0 && mul!(FX̂, JX̂, D0, 1, 1)
898898
# --- update b vector for linear inequality constraints ---
899899
nX̂_He, nŴ_He, nV̂_He = length(X̂0min), length(Ŵmin), length(V̂min)
900-
nx̂ = length(estim.con.x̂0min)
901900
n = 0
902901
estim.con.b[(n+1):(n+nx̂)] .= @. -estim.con.x̂0min
903902
n += nx̂
@@ -923,14 +922,15 @@ end
923922

924923
"Set `b` excluding sensor noise bounds if not a `LinModel` and non-`SingleShooting`."
925924
function linconstraint!(
926-
estim::MovingHorizonEstimator, ::SimModel, ::TranscriptionMethod
925+
estim::MovingHorizonEstimator, model::SimModel, ::TranscriptionMethod
927926
)
928-
nx̂, nŵ = estim.nx̂, estim.nx̂
927+
nx̂, nŵ, na = estim.nx̂, estim.nx̂, get_na(model)
929928
# --- truncate vector and matrices if necessary ---
930929
X̂0min, X̂0max = trunc_bounds(estim, estim.con.X̂0min, estim.con.X̂0max, nx̂)
931930
Ŵmin, Ŵmax = trunc_bounds(estim, estim.con.Ŵmin, estim.con.Ŵmax, nŵ)
931+
Âmin, Âmax = trunc_bounds(estim, estim.con.Âmin, estim.con.Âmax, na, estim.Nk[]+1)
932932
# --- update b vector for linear inequality constraints ---
933-
nx̂, nŴ_He, nX̂_He = length(estim.con.x̂0min), length(Ŵmin), length(X̂0min)
933+
nŴ_He, nX̂_He, nÂe_He = length(Ŵmin), length(X̂0min), length(Âmin)
934934
n = 0
935935
estim.con.b[(n+1):(n+nx̂)] .= @. -estim.con.x̂0min
936936
n += nx̂
@@ -940,6 +940,10 @@ function linconstraint!(
940940
n += nX̂_He
941941
estim.con.b[(n+1):(n+nX̂_He)] .= @. +X̂0max - estim.con.FX̂
942942
n += nX̂_He
943+
estim.con.b[(n+1):(n+nÂe_He)] .= @. -Âmin
944+
n += nÂe_He
945+
estim.con.b[(n+1):(n+nÂe_He)] .= @. +Âmax
946+
n += nÂe_He
943947
estim.con.b[(n+1):(n+nŴ_He)] .= @. -Ŵmin
944948
n += nŴ_He
945949
estim.con.b[(n+1):(n+nŴ_He)] .= @. +Ŵmax

0 commit comments

Comments
 (0)