@@ -235,13 +235,13 @@ function addinfo!(info, estim::MovingHorizonEstimator{NT}, model::SimModel) wher
235235 ngi = sum (con. i_g)
236236 nV̂, nX̂, nÂ, nŴ = He* nym, He* nx̂, He* na, He* nx̂
237237 nK̄, nU, nŶ = He* nk̄, He* nu, He* nŷ
238- nŴe, nX̂e, nV̂e = (He+ 1 )* nx̂, (He+ 1 )* nx̂, (He+ 1 )* nym
238+ nŴe, nX̂e, nÂe, nV̂e = (He+ 1 )* nx̂, (He+ 1 )* nx̂, (He + 1 ) * na , (He+ 1 )* nym
239239 x̂0arr, x̄ = zeros (NT, nx̂), zeros (NT, nx̂)
240240 â0arr, Â0 = zeros (NT, na), zeros (NT, nÂ)
241241 Ŵ = zeros (NT, nŴ)
242242 V̂, X̂0 = zeros (NT, nV̂), zeros (NT, nX̂)
243- Ŵe = zeros (NT, nŴe)
244- V̂e, X̂e = zeros (NT, nV̂e ), zeros (NT, nX̂e )
243+ Ŵe, V̂e = zeros (NT, nŴe), zeros (NT, nV̂e)
244+ X̂e, Âe = zeros (NT, nX̂e ), zeros (NT, nÂe )
245245 K̄ = zeros (NT, nK̄)
246246 Û0, Ŷ0 = zeros (NT, nU), zeros (NT, nŶ)
247247 Ûi = zeros (NT, nU)
@@ -251,13 +251,14 @@ function addinfo!(info, estim::MovingHorizonEstimator{NT}, model::SimModel) wher
251251 J_cache = (
252252 Cache (x̂0arr), Cache (â0arr), Cache (x̄),
253253 Cache (Ŵ), Cache (V̂), Cache (X̂0), Cache (Â0),
254- Cache (Ŵe), Cache (V̂e), Cache (X̂e),
254+ Cache (Ŵe), Cache (V̂e), Cache (X̂e), Cache (Âe),
255255 Cache (Û0), Cache (Ûi), Cache (K̄), Cache (Ŷ0),
256256 Cache (gc), Cache (g), Cache (geq)
257257 )
258- function J! (Z̃, x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g, geq)
258+ function J! (Z̃, x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g, geq)
259259 update_predictions! (
260- x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g, geq, estim, Z̃
260+ x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g, geq,
261+ estim, Z̃
261262 )
262263 return obj_nonlinprog (estim, model, x̄, V̂, Ŵ, Z̃)
263264 end
@@ -274,13 +275,16 @@ function addinfo!(info, estim::MovingHorizonEstimator{NT}, model::SimModel) wher
274275 ∇g_cache = (
275276 Cache (x̂0arr), Cache (â0arr), Cache (x̄),
276277 Cache (Ŵ), Cache (V̂), Cache (X̂0), Cache (Â0),
277- Cache (Ŵe), Cache (V̂e), Cache (X̂e),
278+ Cache (Ŵe), Cache (V̂e), Cache (X̂e), Cache (Âe),
278279 Cache (Û0), Cache (Ûi), Cache (K̄), Cache (Ŷ0),
279280 Cache (gc), Cache (g), Cache (geq)
280281 )
281- function gi! (gi, Z̃, x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g, geq)
282+ function gi! (
283+ gi, Z̃, x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g, geq
284+ )
282285 update_predictions! (
283- x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g, geq, estim, Z̃
286+ x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g, geq,
287+ estim, Z̃
284288 )
285289 gi .= @views g[i_g]
286290 return nothing
@@ -306,16 +310,17 @@ function addinfo!(info, estim::MovingHorizonEstimator{NT}, model::SimModel) wher
306310 ∇²g_cache = (
307311 Cache (x̂0arr), Cache (â0arr), Cache (x̄),
308312 Cache (Ŵ), Cache (V̂), Cache (X̂0), Cache (Â0),
309- Cache (Ŵe), Cache (V̂e), Cache (X̂e),
313+ Cache (Ŵe), Cache (V̂e), Cache (X̂e), Cache (Âe),
310314 Cache (Û0), Cache (Ûi), Cache (K̄), Cache (Ŷ0),
311315 Cache (gc), Cache (g), Cache (geq),
312316 Cache (gi)
313317 )
314318 function ℓ_gi (
315- Z̃, λi, x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g, geq, gi
319+ Z̃, λi, x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g, geq, gi
316320 )
317321 update_predictions! (
318- x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g, geq, estim, Z̃
322+ x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g, geq,
323+ estim, Z̃
319324 )
320325 gi .= @views g[i_g]
321326 return dot (λi, gi)
@@ -330,13 +335,16 @@ function addinfo!(info, estim::MovingHorizonEstimator{NT}, model::SimModel) wher
330335 ∇geq_cache = (
331336 Cache (x̂0arr), Cache (â0arr), Cache (x̄),
332337 Cache (Ŵ), Cache (V̂), Cache (X̂0), Cache (Â0),
333- Cache (Ŵe), Cache (V̂e), Cache (X̂e),
338+ Cache (Ŵe), Cache (V̂e), Cache (X̂e), Cache (Âe),
334339 Cache (Û0), Cache (Ûi), Cache (K̄), Cache (Ŷ0),
335340 Cache (gc), Cache (g)
336341 )
337- function geq! (geq, Z̃, x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g)
342+ function geq! (
343+ geq, Z̃, x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g
344+ )
338345 update_predictions! (
339- x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g, geq, estim, Z̃
346+ x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g, geq,
347+ estim, Z̃
340348 )
341349 return nothing
342350 end
@@ -361,15 +369,16 @@ function addinfo!(info, estim::MovingHorizonEstimator{NT}, model::SimModel) wher
361369 ∇²geq_cache = (
362370 Cache (x̂0arr), Cache (â0arr), Cache (x̄),
363371 Cache (Ŵ), Cache (V̂), Cache (X̂0), Cache (Â0),
364- Cache (Ŵe), Cache (V̂e), Cache (X̂e),
372+ Cache (Ŵe), Cache (V̂e), Cache (X̂e), Cache (Âe),
365373 Cache (Û0), Cache (Ûi), Cache (K̄), Cache (Ŷ0),
366374 Cache (gc), Cache (g), Cache (geq)
367375 )
368376 function ℓ_geq (
369- Z̃, λeq, x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g, geq
377+ Z̃, λeq, x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g, geq
370378 )
371379 update_predictions! (
372- x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g, geq, estim, Z̃
380+ x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g, geq,
381+ estim, Z̃
373382 )
374383 return dot (λeq, geq)
375384 end
911920
912921"""
913922 update_predictions!(
914- x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g, geq,
923+ x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g, geq,
915924 estim::MovingHorizonEstimator, Z̃
916925 ) -> nothing
917926
@@ -920,7 +929,7 @@ Update in-place the vectors for the predictions of `estim` estimator at decision
920929The method mutates all the arguments before `estim` argument.
921930"""
922931function update_predictions! (
923- x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Û0, Ûi, K̄, Ŷ0, gc, g, geq,
932+ x̂0arr, â0arr, x̄, Ŵ, V̂, X̂0, Â0, Ŵe, V̂e, X̂e, Âe, Û0, Ûi, K̄, Ŷ0, gc, g, geq,
924933 estim:: MovingHorizonEstimator , Z̃
925934)
926935 model, transcription = estim. model, estim. transcription
@@ -931,9 +940,9 @@ function update_predictions!(
931940 V̂, X̂0, Â0 = predict_mhe! (
932941 V̂, X̂0, Â0, Û0, Ûi, K̄, Ŷ0, estim, model, transcription, x̂0arr, â0arr, Ŵ, Z̃
933942 )
934- Ŵe, V̂e, X̂e = extended_vectors! (Ŵe, V̂e, X̂e, estim, Ŵ, V̂, X̂0, x̂0arr)
943+ Ŵe, V̂e, X̂e, Âe = extended_vectors! (Ŵe, V̂e, X̂e, Âe, estim, Ŵ, V̂, X̂0, Â0, x̂0arr, â0arr )
935944 ε = getslack (estim, Z̃)
936- gc = con_custom_mhe! (gc, estim, X̂e, V̂e, Ŵe, x̄, ε)
945+ gc = con_custom_mhe! (gc, estim, X̂e, Âe, V̂e, Ŵe, x̄, ε)
937946 g = con_nonlinprog_mhe! (g, estim, model, transcription, X̂0, V̂, gc, ε)
938947 geq = con_nonlinprogeq_mhe! (
939948 geq, X̂0, Û0, Ûi, K̄, estim, model, transcription, x̂0arr, â0arr, Ŵ, Z̃
@@ -943,52 +952,59 @@ end
943952
944953"""
945954 extended_vectors!(
946- Ŵe, V̂e, X̂e, estim::MovingHorizonEstimator, Ŵ, V̂, X̂0, x̂0arr
947- ) -> Ŵe, V̂e, X̂e
955+ Ŵe, V̂e, X̂e, Âe, estim::MovingHorizonEstimator, Ŵ, V̂, X̂0, Â0, x̂0arr, â0arr
956+ ) -> Ŵe, V̂e, X̂e, Âe
948957
949958Compute the extended `Ŵe, V̂e` and `X̂e` vectors for NLP using the `Ŵ, V̂` and `X̂0` vectors.
950959
951960See [`MovingHorizonEstimator`](@ref) for the definition of the vectors, the exact time
952961steps of the samples in them and the missing values with `NaN`s. The method mutates all
953962the arguments before `estim` argument.
954963"""
955- function extended_vectors! (Ŵe, V̂e, X̂e, estim:: MovingHorizonEstimator , Ŵ, V̂, X̂0, x̂0arr)
956- nym, nŵ, nx̂ = estim. nym, estim. nx̂, estim. nx̂
964+ function extended_vectors! (
965+ Ŵe, V̂e, X̂e, Âe,
966+ estim:: MovingHorizonEstimator , Ŵ, V̂, X̂0, Â0, x̂0arr, â0arr
967+ )
968+ nym, nŵ, nx̂, na = estim. nym, estim. nx̂, estim. nx̂, get_na (estim. model)
957969 Ŵe[1 : end - nŵ] .= Ŵ
958970 Ŵe[end - nŵ+ 1 : end ] .= NaN
959971 X̂e[1 : nx̂] .= x̂0arr .+ estim. x̂op
960972 X̂e[nx̂+ 1 : end ] .= X̂0 .+ estim. X̂op
973+ Âe[1 : na] .= â0arr # no operating points for algebraic var. a
974+ Âe[na+ 1 : end ] .= Â0
961975 if estim. direct
962976 V̂e[1 : nym] .= NaN
963977 V̂e[1 + nym: end ] .= V̂
964978 else
965979 V̂e[1 : end - nym] .= V̂
966980 V̂e[end - nym+ 1 : end ] .= NaN
967981 end
968- return Ŵe, V̂e, X̂e
982+ return Ŵe, V̂e, X̂e, Âe
969983end
970984
971985
972986"""
973- con_custom_mhe!(gc, estim::MovingHorizonEstimator, X̂e, V̂e, Ŵe, x̄, ε) -> gc
987+ con_custom_mhe!(gc, estim::MovingHorizonEstimator, X̂e, Âe, V̂e, Ŵe, x̄, ε) -> gc
974988
975989Evaluate the custom inequality constraint `gc` in-place for [`MovingHorizonEstimator`](@ref).
976990"""
977- function con_custom_mhe! (gc, estim:: MovingHorizonEstimator , X̂e, V̂e, Ŵe, x̄, ε)
991+ function con_custom_mhe! (gc, estim:: MovingHorizonEstimator , X̂e, Âe, V̂e, Ŵe, x̄, ε)
978992 if estim. con. nc > 0
979993 P̄ = estim. P̂arr_old
980994 Nk = estim. Nk[]
981995 Ue, Yem, De = estim. Ue, estim. Yem, estim. De
982996 if Nk < estim. He
983997 # avoid views since allocations only when Nk < He and we want fast mul!:
984- nX̂e, nŴe, nYem = (Nk+ 1 )* estim. nx̂, (Nk+ 1 )* estim. nx̂, (Nk+ 1 )* estim. nym
985- nUe, nDe = (Nk+ 1 )* estim. model. nu, (Nk+ 1 )* estim. model. nd
998+ nX̂e, nÂe = (Nk+ 1 )* estim. nx̂, (Nk+ 1 )* get_na (estim. model)
999+ nŴe, nYem = (Nk+ 1 )* estim. nx̂, (Nk+ 1 )* estim. nym
1000+ nUe, nDe = (Nk+ 1 )* estim. model. nu, (Nk+ 1 )* estim. model. nd
9861001 Ue, Yem, De = estim. Ue[1 : nUe], estim. Yem[1 : nYem], estim. De[1 : nDe]
987- X̂e, V̂e, Ŵe = X̂e[1 : nX̂e], V̂e[1 : nYem], Ŵe[1 : nŴe]
1002+ X̂e, Âe = X̂e[1 : nX̂e], Âe[1 : nÂe]
1003+ V̂e, Ŵe = V̂e[1 : nYem], Ŵe[1 : nŴe]
9881004 else
9891005 Ue, Yem, De = estim. Ue, estim. Yem, estim. De
9901006 end
991- estim. con. gc! (gc, X̂e, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, estim. p, ε)
1007+ estim. con. gc! (gc, X̂e, Âe, V̂e, Ŵe, Ue, Yem, De, P̄, x̄, estim. p, ε)
9921008 end
9931009 return gc
9941010end
0 commit comments