145145@doc raw """
146146 MovingHorizonEstimator(model::SimModel; <keyword arguments>)
147147
148- Construct a moving horizon estimator based on `model` ([`LinModel`](@ref) or [`NonLinModel`](@ref)).
148+ Construct a moving horizon estimator (MHE) based on `model` ([`LinModel`](@ref) or [`NonLinModel`](@ref)).
149149
150150This estimator can handle constraints on the estimates, see [`setconstraint!`](@ref).
151151Additionally, `model` is not linearized like the [`ExtendedKalmanFilter`](@ref), and the
@@ -519,10 +519,10 @@ function init_optimization!(
519519 He, con = estim. He, estim. con
520520 nŶm, nX̂, ng = He* estim. nym, He* estim. nx̂, length (con. i_g)
521521 # --- variables and linear constraints ---
522- nvar = length (estim. Z̃)
522+ nZ̃ = length (estim. Z̃)
523523 set_silent (optim)
524524 # limit_solve_time(estim) #TODO : add this feature
525- @variable (optim, Z̃var[1 : nvar ])
525+ @variable (optim, Z̃var[1 : nZ̃ ])
526526 A = con. A[con. i_b, :]
527527 b = con. b[con. i_b]
528528 @constraint (optim, linconstraint, A* Z̃var .≤ b)
@@ -541,20 +541,20 @@ function init_optimization!(
541541 He, con = estim. He, estim. con
542542 nV̂, nX̂, ng = He* estim. nym, He* estim. nx̂, length (con. i_g)
543543 # --- variables and linear constraints ---
544- nvar = length (estim. Z̃)
544+ nZ̃ = length (estim. Z̃)
545545 set_silent (optim)
546546 # limit_solve_time(estim) #TODO : add this feature
547- @variable (optim, Z̃var[1 : nvar ])
547+ @variable (optim, Z̃var[1 : nZ̃ ])
548548 A = con. A[con. i_b, :]
549549 b = con. b[con. i_b]
550550 @constraint (optim, linconstraint, A* Z̃var .≤ b)
551551 # --- nonlinear optimization init ---
552552 # see init_optimization!(mpc::NonLinMPC, optim) for details on the inspiration
553- Jfunc, gfunc = let estim= estim, model= model, nvar = nvar , nV̂= nV̂, nX̂= nX̂, ng= ng
553+ Jfunc, gfunc = let estim= estim, model= model, nZ̃ = nZ̃ , nV̂= nV̂, nX̂= nX̂, ng= ng
554554 last_Z̃tup_float, last_Z̃tup_dual = nothing , nothing
555- V̂_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nV̂), nvar + 3 )
556- g_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, ng), nvar + 3 )
557- X̂_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nX̂), nvar + 3 )
555+ V̂_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nV̂), nZ̃ + 3 )
556+ g_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, ng), nZ̃ + 3 )
557+ X̂_cache:: DiffCache{Vector{JNT}, Vector{JNT}} = DiffCache (zeros (JNT, nX̂), nZ̃ + 3 )
558558 function Jfunc (Z̃tup:: JNT... )
559559 V̂ = get_tmp (V̂_cache, Z̃tup[1 ])
560560 Z̃ = collect (Z̃tup)
@@ -606,27 +606,27 @@ function init_optimization!(
606606 gfunc = [(Z̃... ) -> gfunc_i (i, Z̃) for i in 1 : ng]
607607 Jfunc, gfunc
608608 end
609- register (optim, :Jfunc , nvar , Jfunc, autodiff= true )
609+ register (optim, :Jfunc , nZ̃ , Jfunc, autodiff= true )
610610 @NLobjective (optim, Min, Jfunc (Z̃var... ))
611611 if ng ≠ 0
612612 for i in eachindex (con. X̂min)
613613 sym = Symbol (" g_X̂min_$i " )
614- register (optim, sym, nvar , gfunc[i], autodiff= true )
614+ register (optim, sym, nZ̃ , gfunc[i], autodiff= true )
615615 end
616616 i_end_X̂min = nX̂
617617 for i in eachindex (con. X̂max)
618618 sym = Symbol (" g_X̂max_$i " )
619- register (optim, sym, nvar , gfunc[i_end_X̂min+ i], autodiff= true )
619+ register (optim, sym, nZ̃ , gfunc[i_end_X̂min+ i], autodiff= true )
620620 end
621621 i_end_X̂max = 2 * nX̂
622622 for i in eachindex (con. V̂min)
623623 sym = Symbol (" g_V̂min_$i " )
624- register (optim, sym, nvar , gfunc[i_end_X̂max+ i], autodiff= true )
624+ register (optim, sym, nZ̃ , gfunc[i_end_X̂max+ i], autodiff= true )
625625 end
626626 i_end_V̂min = 2 * nX̂ + nV̂
627627 for i in eachindex (con. V̂max)
628628 sym = Symbol (" g_V̂max_$i " )
629- register (optim, sym, nvar , gfunc[i_end_V̂min+ i], autodiff= true )
629+ register (optim, sym, nZ̃ , gfunc[i_end_V̂min+ i], autodiff= true )
630630 end
631631 end
632632 return nothing
0 commit comments