@@ -490,12 +490,10 @@ If first warm-starts the solver with [`set_warmstart_mhe!`](@ref). It then calls
490490"""
491491function optim_objective! (estim:: MovingHorizonEstimator{NT} ) where NT<: Real
492492 model, optim, buffer = estim. model, estim. optim, estim. buffer
493- nym , nx̂, nŵ, nε, Nk = estim . nym, estim. nx̂, estim. nx̂, estim . nε , estim. Nk[]
494- nx̃ = nε + nx̂
493+ nŵ , nx̂, Nk = estim. nx̂, estim. nx̂, estim. Nk[]
494+ nx̃ = estim . nε + nx̂
495495 Z̃var:: Vector{JuMP.VariableRef} = optim[:Z̃var ]
496- V̂ = Vector {NT} (undef, nym* Nk) # TODO : remove this allocation
497- X̂0 = Vector {NT} (undef, nx̂* Nk) # TODO : remove this allocation
498- Z̃s = set_warmstart_mhe! (V̂, X̂0, estim, Z̃var)
496+ Z̃s = set_warmstart_mhe! (estim, Z̃var)
499497 # ------- solve optimization problem --------------
500498 try
501499 JuMP. optimize! (optim)
@@ -534,14 +532,15 @@ function optim_objective!(estim::MovingHorizonEstimator{NT}) where NT<:Real
534532 # --------- update estimate -----------------------
535533 û0, ŷ0, k = buffer. û, buffer. ŷ, buffer. k
536534 estim. Ŵ[1 : nŵ* Nk] .= @views estim. Z̃[nx̃+ 1 : nx̃+ nŵ* Nk] # update Ŵ with optimum for warm-start
537- V̂, X̂0 = predict_mhe! (V̂, X̂0, û0, k, ŷ0, estim, model, estim. Z̃)
538- x̂0next = @views X̂0[end - nx̂+ 1 : end ]
535+ V̂, X̂0 = estim. buffer. V̂, estim. buffer. X̂
536+ predict_mhe! (V̂, X̂0, û0, k, ŷ0, estim, model, estim. Z̃)
537+ x̂0next = @views X̂0[Nk* nx̂- nx̂+ 1 : Nk* nx̂]
539538 estim. x̂0 .= x̂0next
540539 return estim. Z̃
541540end
542541
543542@doc raw """
544- set_warmstart_mhe!(V̂, X̂0, estim::MovingHorizonEstimator, Z̃var) -> Z̃s
543+ set_warmstart_mhe!(estim::MovingHorizonEstimator, Z̃var) -> Z̃s
545544
546545Set and return the warm-start value of `Z̃var` for [`MovingHorizonEstimator`](@ref).
547546
@@ -564,11 +563,11 @@ computed at the last time step ``k-1``. If the objective function is not finite
564563point, all the process noises ``\m athbf{ŵ}_{k-1}(k-j)`` are warm-started at zeros. The
565564method mutates all the arguments.
566565"""
567- function set_warmstart_mhe! (V̂, X̂0, estim:: MovingHorizonEstimator{NT} , Z̃var) where NT<: Real
566+ function set_warmstart_mhe! (estim:: MovingHorizonEstimator{NT} , Z̃var) where NT<: Real
568567 model, buffer = estim. model, estim. buffer
569- nε, nx̂, nŵ, nZ̃, Nk = estim. nε, estim. nx̂, estim. nx̂, length (estim . Z̃) , estim. Nk[]
568+ nε, nx̂, nŵ, Nk = estim. nε, estim. nx̂, estim. nx̂, estim. Nk[]
570569 nx̃ = nε + nx̂
571- Z̃s = Vector {NT} (undef, nZ̃) # TODO : remove this allocation
570+ Z̃s = estim . buffer . Z̃
572571 û0, ŷ0, x̄, k = buffer. û, buffer. ŷ, buffer. x̂, buffer. k
573572 # --- slack variable ε ---
574573 estim. nε == 1 && (Z̃s[begin ] = estim. Z̃[begin ])
@@ -577,7 +576,8 @@ function set_warmstart_mhe!(V̂, X̂0, estim::MovingHorizonEstimator{NT}, Z̃var
577576 # --- process noise estimates Ŵ ---
578577 Z̃s[nx̃+ 1 : end ] = estim. Ŵ
579578 # verify definiteness of objective function:
580- V̂, X̂0 = predict_mhe! (V̂, X̂0, û0, k, ŷ0, estim, model, Z̃s)
579+ V̂, X̂0 = estim. buffer. V̂, estim. buffer. X̂
580+ predict_mhe! (V̂, X̂0, û0, k, ŷ0, estim, model, Z̃s)
581581 Js = obj_nonlinprog! (x̄, estim, model, V̂, Z̃s)
582582 if ! isfinite (Js)
583583 Z̃s[nx̃+ 1 : end ] = 0
0 commit comments